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

2
app.js
View file

@ -91,7 +91,7 @@ const Admiral = new Fleet({
users: true,
repliedUser: true
},
guildSubscriptions: false,
restMode: true,
messageLimit: 50,
intents: [
"guilds",

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 => {

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 => {

View file

@ -39,8 +39,16 @@ class TagsCommand extends Command {
const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
if (!getResult) return "This tag doesn't exist!";
const user = await this.ipc.fetchUser(getResult.author);
if (!user) return `I couldn't find exactly who owns this tag, but I was able to get their ID: \`${getResult.author}\``;
if (!user) {
try {
const restUser = await this.client.getRESTUser(getResult.author);
return `This tag is owned by **${restUser.username}#${restUser.discriminator}** (\`${getResult.author}\`).`;
} catch {
return `I couldn't find exactly who owns this tag, but I was able to get their ID: \`${getResult.author}\``;
}
} else {
return `This tag is owned by **${user.username}#${user.discriminator}** (\`${getResult.author}\`).`;
}
} else if (this.args[0].toLowerCase() === "list") {
if (!this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
const tagList = await database.getTags(this.message.channel.guild.id);