role command
parent
3927b3c50f
commit
c31c99f54e
|
@ -0,0 +1,69 @@
|
||||||
|
import { Message } 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.permissions = 6;
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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.');
|
||||||
|
const rolesList = args.slice(1).join(' ').split(', ');
|
||||||
|
const rolesToAdd = [];
|
||||||
|
const rolesToRemove = [];
|
||||||
|
let stop = false;
|
||||||
|
await rolesList.forEach((arg) => {
|
||||||
|
const action = arg[0];
|
||||||
|
let role;
|
||||||
|
if (action !== '+' && action !== '-') {
|
||||||
|
role = this.client.util.resolveRole(arg, message.guild);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
if (action === '+') {
|
||||||
|
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
||||||
|
if (!role) {
|
||||||
|
stop = true;
|
||||||
|
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||||
|
}
|
||||||
|
if (member.roles.includes(role.id)) {
|
||||||
|
stop = true;
|
||||||
|
return this.error(message.channel, `You already have the role \`${role.name}\`.`);
|
||||||
|
}
|
||||||
|
return rolesToAdd.push(role);
|
||||||
|
}
|
||||||
|
if (action === '-') {
|
||||||
|
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
||||||
|
if (!role) {
|
||||||
|
stop = true;
|
||||||
|
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||||
|
}
|
||||||
|
if (!member.roles.includes(role.id)) {
|
||||||
|
stop = true;
|
||||||
|
return this.error(message.channel, `You don't have the role \`${role.name}\``);
|
||||||
|
}
|
||||||
|
return rolesToRemove.push(role);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (stop) return;
|
||||||
|
await rolesToAdd.forEach((role) => member.addRole(role.id));
|
||||||
|
await 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('`, `')}\`` : ''}`);
|
||||||
|
} catch (err) {
|
||||||
|
return this.client.util.handleError(err, message, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue