import { Message, Role } from 'eris'; import { Client, Command, RichEmbed } from '../class'; export default class Roleinfo extends Command { constructor(client: Client) { super(client); this.name = 'roleinfo'; this.description = 'Get information about a role.'; this.usage = 'roleinfo [role ID or role name]'; this.permissions = 0; this.guildOnly = true; this.enabled = true; } public async run(message: Message, args: string[]) { try { if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.***`); // @ts-ignore let role: Role = message.channel.guild.roles.find((r: Role) => r.id === args[0]); if (!role) { // if it's a role name // @ts-ignore role = message.channel.guild.roles.find((r: Role) => r.name.toLowerCase().includes(args.join(' ').toLowerCase())); } if (!role) return this.client.createMessage(message.channel.id, `***${this.client.util.emojis.ERROR} Could not find role.***`); const ms = role.createdAt; const date = new Date(ms).toLocaleDateString('en-us'); const time = new Date(ms).toLocaleTimeString('en-us'); const perms = role.permissions; const permsArray: string[] = []; 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'); const embed = new RichEmbed(); embed.setTitle('Role Information'); embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``); 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(); if (permsArray.length > 0) { embed.addField('Permissions', permsArray.join(', '), true); } return message.channel.createMessage({ embed }); } catch (err) { return this.client.util.handleError(err, message, this); } } }