Get user info over REST if it's not cached
This commit is contained in:
		
							parent
							
								
									5acd2b1113
								
							
						
					
					
						commit
						6494dcdcb4
					
				
					 4 changed files with 28 additions and 7 deletions
				
			
		
							
								
								
									
										4
									
								
								app.js
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								app.js
									
										
									
									
									
								
							| 
						 | 
					@ -91,7 +91,7 @@ const Admiral = new Fleet({
 | 
				
			||||||
      users: true,
 | 
					      users: true,
 | 
				
			||||||
      repliedUser: true
 | 
					      repliedUser: true
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    guildSubscriptions: false,
 | 
					    restMode: true,
 | 
				
			||||||
    messageLimit: 50,
 | 
					    messageLimit: 50,
 | 
				
			||||||
    intents: [
 | 
					    intents: [
 | 
				
			||||||
      "guilds",
 | 
					      "guilds",
 | 
				
			||||||
| 
						 | 
					@ -158,4 +158,4 @@ if (isMaster) {
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,13 @@ class AvatarCommand extends Command {
 | 
				
			||||||
    } else if (await this.ipc.fetchUser(this.args[0])) {
 | 
					    } else if (await this.ipc.fetchUser(this.args[0])) {
 | 
				
			||||||
      const user = 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"
 | 
					      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) {
 | 
					    } else if (this.args.join(" ") !== "" && this.message.channel.guild) {
 | 
				
			||||||
      const userRegex = new RegExp(this.args.join("|"), "i");
 | 
					      const userRegex = new RegExp(this.args.join("|"), "i");
 | 
				
			||||||
      const member = this.message.channel.guild.members.find(element => {
 | 
					      const member = this.message.channel.guild.members.find(element => {
 | 
				
			||||||
| 
						 | 
					@ -23,4 +30,4 @@ class AvatarCommand extends Command {
 | 
				
			||||||
  static arguments = ["{mention/id}"];
 | 
					  static arguments = ["{mention/id}"];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default AvatarCommand;
 | 
					export default AvatarCommand;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,12 @@ class UserInfoCommand extends Command {
 | 
				
			||||||
    let user;
 | 
					    let user;
 | 
				
			||||||
    if (getUser) {
 | 
					    if (getUser) {
 | 
				
			||||||
      user = 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(" ") !== "") {
 | 
					    } else if (this.args.join(" ") !== "") {
 | 
				
			||||||
      const userRegex = new RegExp(this.args.join("|"), "i");
 | 
					      const userRegex = new RegExp(this.args.join("|"), "i");
 | 
				
			||||||
      const member = this.client.users.find(element => {
 | 
					      const member = this.client.users.find(element => {
 | 
				
			||||||
| 
						 | 
					@ -54,4 +60,4 @@ class UserInfoCommand extends Command {
 | 
				
			||||||
  static arguments = ["[mention/id]"];
 | 
					  static arguments = ["[mention/id]"];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default UserInfoCommand;
 | 
					export default UserInfoCommand;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,8 +39,16 @@ class TagsCommand extends Command {
 | 
				
			||||||
      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
					      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
				
			||||||
      if (!getResult) return "This tag doesn't exist!";
 | 
					      if (!getResult) return "This tag doesn't exist!";
 | 
				
			||||||
      const user = await this.ipc.fetchUser(getResult.author);
 | 
					      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) {
 | 
				
			||||||
      return `This tag is owned by **${user.username}#${user.discriminator}** (\`${getResult.author}\`).`;
 | 
					        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") {
 | 
					    } 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!";
 | 
					      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);
 | 
					      const tagList = await database.getTags(this.message.channel.guild.id);
 | 
				
			||||||
| 
						 | 
					@ -118,4 +126,4 @@ class TagsCommand extends Command {
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default TagsCommand;
 | 
					export default TagsCommand;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue