discord.js "displayAvatarURL" low resolution - discord

I have a question about programming a Discord bot using discord.js. Well, when I use "displayAvatarURL" the user's avatar is shown to me, but in very low quality. Is there any way to improve this quality?

You issue is quite simple to fix, according to the docs, you can pass an object as parameter to set the image's size, like this :
user.displayAvatarURL({ size: 2048, dynamic: true });
I've also added the dynamic: true to let the GIFs avatars be animated ;)

That's not a big issue you can add the following code for avatar code.
.displayAvatarURL({ dynamic: true })
Note:- Adding any format or size parameter may work glitchy for some avatars.

You can pass an object as a parameter to set the image's size :
user.displayAvatarURL({size: yourSize, dynamic: true});
In order to set a valid size, check the docs.
I added dynamic: true to animate the animated profile pictures.

Related

how to distinguish which picture put in the right position

I am using preloadjs, but I have a question that when I store the images in the queue object. How do I distinguish which image put in the right place.
here is storing the images code
queue.loadFile('https://s3.amazonaws.com/coursetro/stuff/mountains-clouds.jpg');
queue.loadFile('https://s3.amazonaws.com/coursetro/stuff/adventure-alpine-alps-714258.jpg');
queue.loadFile('https://s3.amazonaws.com/coursetro/stuff/170407220921-07-iconic-mountains-pitons-restricted.jpg');
queue.loadFile('https://s3.amazonaws.com/coursetro/stuff/170407220916-04-iconic-mountains-matterhorn-restricted.jpg');
here is setting the image Dom to html
const handleFileComplete=(event)=>{
const type=event.type;
if (type=="fileload"){
galleryRef.current.appendChild(event.result); //this is just a simple traversal How to distinguish
};
}
queue.on("fileload",handleFileComplete);
Thank you for helping me :)
=============================FIXED===============================
Thank for Lanny's answer. We can just set the id when we load the image
queue.loadFile({id:"dance1",src:'https://s3.amazonaws.com/coursetro/stuff/170407220916-04-iconic-mountains-matterhorn-restricted.jpg'});

React Native End to End Tests with Detox: Getting height, width, and other properties of matched elements

As the title states, I would like to programmatically retrieve properties of matched elements in Detox. I know Detox sees them, because as we all infamously know when a toBeVisible expectation fails by the 75% view rule (a built in Detox opinion for the uninitated), we can see what detox 'got', usually it is a message something like this:
Got: "ReactTextView{id=13725, visibility=VISIBLE, width=376, height=102, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams#ac227fb, tag=PROFILE_NAME_TEXT, root-is-layout-requested=false, has-input-connection=false, x=486.0, y=120.0, text=Anonymous, input-type=0, ime-target=false, has-links=false}"
So we have things like the width, height, focus and so on.
My question is, how can we get at these properties programmatically? Specifically, I have an element that is expanding after a button tap and I want to be sure the height is larger than it was before.
If you check the methods available for element(by.id("SOME_ID")), there are only action methods available...
I've finally discovered the answer which was hard to find initial due to missing typings of detox at the time. Properties like height and width that I mentioned are available through getAttributes() method:
const attributes = await element(by.text('Tap Me')).getAttributes();
expect(attributes.text).toBe('Tap Me');
const multipleMatchedElements = await element(by.text('Multiple')).getAttributes();
expect(multipleMatchedElements.elements.length).toBe(5);
expect(multipleMatchedElements.elements[0].identifier).toBe('FirstElement');
The available properties vary between Android and iOS as well. See the documentation in the library for getAttributes(), and the pull request on detox which adds all the types.

React Native - Is it possible to control the speed at which the ScrollView scrolls

I have looked at many posts and they seem to suggest that it is not possible. However, they are very old posts. I am curious if this is possible now.
I am using expo in my project and referred the below,
https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz
I don't seem to find the duration variable as suggested in the below pull request that is requested as a feature.
https://github.com/facebook/react-native/pull/17422
Any help would be appreciated.Any workarounds if this is not possible? I am thinking of setting a time interval and wrap the scrollview around but I am not sure if that works.
would like to know why you need to do this. Maybe understand we'll can help with other way.
I got this working by having setInterval call a function(in which you define the logic or the pace at which the scroll should move).
this.interval= setInterval(this.scrollwithSpeed, 100); // Set the function to this timer
scrollwithSpeed() {
position = this.state.currentPosition + x; // x decides the speed and currentPosition is set to 0 initially.
this.scrollObject.scrollTo(
{ y: position, animated: true }
);
this.setState({ currentPosition: position });
}
Make sure you call clearInterval(this.interval) after it is done.

To check if an image file exists and load another default file if not

In my developing with React, I encounter this problem:
I retrieve certain data from a remote API with relevant information to describe a book: http://api.rsywx.com/book/randomBook/1. This will return a JSON string:
{"status":200,"out":[{"bookid":"00637","title":"\u4e2d\u56fd\u53e4\u4ee3\u601d\u60f3\u53f2","author":"\u6768\u8363\u56fd","region":"\u4e2d\u56fd\u5927\u9646","purchdate":"1973-09-13"}]}
Out of this return, I populate a state object and to display that book in the page.
One thing is that I need to display a book cover associated with that book. I don't have covers for all my books stored in (and thus randomly returned from) the API.
If a cover image is there, I can safely display that image via:
<img
className="ls-l"
src={this.state.cover}
.../>
cover is populated from bookid.
But if not, I must display a default.jpg as a fallback.
So basically I need to check if this.state.cover file exists.
Any input will be much appreciated.
Update
Thanks for all's input below.
I think it may be that I did not make my self clear.
No matter whether the image file exists in my server side, this.state.cover will be populated from bookid, i.e, in the form of "http://myserver/img/12345.jpg", where 12345 is the bookid.
The real situaion is that file 12345.jpg exisits, but 54321.jpg is not.
So before I display the image in my <img> tag, I have to replace 54321.jpg to default.jpg. I think this is a question related to file manupilation.
The below methods are assuming cover field is not set, which is not the case in my code.
Nevertheless, thanks all.
Two different ways:
let {cover = "fallback.jpg"} = this.state;
Or
src={this.state.cover || "fallback.jpg"}
Or you use the monadic goodness of functional programming to get rid of the null checks.
fetch(url,{})
.then( (response)=> response.json())
.then((book) => this.setState({
picture: book.picture || defaultCover.jpg
}))
You can go with the usual || operator here. This would work fine. But be sure of the ordering. In pic1 || pic2 pic1 is checked first. If it is undefined, it goes for pic2.
Use conditional operator to check if cover property exists or not. Use something like this,
const defaultImage = "some-url";
<img
className="ls-l"
src={this.state.cover ? this.state.cover : defaultImage}
.../>

What does GTK_WINDOW(window)->allow_shrink = TRUE mean in c?

I'm just getting started with gtk,anyone knows what this means?
GTK_WINDOW(window)->allow_shrink = TRUE;
It means the user can resize the window to smaller dimensions than were specified on creation of the window. GTK+ has an excellent reference, a quick search is all you need.
According to the GTK docs, something you shouldn't do:
If allow_shrink is TRUE, the user can
shrink the window so that its children
do not receive their full size
request; this is basically a bad
thing, because most widgets will look
wrong if this happens. Furthermore
GTK+ has a tendency to re-expand the
window if size is recalculated for any
reason. The upshot is that
allow_shrink should always be set to
FALSE.
See this page for more info.
If TRUE, the window has no mimimum size. Setting this to TRUE is 99% of the time a bad idea.
Default value: FALSE
If allow_shrink is TRUE, the user can shrink the window so that its children do not receive their full size request; this is basically a bad thing, because most widgets will look wrong if this happens. Furthermore GTK+ has a tendency to re-expand the window if size is recalculated for any reason. The upshot is that allow_shrink should always be set to FALSE.
If you are referring to the GTK_WINDOW(window) part, then I imagine it is casting/adjusting the pointer to obtain a pointer to a struct type for a window object that contains a variable called allow_shrink.

Resources