mrmBot-Matrix/commands/general/avatar.js

35 lines
1.7 KiB
JavaScript
Raw Normal View History

import Command from "../../classes/command.js";
class AvatarCommand extends Command {
async run() {
2022-01-07 17:44:18 +00:00
if (this.message.mentions[0]) {
return this.message.mentions[0].dynamicAvatarURL(null, 1024);
2021-08-01 12:16:43 +00:00
} 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] && this.args[0].match(/^<?[@#]?[&!]?\d+>?$/) && this.args[0] >= 21154535154122752n) {
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.author.dynamicAvatarURL(null, 1024);
}
} else if (this.args.join(" ") !== "" && this.channel.guild) {
const userRegex = new RegExp(this.args.join("|"), "i");
const member = this.channel.guild.members.find(element => {
return userRegex.test(element.nick) ? userRegex.test(element.nick) : userRegex.test(element.username);
});
return member ? member.user.dynamicAvatarURL(null, 1024) : this.author.dynamicAvatarURL(null, 1024);
} else {
return this.author.dynamicAvatarURL(null, 1024);
}
}
static description = "Gets a user's avatar";
static aliases = ["pfp", "ava"];
static arguments = ["{mention/id}"];
2022-03-31 19:53:22 +00:00
static slashAllowed = false;
}
export default AvatarCommand;