forked from Galactic/galactic-bot
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
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"
|
|
],
|
|
arguments: [
|
|
{
|
|
name: 'silent',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG'],
|
|
default: true
|
|
}
|
|
],
|
|
guildOnly: true,
|
|
showUsage: true,
|
|
throttling: {
|
|
usages: 2,
|
|
duration: 10
|
|
}
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute(message, { qParams }) {
|
|
|
|
let { parsed, parameters } = await this.client.resolver.infinite(qParams, [ //eslint-disable-line prefer-const
|
|
this.client.resolver.resolveChannel.bind(this.client.resolver)
|
|
], true, message.guild, (c) => c.type === 'text');
|
|
|
|
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; |