2020-04-15 07:25:02 -04:00
|
|
|
import { Message } from 'eris';
|
2020-04-15 20:14:20 -04:00
|
|
|
import { Client, Command, RichEmbed } from '../class';
|
2020-04-15 07:25:02 -04:00
|
|
|
|
|
|
|
export default class Roleinfo extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'roleinfo';
|
|
|
|
this.description = 'Get information about a role.';
|
2020-04-15 20:14:20 -04:00
|
|
|
this.usage = "roleinfo [role ID or role name]"
|
2020-04-15 07:25:02 -04:00
|
|
|
this.permissions = 0;
|
|
|
|
this.guildOnly = true;
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
public async run(message: Message, args: any) {
|
|
|
|
try {
|
|
|
|
if (!args[0]) return this.client.createMessage(message.channel.id, `${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.`);
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
let role: any;
|
|
|
|
if (!isNaN(args[0])) { // if it's a role id
|
2020-04-15 07:25:02 -04:00
|
|
|
// @ts-ignore
|
2020-04-15 09:54:19 -04:00
|
|
|
role = message.channel.guild.roles.find((role) => role.id == args[0]);
|
|
|
|
} else if (isNaN(args[0])) { // if it's a role name
|
|
|
|
args = args.join(' ');
|
|
|
|
// @ts-ignore
|
|
|
|
role = message.channel.guild.roles.find((role) => role.name == args);
|
|
|
|
}
|
|
|
|
if (!role) return this.client.createMessage(message.channel.id, `${this.client.util.emojis.ERROR} Could not find role.`);
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
const ms = role.createdAt;
|
|
|
|
const date = new Date(ms).toLocaleDateString('en-us');
|
|
|
|
const time = new Date(ms).toLocaleTimeString('en-us');
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
const perms = role.permissions;
|
|
|
|
let permsArray: any = [];
|
|
|
|
if (perms.has('administrator')) permsArray.push('Administrator');
|
|
|
|
if (perms.has('manageGuild')) permsArray.push('Manage Server');
|
|
|
|
if (perms.has('manageChannels')) permsArray.push('Manage Channels');
|
|
|
|
if (perms.has('manageRoles')) permsArray.push('Manage Roles');
|
|
|
|
if (perms.has('manageMessages')) permsArray.push('Manage Messages');
|
|
|
|
if (perms.has('manageNicknames')) permsArray.push('Manage Nicknames');
|
|
|
|
if (perms.has('manageEmojis')) permsArray.push('Manage Emojis');
|
|
|
|
if (perms.has('banMembers')) permsArray.push('Ban Members');
|
|
|
|
if (perms.has('kickMembers')) permsArray.push('Kick Members');
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
let hasPerms: boolean;
|
|
|
|
if (permsArray.length > 0) {
|
|
|
|
permsArray = permsArray.join(', ');
|
|
|
|
hasPerms = true;
|
|
|
|
}
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 20:14:20 -04:00
|
|
|
let embed = new RichEmbed()
|
|
|
|
embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``)
|
|
|
|
embed.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.avatarURL)
|
|
|
|
embed.setColor(role.color)
|
|
|
|
embed.addField("Name", role.name, true)
|
|
|
|
embed.addField("Color", `#${role.color.toString(16)}`, true)
|
|
|
|
embed.addField("Hoisted", role.hoist.toString(), true)
|
|
|
|
embed.addField("Position", role.position.toString(), true)
|
|
|
|
embed.addField("Creation Date", `${date} ${time}`, true)
|
|
|
|
embed.addField("Mentionnable", role.mentionable.toString(), true)
|
|
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL)
|
|
|
|
embed.setTimestamp()
|
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
if (hasPerms) {
|
2020-04-15 20:14:20 -04:00
|
|
|
embed.fields.push({ name: 'Permissions', value: permsArray, inline: false });
|
2020-04-15 09:54:19 -04:00
|
|
|
}
|
2020-04-15 20:14:20 -04:00
|
|
|
message.channel.createMessage({embed: embed});
|
2020-04-15 09:54:19 -04:00
|
|
|
} catch (err) {
|
|
|
|
this.client.createMessage(message.channel.id, `${this.client.util.emojis.ERROR} An unexpected error has occured.`);
|
2020-04-15 07:25:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|