Start utils with avatar
This commit is contained in:
parent
bb8f3128ea
commit
aa74f89498
1 changed files with 79 additions and 0 deletions
79
src/modules/utils.js
Normal file
79
src/modules/utils.js
Normal file
|
@ -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 = "<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);
|
Loading…
Reference in a new issue