galactic-bot/structure/client/components/commands/utility/Lookup.js

96 lines
2.5 KiB
JavaScript
Raw Normal View History

const { Command } = require('../../../../interfaces/');
//Apparently hit ratelimits pretty damn quick and doesn't expire often.
class LookupCommand extends Command {
constructor(client) {
super(client, {
name: 'lookup',
module: 'utility',
usage: "<discord-invite>",
showUsage: true,
examples: [
"SvJgtEj",
"discord.gg/SvJgtEj"
],
2021-06-23 10:51:34 +02:00
aliases: [],
restricted: true //For now
// throttling: {
// usages: 1,
// duration: 30
// }
});
this.client = client;
}
async execute(message, { params }) {
let invite = null;
try {
invite = await this.client.fetchInvite(params);
} catch(e) {
2021-06-23 10:51:34 +02:00
return message.respond(message.format('C_LOOKUP_FAILED'), {
emoji: 'failure'
});
}
const fields = [];
if(invite.inviter) {
fields.push({
name: "Inviter",
value: `${invite.inviter.username}#${invite.inviter.discriminator} \`(${invite.inviter.id})\``,
inline: true
});
}
if(invite.memberCount) {
fields.push({
name: "Member Count",
value: `${invite.memberCount} members`,
inline: true
});
}
if(invite.channel) {
fields.push({
name: "Default Channel",
value: `#${invite.channel.name} \`(${invite.channel.id})\``,
inline: true
});
}
if(invite?.guild?.features.length > 0) {
fields.push({
name: "Features",
value: invite.guild.features.map((f) => `\`${f}\``).join(', '),
inline: true
});
}
const embed = {
author: {
name: `${invite.guild.name} (${invite.guild.id})`,
icon_url: invite.guild.iconURL() //eslint-disable-line camelcase
},
thumbnail: {
url: invite.guild.splash ? invite.guild.splashURL() : invite.guild.iconURL()
},
description: invite.guild.description || null,
fields,
footer: {
text: ` https://discord.gg/${invite.code}`
}
};
return message.embed(embed);
}
}
module.exports = LookupCommand;