const Command = require("../lib/command.js"); const CATEGORY = "utility"; const ICON_BASE = "https://cdn.discordapp.com/icons/"; const AVATAR_BASE = "https://cdn.discordapp.com/avatars/"; const {pastelize, getTopColor, lookupUser} = require("../lib/utils.js"); const avatar = new Command("avatar"); avatar.category = CATEGORY; avatar.helpText = "Get avatar of a user"; avatar.usage = ""; avatar.callback = async function (msg, line) { const color = getTopColor(msg, hf.bot.user.id, pastelize(hf.bot.user.id)); if (line == "--server" || line == "--guild") { if (!msg.channel.guild) { return "`--server/--guild` can only be used within guilds."; } else { const url = `${ICON_BASE}${msg.channel.guild.id}/${ msg.channel.guild.icon }.${ msg.channel.guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024" }`; return { embed: { color, title: "Server Icon", url, image: { url, }, }, }; } } else if (line) { const user = await lookupUser(msg, line); if ( user == "No results" || user == "Canceled" || user == "Request timed out" ) { return user; } else { const url = `${AVATAR_BASE}${user.id}/${user.avatar}.${ user.avatar.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024" }`; return { embed: { color, title: `Avatar for \`${user.username}#${user.discriminator}\``, url, image: { url, }, }, }; } } else { const url = `${AVATAR_BASE}${msg.author.id}/${msg.author.avatar}.${ msg.author.avatar.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024" }`; return { embed: { color, title: `Avatar for \`${msg.author.username}#${msg.author.discriminator}\``, url, image: { url, }, }, }; } }; hf.registerCommand(avatar);