2021-06-02 00:31:39 +00:00
|
|
|
const Command = require("../lib/command.js");
|
2021-06-02 00:32:30 +00:00
|
|
|
const CATEGORY = "utility";
|
2021-06-02 00:31:39 +00:00
|
|
|
|
|
|
|
const ICON_BASE = "https://cdn.discordapp.com/icons/";
|
|
|
|
const AVATAR_BASE = "https://cdn.discordapp.com/avatars/";
|
2021-06-02 00:58:39 +00:00
|
|
|
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>",
|
|
|
|
};
|
2021-06-02 00:31:39 +00:00
|
|
|
|
|
|
|
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 = "<user>";
|
|
|
|
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);
|
2021-06-02 00:58:39 +00:00
|
|
|
|
|
|
|
const lookupinvite = new Command("lookupinvite");
|
|
|
|
lookupinvite.category = CATEGORY;
|
|
|
|
lookupinvite.helpText = "Lookup an invite";
|
|
|
|
lookupinvite.usage = "<invite code>";
|
|
|
|
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);
|