const { Command } = require('../../../../interfaces/'); const { Prune } = require('../../../../moderation/infractions/'); class PruneCommand extends Command { constructor(client) { super(client, { name: 'prune', module: 'moderation', usage: "[channel..] [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: '', type: 'MEMBER', types: ['FLAG'], required: true, infinite: true }, { name: 'bots', aliases: ['bot', 'robots', 'robot'], type: 'BOOLEAN', types: ['FLAG'], default: true }, { name: 'humans', aliases: ['human'], type: 'BOOLEAN', types: ['FLAG'], default: true }, { name: 'contains', aliases: ['includes'], usage: '', type: 'STRING', types: ['FLAG'], required: true }, { name: 'startswith', aliases: [ 'starts', 'begins', 'beginswith' ], usage: '', type: 'STRING', types: ['FLAG'], required: true }, { name: 'endswith', aliases: ['ends'], usage: '', type: 'STRING', types: ['FLAG'], required: true }, { 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 }, { 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: '', type: 'INTEGER', types: ['FLAG'], default: true, required: true }, { name: 'before', usage: '', 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 } }); } 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 ]; if(parsed.length > 3) return message.respond(message.format('C_PRUNE_CHANNELEXCEPTION'), { emoji: 'failure' }); if(parameters.length === 0) return message.respond(message.format('C_PRUNE_INTEGERINVALID'), { emoji: 'failure' }); let int = parseInt(parameters[0]); if(Number.isNaN(int)) { return message.respond(message.format('C_PRUNE_INTEGERINVALID'), { emoji: 'failure' }); } if(int < 1 || int > 300) { return message.respond(message.format('C_PRUNE_INTEGEREXCEPTION'), { emoji: 'failure' }); } 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. const reason = parameters.slice(1).join(' '); return this.client.moderationManager .handleInfraction(Prune, message, { targets: parsed, data: { amount: int }, reason }); } } module.exports = PruneCommand;