2020-07-04 12:23:10 +02:00
|
|
|
const { Command } = require('../../../../interfaces/');
|
|
|
|
const { Prune } = require('../../../../moderation/infractions/');
|
|
|
|
|
|
|
|
class PruneCommand extends Command {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
super(client, {
|
|
|
|
name: 'prune',
|
|
|
|
module: 'moderation',
|
|
|
|
usage: "[channel..] <amount> [reason]",
|
|
|
|
aliases: [
|
|
|
|
'purge'
|
|
|
|
],
|
|
|
|
clientPermissions: ['MANAGE_MESSAGES'],
|
|
|
|
memberPermissions: ['MANAGE_MESSAGES'],
|
|
|
|
examples: [
|
|
|
|
"50 -u @nolan#2887 @Navy#1998 they were spamming",
|
|
|
|
"10 bot spam -b"
|
|
|
|
],
|
|
|
|
arguments: [
|
|
|
|
{
|
|
|
|
name: 'users',
|
|
|
|
aliases: [
|
|
|
|
'user'
|
|
|
|
],
|
|
|
|
usage: '<member..>',
|
|
|
|
type: 'MEMBER',
|
|
|
|
types: ['FLAG'],
|
|
|
|
required: true,
|
|
|
|
infinite: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'bots',
|
|
|
|
aliases: ['bot', 'robots', 'robot'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
2020-08-08 00:21:28 +02:00
|
|
|
name: 'humans',
|
|
|
|
aliases: ['human'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'contains',
|
|
|
|
aliases: ['includes'],
|
2020-07-04 12:23:10 +02:00
|
|
|
usage: '<text>',
|
|
|
|
type: 'STRING',
|
|
|
|
types: ['FLAG'],
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'startswith',
|
|
|
|
aliases: [
|
|
|
|
'starts',
|
2020-08-08 00:21:28 +02:00
|
|
|
'begins',
|
|
|
|
'beginswith'
|
2020-07-04 12:23:10 +02:00
|
|
|
],
|
|
|
|
usage: '<text>',
|
|
|
|
type: 'STRING',
|
|
|
|
types: ['FLAG'],
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'endswith',
|
2020-08-08 00:21:28 +02:00
|
|
|
aliases: ['ends'],
|
2020-07-04 12:23:10 +02:00
|
|
|
usage: '<text>',
|
|
|
|
type: 'STRING',
|
|
|
|
types: ['FLAG'],
|
|
|
|
required: true
|
|
|
|
},
|
2020-08-08 00:21:28 +02:00
|
|
|
{
|
|
|
|
name: 'text',
|
|
|
|
aliases: ['texts'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'invites',
|
|
|
|
aliases: ['invite'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'links',
|
|
|
|
aliases: ['link'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
2020-07-04 12:23:10 +02:00
|
|
|
{
|
|
|
|
name: 'emojis',
|
|
|
|
aliases: ['emoji'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'reactions',
|
|
|
|
aliases: ['reaction'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'images',
|
|
|
|
aliases: ['image'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'attachments',
|
|
|
|
aliases: ['attachment'],
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'after',
|
|
|
|
usage: '<message-id>',
|
|
|
|
type: 'INTEGER',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'before',
|
|
|
|
usage: '<message-id>',
|
|
|
|
type: 'INTEGER',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'and',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'not',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'silent',
|
|
|
|
type: 'BOOLEAN',
|
|
|
|
types: ['FLAG'],
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
guildOnly: true,
|
|
|
|
showUsage: true,
|
|
|
|
throttling: {
|
|
|
|
usages: 2,
|
|
|
|
duration: 10
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-10 22:09:03 +02:00
|
|
|
async execute(message, { qParams }) {
|
2020-07-04 12:23:10 +02:00
|
|
|
|
2021-05-10 22:09:03 +02:00
|
|
|
let { parsed, parameters } = await this.client.resolver.infinite(qParams, [ //eslint-disable-line prefer-const
|
2020-07-04 12:23:10 +02:00
|
|
|
this.client.resolver.resolveChannel.bind(this.client.resolver)
|
2021-06-21 21:53:52 +02:00
|
|
|
], true, message.guild, (c) => c.type === 'text');
|
2020-07-04 12:23:10 +02:00
|
|
|
|
|
|
|
if(parsed.length === 0) parsed = [ message.channel ];
|
2020-08-08 00:21:28 +02:00
|
|
|
if(parsed.length > 3) return message.respond(message.format('C_PRUNE_CHANNELEXCEPTION'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
if(parameters.length === 0) return message.respond(message.format('C_PRUNE_INTEGERINVALID'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
|
|
|
|
2020-08-16 09:27:49 +02:00
|
|
|
let int = parseInt(parameters[0]);
|
2020-07-04 12:23:10 +02:00
|
|
|
if(Number.isNaN(int)) {
|
|
|
|
return message.respond(message.format('C_PRUNE_INTEGERINVALID'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
2020-08-16 09:27:49 +02:00
|
|
|
}
|
2020-07-04 12:23:10 +02:00
|
|
|
|
|
|
|
if(int < 1 || int > 300) {
|
|
|
|
return message.respond(message.format('C_PRUNE_INTEGEREXCEPTION'), {
|
|
|
|
emoji: 'failure'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-16 09:27:49 +02:00
|
|
|
if(int % 100 > 0) int++; //Increase amount by one (to delete command message) ONLY IF indivisible by 100, this is to save a message fetch call.
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
const reason = parameters.slice(1).join(' ');
|
|
|
|
|
|
|
|
return this.client.moderationManager
|
|
|
|
.handleInfraction(Prune, message, {
|
|
|
|
targets: parsed,
|
|
|
|
data: {
|
2020-08-14 08:29:58 +02:00
|
|
|
amount: int
|
2020-07-04 12:23:10 +02:00
|
|
|
},
|
|
|
|
reason
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PruneCommand;
|