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

82 lines
2.3 KiB
JavaScript
Raw Normal View History

const { Command } = require('../../../../interfaces/');
const { Slowmode } = require('../../../../moderation/infractions/');
class SlowmodeCommand extends Command {
constructor(client) {
super(client, {
name: 'slowmode',
module: 'moderation',
usage: "[channel..] <duration> [reason]",
clientPermissions: ['MANAGE_CHANNELS'],
memberPermissions: ['MANAGE_CHANNELS'],
examples: [
"#general #off-topic 5s influx of new users",
"10 raid"
],
keepQuotes: true,
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
}
});
this.client = client;
}
async execute(message, { params }) {
let { parsed, parameters } = await this.client.resolver.infinite(params, [ //eslint-disable-line prefer-const
this.client.resolver.resolveChannel.bind(this.client.resolver)
], true, message.guild);
if(parsed.length === 0) parsed = [ message.channel ];
const [firstArgument, ...rest] = parameters;
const [, match ] = (/(\w{0,});?/ui).exec(firstArgument);
const reason = rest.join(' ');
let time = this.client.resolver.resolveTime(match);
const int = parseInt(firstArgument);
if(!time) {
if(Number.isNaN(int)) {
return message.respond(message.format('C_SLOWMODE_SECONDREQUIRED'), {
emoji: 'failure'
});
}
time = int;
}
if(time < 0 || time > 21600) {
return message.respond(message.format('C_SLOWMODE_SECONDEXCEPTION'), {
emoji: 'failure'
});
}
return this.client.moderationManager
.handleInfraction(Slowmode, message, {
targets: parsed,
data: {
seconds: time
},
reason
});
}
}
module.exports = SlowmodeCommand;