From aa74f89498bd66a9b31edeb90523896b5a47fbd1 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 1 Jun 2021 18:31:39 -0600 Subject: [PATCH] Start utils with avatar --- src/modules/utils.js | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/modules/utils.js diff --git a/src/modules/utils.js b/src/modules/utils.js new file mode 100644 index 0000000..0c4f790 --- /dev/null +++ b/src/modules/utils.js @@ -0,0 +1,79 @@ +const Command = require("../lib/command.js"); +const CATEGORY = "utils"; + +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);