2020-07-04 12:23:10 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
2021-06-26 08:42:57 +02:00
|
|
|
const { Removerole } = require('../../../../moderation/infractions/');
|
2020-07-04 12:23:10 +02:00
|
|
|
|
|
|
|
class RemoveroleCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'removerole',
|
|
|
|
module: 'moderation',
|
|
|
|
aliases: [
|
2020-07-20 00:42:21 +02:00
|
|
|
'roleremove',
|
|
|
|
'removeroles',
|
|
|
|
'rolesremove'
|
2020-07-04 12:23:10 +02:00
|
|
|
],
|
|
|
|
usage: "<member..> <role..> [reason]",
|
|
|
|
clientPermissions: ['MANAGE_ROLES'],
|
|
|
|
memberPermissions: ['MANAGE_ROLES'],
|
|
|
|
examples: [],
|
|
|
|
arguments: [
|
|
|
|
{
|
|
|
|
name: 'silent',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
guildOnly: true,
|
2020-07-20 00:42:21 +02:00
|
|
|
showUsage: true,
|
|
|
|
throttling: {
|
|
|
|
usages: 2,
|
|
|
|
duration: 10
|
|
|
|
}
|
2020-07-04 12:23:10 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute(message, { params }) {
|
|
|
|
|
|
|
|
const { parsed: members, parameters: temporaryParameters } = await this.client.resolver.infinite(params, [
|
|
|
|
this.client.resolver.resolveMember.bind(this.client.resolver)
|
|
|
|
], true, message.guild);
|
|
|
|
|
|
|
|
if(members.length === 0) return message.respond(message.format('C_ADDROLE_MISSINGMEMBERS'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
|
|
|
|
2021-06-26 08:42:57 +02:00
|
|
|
let { parsed: roles, parameters } = await this.client.resolver.infinite(temporaryParameters, [ //eslint-disable-line prefer-const
|
2020-07-04 12:23:10 +02:00
|
|
|
this.client.resolver.resolveRole.bind(this.client.resolver)
|
|
|
|
], true, message.guild);
|
|
|
|
|
|
|
|
if(roles.length === 0) return message.respond(message.format('C_ADDROLE_MISSINGROLES'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
|
|
|
|
2021-06-26 08:42:57 +02:00
|
|
|
const [firstArgument] = parameters;
|
|
|
|
const [, match ] = (/(\w{0,});?/ui).exec(firstArgument);
|
|
|
|
|
|
|
|
const time = this.client.resolver.resolveTime(match) || 0;
|
|
|
|
if(time !== 0) {
|
|
|
|
if(time < 0 || time > 2629801) { // approx. over 1 month (according to resolveTime)
|
|
|
|
return message.respond(message.format('C_ADDROLE_DURATIONEXCEPTION'), { emoji: 'failure' });
|
|
|
|
}
|
|
|
|
parameters = parameters.slice(1);
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
return this.client.moderationManager
|
2021-06-26 08:42:57 +02:00
|
|
|
.handleInfraction(Removerole, message, {
|
2020-07-04 12:23:10 +02:00
|
|
|
targets: members,
|
|
|
|
data: {
|
2021-06-12 09:12:40 +02:00
|
|
|
roleIds: roles.map((r) => r.id),
|
|
|
|
roleNames: roles.map((r) => r.display),
|
2020-07-04 12:23:10 +02:00
|
|
|
roles
|
|
|
|
},
|
2021-06-26 08:42:57 +02:00
|
|
|
duration: time,
|
2020-07-04 12:23:10 +02:00
|
|
|
reason: parameters.join(' ')
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RemoveroleCommand;
|