galactic-bot/structure/client/components/commands/moderation/Ban.js

119 lines
3.7 KiB
JavaScript
Raw Normal View History

const { Command } = require('../../../../interfaces/');
const { Ban } = require('../../../../moderation/infractions/');
class BanCommand extends Command {
constructor(client) {
super(client, {
name: 'ban',
module: 'moderation',
usage: "<member..> [duration] [reason]",
clientPermissions: ['BAN_MEMBERS'],
memberPermissions: ['BAN_MEMBERS'],
aliases: [
'tempban',
'hardban'
],
examples: [
"24h @nolan#2887 @Navy.gif#1998 raiding the server"
],
keepQuotes: true,
arguments: [
{
name: 'points',
aliases: ['point', 'modpoints', 'modpoint', 'pts', 'pt'],
type: 'INTEGER',
types: ['VERBAL', 'FLAG'],
usage: '<amount>',
default: (guild) => {
return guild._settings.moderationPoints.points.KICK;
},
min: 0, max: 100,
ignoreInvalid: true,
required: true
},
{
name: 'expiration',
aliases: ['expire', 'expires', 'expirations'],
type: 'TIME',
types: ['FLAG'],
usage: '<time>',
default: (guild) => {
return guild._settings.moderationPoints.expirations.KICK;
}
},
{
name: 'force',
type: 'BOOLEAN',
types: ['FLAG'],
default: true
},
{
name: 'days',
aliases: ['day'],
type: 'INTEGER',
types: ['FLAG'],
usage: '<days>',
default: 1,
min: 1, max: 7,
ignoreInvalid: true
},
{
name: 'silent',
type: 'BOOLEAN',
types: ['FLAG'],
default: true
}
],
guildOnly: true,
showUsage: true
});
this.client = client;
}
async execute(message, { params }) {
const { parsed, parameters } = await this.client.resolver.infinite(params, [
this.client.resolver.resolveMember.bind(this.client.resolver),
this.client.resolver.resolveUser.bind(this.client.resolver)
], true, message.guild);
if(parsed.length === 0) {
return message.respond(message.format('C_BAN_MISSINGMEMBERS'), {
emoji: 'failure'
});
}
const [firstArgument] = parameters;
const [, match ] = (/(\w{0,});?/ui).exec(firstArgument);
let reason = parameters;
let time = this.client.resolver.resolveTime(match);
if(!time) {
if(message._caller === 'tempban') return message.respond(message.format('C_BAN_DURATIONREQUIRED'), { emoji: 'failure' });
time = 0;
} else {
2020-07-16 09:54:39 +02:00
reason = reason.slice(1);
}
if(time !== 0) {
if(time < 60 || time > 7889401) { // approx. over 3 months (according to resolveTime)
return message.respond(message.format('C_BAN_DURATIONEXCEPTION'), { emoji: 'failure' });
}
}
return this.client.moderationManager
.handleInfraction(Ban, message, {
targets: parsed,
duration: time,
2020-07-16 09:54:39 +02:00
reason: reason.join(' ')
});
}
}
module.exports = BanCommand;