diff --git a/src/modules/utility.js b/src/modules/utility.js index 2d70716..e4eee37 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -3,6 +3,15 @@ const CATEGORY = "utility"; const ICON_BASE = "https://cdn.discordapp.com/icons/"; const AVATAR_BASE = "https://cdn.discordapp.com/avatars/"; +const SPLASH_BASE = "https://cdn.discordapp.com/splashes/"; +const BANNER_BASE = "https://cdn.discordapp.com/banners/"; + +const STATUS_ICONS = { + online: "<:online:493173082421461002>", + idle: "<:idle:493173082006093836>", + dnd: "<:dnd:493173082261815307>", + offline: "<:offline:493173082253426688>", +}; const {pastelize, getTopColor, lookupUser} = require("../lib/utils.js"); @@ -77,3 +86,126 @@ avatar.callback = async function (msg, line) { } }; hf.registerCommand(avatar); + +const lookupinvite = new Command("lookupinvite"); +lookupinvite.category = CATEGORY; +lookupinvite.helpText = "Lookup an invite"; +lookupinvite.usage = ""; +lookupinvite.addAlias("linvite"); +lookupinvite.callback = async function (msg, line) { + const color = getTopColor(msg, hf.bot.user.id, pastelize(hf.bot.user.id)); + + if (!line) { + return "No arguments passed."; + } + + line = line.replace(/(https?:\/\/)?discord\.gg\//, ""); + + const invite = await hf.bot.requestHandler.request( + "GET", + "/invites/" + line + "?with_counts=1" + ); + if (!invite) return ":warning: No data returned."; + + if (invite.message) { + if (invite.message == "Unknown Invite") { + return "Invite provided is not valid."; + } else { + return `:warning: Got error \`${invite.code}: "${invite.message}"\``; + } + } else { + const embed = { + color, + title: `Invite Info: \`${invite.code}\``, + description: invite.description, + fields: [ + { + name: "Guild", + value: `**${invite.guild.name}** (${invite.guild.id})`, + inline: true, + }, + { + name: "Channel", + value: `**${invite.channel.name}** (${invite.channel.id})`, + inline: true, + }, + { + name: "Member Count", + value: `${STATUS_ICONS.online}${invite.approximate_presence_count} online\t\t${STATUS_ICONS.offline}${invite.approximate_member_count} members`, + inline: false, + }, + { + name: "Features", + value: + invite.guild.features.length > 0 + ? invite.guild.features + .map((feature) => + feature + .split("_") + .map((x) => x[0] + x.substring(1).toLowerCase()) + .join(" ") + ) + .join(", ") + : "None", + inline: false, + }, + ], + thumbnail: { + url: + invite.guild.icon && + `${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${ + invite.guild.icon.startsWith("a_") + ? "gif?size=1024&_=.gif" + : "png?size=1024" + }`, + }, + }; + + if (invite.inviter) { + embed.fields.push({ + name: "Inviter", + value: `**${invite.inviter.username}#${invite.inviter.discriminator}** (${invite.inviter.id})`, + inline: true, + }); + } + + if (invite.guild.icon || invite.guild.splash || invite.guild.banner) { + embed.fields.push({ + name: "\u200b", + value: `${ + invite.guild.icon + ? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${ + invite.guild.icon.startsWith("a_") + ? "gif?size=1024" + : "png?size=1024" + })` + : "" + }${ + invite.guild.splash + ? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${ + invite.guild.id + }/${invite.guild.splash}.png?size=2048)` + : "" + }${ + invite.guild.banner + ? `${ + invite.guild.icon || invite.guild.splash ? " | " : "" + }[Banner](${BANNER_BASE}${invite.guild.id}/${ + invite.guild.banner + }.png?size=2048)` + : "" + }`, + inline: false, + }); + } + + if (invite.guild.splash) { + embed.image = { + url: `${SPLASH_BASE}${invite.guild.id}/${invite.guild.splash}.png?size=256`, + }; + } + + return {embed}; + } +}; +hf.registerCommand(lookupinvite);