fix and add role cmd
parent
98f89b5bfd
commit
028094aa87
|
@ -1,12 +1,12 @@
|
||||||
import { Message } from 'eris';
|
import { Message, Role as DRole } from 'eris';
|
||||||
import { Client, Command } from '../class';
|
import { Client, Command } from '../class';
|
||||||
|
|
||||||
export default class Role extends Command {
|
export default class Role extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'role';
|
this.name = 'role';
|
||||||
this.description = 'Manage the roles of a member';
|
this.description = 'Manage the roles of a member.';
|
||||||
this.usage = 'role <user> <roles>';
|
this.usage = `${this.client.config.prefix}role <user> <roles>`;
|
||||||
this.permissions = 6;
|
this.permissions = 6;
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
}
|
}
|
||||||
|
@ -14,27 +14,28 @@ export default class Role extends Command {
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
if (args.length < 2) return this.client.commands.get('help').run(message, [this.name]);
|
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 (!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 rolesList = args.slice(1).join(' ').split(', ');
|
||||||
const rolesToAdd = [];
|
const rolesToAdd = [];
|
||||||
const rolesToRemove = [];
|
const rolesToRemove = [];
|
||||||
let stop = false;
|
let stop = false;
|
||||||
for (const arg of rolesList) {
|
for (const arg of rolesList) {
|
||||||
const action = arg[0];
|
const action = arg[0];
|
||||||
let role;
|
let role: DRole;
|
||||||
if (action !== '+' && action !== '-') {
|
if (action !== '+' && action !== '-') {
|
||||||
role = this.client.util.resolveRole(arg, message.guild);
|
role = this.client.util.resolveRole(arg, this.mainGuild);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
stop = true;
|
stop = true;
|
||||||
return this.error(message.channel, `Role \`${arg}\` not found.`);
|
return this.error(message.channel, `Role \`${arg}\` not found.`);
|
||||||
}
|
}
|
||||||
if (member.roles.includes(role.id)) return rolesToRemove.push(role);
|
if (member.roles.includes(role.id)) return rolesToRemove.push(role);
|
||||||
return rolesToAdd.push(role);
|
rolesToAdd.push(role);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (action === '+') {
|
if (action === '+') {
|
||||||
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
stop = true;
|
stop = true;
|
||||||
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||||
|
@ -43,10 +44,11 @@ export default class Role extends Command {
|
||||||
stop = true;
|
stop = true;
|
||||||
return this.error(message.channel, `You already have the role \`${role.name}\`.`);
|
return this.error(message.channel, `You already have the role \`${role.name}\`.`);
|
||||||
}
|
}
|
||||||
return rolesToAdd.push(role);
|
rolesToAdd.push(role);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (action === '-') {
|
if (action === '-') {
|
||||||
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
stop = true;
|
stop = true;
|
||||||
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||||
|
@ -55,10 +57,12 @@ export default class Role extends Command {
|
||||||
stop = true;
|
stop = true;
|
||||||
return this.error(message.channel, `You don't have the role \`${role.name}\``);
|
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));
|
rolesToAdd.forEach((role) => member.addRole(role.id));
|
||||||
rolesToRemove.forEach((role) => member.removeRole(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('`, `')}\`` : ''}`);
|
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('`, `')}\`` : ''}`);
|
||||||
|
|
Loading…
Reference in New Issue