forked from Galactic/galactic-bot
79 lines
2.6 KiB
JavaScript
79 lines
2.6 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
const { Addrole } = require('../../../../moderation/infractions/');
|
|
|
|
class AddroleCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'addrole',
|
|
module: 'moderation',
|
|
aliases: [
|
|
'roleadd',
|
|
'addroles',
|
|
'rolesadd'
|
|
],
|
|
usage: "<member..> <role..> [duration] [reason]",
|
|
clientPermissions: ['MANAGE_ROLES'],
|
|
memberPermissions: ['MANAGE_ROLES'],
|
|
examples: [],
|
|
arguments: [
|
|
{
|
|
name: 'silent',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG'],
|
|
default: true
|
|
}
|
|
],
|
|
guildOnly: true,
|
|
showUsage: true
|
|
});
|
|
}
|
|
|
|
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'
|
|
});
|
|
|
|
let { parsed: roles, parameters } = await this.client.resolver.infinite(temporaryParameters, [ //eslint-disable-line prefer-const
|
|
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'
|
|
});
|
|
|
|
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);
|
|
}
|
|
|
|
return this.client.moderationManager
|
|
.handleInfraction(Addrole, message, {
|
|
targets: members,
|
|
data: {
|
|
roleIds: roles.map((r) => r.id),
|
|
roleNames: roles.map((r) => r.display),
|
|
roles
|
|
},
|
|
reason: parameters.join(' '),
|
|
duration: time
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = AddroleCommand; |