roleinfo command fixes

merge-requests/9/merge
Matthew 2020-04-16 09:16:48 -04:00
parent e3dd49e3a8
commit b904a00b33
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 10 additions and 18 deletions

View File

@ -12,26 +12,24 @@ export default class Roleinfo extends Command {
this.enabled = true; this.enabled = true;
} }
public async run(message: Message, args: any) { public async run(message: Message, args: string[]) {
try { 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.`); if (!args[0]) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} You need to specifiy a role ID or a role name.***`);
let role: any;
if (!Number.isNaN(args[0])) { // if it's a role id
// @ts-ignore // @ts-ignore
role = message.channel.guild.roles.find((r: Role) => r.id === args[0]); let role: Role = message.channel.guild.roles.find((r: Role) => r.id === args[0]);
} else if (Number.isNaN(args[0])) { // if it's a role name if (!role) { // if it's a role name
// @ts-ignore // @ts-ignore
role = message.channel.guild.roles.find((r: Role) => r.name === args.join(' ')); 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.`); if (!role) return this.client.createMessage(message.channel.id, `***${this.client.util.emojis.ERROR} Could not find role.***`);
const ms = role.createdAt; const ms = role.createdAt;
const date = new Date(ms).toLocaleDateString('en-us'); const date = new Date(ms).toLocaleDateString('en-us');
const time = new Date(ms).toLocaleTimeString('en-us'); const time = new Date(ms).toLocaleTimeString('en-us');
const perms = role.permissions; const perms = role.permissions;
let permsArray: any = []; const permsArray: string[] = [];
if (perms.has('administrator')) permsArray.push('Administrator'); if (perms.has('administrator')) permsArray.push('Administrator');
if (perms.has('manageGuild')) permsArray.push('Manage Server'); if (perms.has('manageGuild')) permsArray.push('Manage Server');
if (perms.has('manageChannels')) permsArray.push('Manage Channels'); if (perms.has('manageChannels')) permsArray.push('Manage Channels');
@ -42,15 +40,9 @@ export default class Roleinfo extends Command {
if (perms.has('banMembers')) permsArray.push('Ban Members'); if (perms.has('banMembers')) permsArray.push('Ban Members');
if (perms.has('kickMembers')) permsArray.push('Kick Members'); if (perms.has('kickMembers')) permsArray.push('Kick Members');
let hasPerms: boolean;
if (permsArray.length > 0) {
permsArray = permsArray.join(', ');
hasPerms = true;
}
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setTitle('Role Information');
embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``); embed.setDescription(`<@&${role.id}> ID: \`${role.id}\``);
embed.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setColor(role.color); embed.setColor(role.color);
embed.addField('Name', role.name, true); embed.addField('Name', role.name, true);
embed.addField('Color', `#${role.color.toString(16)}`, true); embed.addField('Color', `#${role.color.toString(16)}`, true);
@ -61,8 +53,8 @@ export default class Roleinfo extends Command {
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
if (hasPerms) { if (permsArray.length > 0) {
embed.fields.push({ name: 'Permissions', value: permsArray, inline: false }); embed.addField('Permissions', permsArray.join(', '), true);
} }
return message.channel.createMessage({ embed }); return message.channel.createMessage({ embed });
} catch (err) { } catch (err) {