Get user info over REST if it's not cached

This commit is contained in:
Essem 2021-12-13 17:09:05 -06:00
parent 5acd2b1113
commit 6494dcdcb4
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
4 changed files with 28 additions and 7 deletions

View file

@ -7,6 +7,13 @@ class AvatarCommand extends Command {
} else if (await this.ipc.fetchUser(this.args[0])) {
const user = await this.ipc.fetchUser(this.args[0]);
return user.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 1024) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // hacky "solution"
} else if (this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752) {
try {
const user = await this.client.getRESTUser(this.args[0]);
return user.avatar ? this.client._formatImage(`/avatars/${user.id}/${user.avatar}`, null, 1024) : `https://cdn.discordapp.com/embed/avatars/${user.discriminator % 5}.png`; // repeat of hacky "solution" from above
} catch {
return this.message.author.dynamicAvatarURL(null, 1024);
}
} else if (this.args.join(" ") !== "" && this.message.channel.guild) {
const userRegex = new RegExp(this.args.join("|"), "i");
const member = this.message.channel.guild.members.find(element => {
@ -23,4 +30,4 @@ class AvatarCommand extends Command {
static arguments = ["{mention/id}"];
}
export default AvatarCommand;
export default AvatarCommand;

View file

@ -6,6 +6,12 @@ class UserInfoCommand extends Command {
let user;
if (getUser) {
user = getUser;
} else if (this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752) {
try {
user = await this.client.getRESTUser(this.args[0]);
} catch {
user = this.message.author;
}
} else if (this.args.join(" ") !== "") {
const userRegex = new RegExp(this.args.join("|"), "i");
const member = this.client.users.find(element => {
@ -54,4 +60,4 @@ class UserInfoCommand extends Command {
static arguments = ["[mention/id]"];
}
export default UserInfoCommand;
export default UserInfoCommand;