fix and add role cmd

merge-requests/21/merge^2
Matthew 2021-03-06 18:32:42 -05:00
parent 98f89b5bfd
commit 028094aa87
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 17 additions and 13 deletions

View File

@ -1,12 +1,12 @@
import { Message } from 'eris';
import { Message, Role as DRole } from 'eris';
import { Client, Command } from '../class';
export default class Role extends Command {
constructor(client: Client) {
super(client);
this.name = 'role';
this.description = 'Manage the roles of a member';
this.usage = 'role <user> <roles>';
this.description = 'Manage the roles of a member.';
this.usage = `${this.client.config.prefix}role <user> <roles>`;
this.permissions = 6;
this.enabled = true;
}
@ -14,27 +14,28 @@ export default class Role extends Command {
public async run(message: Message, args: string[]) {
try {
if (args.length < 2) return this.client.commands.get('help').run(message, [this.name]);
const member = this.client.util.resolveMember(args[0], message.guild);
const member = this.client.util.resolveMember(args[0], this.mainGuild);
if (!member) return this.error(message.channel, 'Member not found');
if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
// if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission denied.');
const rolesList = args.slice(1).join(' ').split(', ');
const rolesToAdd = [];
const rolesToRemove = [];
let stop = false;
for (const arg of rolesList) {
const action = arg[0];
let role;
let role: DRole;
if (action !== '+' && action !== '-') {
role = this.client.util.resolveRole(arg, message.guild);
role = this.client.util.resolveRole(arg, this.mainGuild);
if (!role) {
stop = true;
return this.error(message.channel, `Role \`${arg}\` not found.`);
}
if (member.roles.includes(role.id)) return rolesToRemove.push(role);
return rolesToAdd.push(role);
rolesToAdd.push(role);
continue;
}
if (action === '+') {
role = this.client.util.resolveRole(arg.slice(1), message.guild);
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
if (!role) {
stop = true;
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
@ -43,10 +44,11 @@ export default class Role extends Command {
stop = true;
return this.error(message.channel, `You already have the role \`${role.name}\`.`);
}
return rolesToAdd.push(role);
rolesToAdd.push(role);
continue;
}
if (action === '-') {
role = this.client.util.resolveRole(arg.slice(1), message.guild);
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
if (!role) {
stop = true;
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
@ -55,10 +57,12 @@ export default class Role extends Command {
stop = true;
return this.error(message.channel, `You don't have the role \`${role.name}\``);
}
return rolesToRemove.push(role);
rolesToRemove.push(role);
continue;
}
}
if (stop) return;
// eslint-disable-next-line
// if (stop) return;
rolesToAdd.forEach((role) => member.addRole(role.id));
rolesToRemove.forEach((role) => member.removeRole(role.id));
return this.success(message.channel, `Changed the roles for ${member.username}#${member.discriminator}${rolesToAdd.length > 0 ? `, added \`${rolesToAdd.map((r) => r.name).join('`, `')}\`` : ''}${rolesToRemove.length > 0 ? `, removed \`${rolesToRemove.map((r) => r.name).join('`, `')}\`` : ''}`);