2020-04-16 09:03:59 -04:00
|
|
|
import { Message, Role } 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-16 09:03:59 -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-16 09:16:48 -04:00
|
|
|
public async run(message: Message, args: string[]) {
|
2020-04-15 09:54:19 -04:00
|
|
|
try {
|
2020-04-16 22:56:52 -04:00
|
|
|
if (!args[0]) return this.error(message.channel, 'You need to specifiy a role ID or a role name.');
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-16 22:56:52 -04:00
|
|
|
let role: Role = message.member.guild.roles.find((r: Role) => r.id === args[0]);
|
2020-04-16 09:16:48 -04:00
|
|
|
if (!role) { // if it's a role name
|
2020-04-16 22:56:52 -04:00
|
|
|
role = message.member.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase()));
|
2020-04-15 09:54:19 -04:00
|
|
|
}
|
2020-04-16 22:56:52 -04:00
|
|
|
if (!role) return this.error(message.channel, 'Could not find role.');
|
2020-04-15 07:25:02 -04:00
|
|
|
|
2020-04-15 09:54:19 -04:00
|
|
|
const perms = role.permissions;
|
2020-04-16 09:16:48 -04:00
|
|
|
const permsArray: string[] = [];
|
2020-04-15 09:54:19 -04:00
|
|
|
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-16 09:03:59 -04:00
|
|
|
const embed = new RichEmbed();
|
2020-04-16 09:16:48 -04:00
|
|
|
embed.setTitle('Role Information');
|
2020-04-16 09:03:59 -04:00
|
|
|
embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``);
|
|
|
|
embed.setColor(role.color);
|
|
|
|
embed.addField('Name', role.name, true);
|
2020-04-16 22:56:52 -04:00
|
|
|
embed.addField('Color', role.color ? this.client.util.decimalToHex(role.color) : 'None', true);
|
|
|
|
embed.addField('Hoisted', role.hoist ? 'Yes' : 'No', true);
|
|
|
|
embed.addField('Position', role.position ? 'Yes' : 'No', true);
|
|
|
|
embed.addField('Creation Date', new Date(role.createdAt).toLocaleString(), true);
|
|
|
|
embed.addField('Mentionable', role.mentionable ? 'Yes' : 'No', true);
|
2020-04-16 09:03:59 -04:00
|
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
|
|
embed.setTimestamp();
|
|
|
|
|
2020-04-16 09:16:48 -04:00
|
|
|
if (permsArray.length > 0) {
|
|
|
|
embed.addField('Permissions', permsArray.join(', '), true);
|
2020-04-15 09:54:19 -04:00
|
|
|
}
|
2020-04-16 09:03:59 -04:00
|
|
|
return message.channel.createMessage({ embed });
|
2020-04-15 09:54:19 -04:00
|
|
|
} catch (err) {
|
2020-04-16 09:03:59 -04:00
|
|
|
return this.client.util.handleError(err, message, this);
|
2020-04-15 07:25:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|