summaryrefslogtreecommitdiff
path: root/server/src/commands/mod/Prune.ts
blob: 55307bc1691e98a058b8fd1923714a5227889699 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import { TextChannel } from 'discord.js';

export default class PruneMod extends Command {
    public constructor() {
        super('prune', {
            aliases: ['prune', 'clear', 'purge'],
            category: 'moderation',
            description: {
                content: 'Bulk delete a specified amount of message from the server.',
                usage: '[amount]',
                examples: [
                    '50'
                ]
            },
            ratelimit: 3,
            channel: 'guild',
            clientPermissions: ['MANAGE_MESSAGES'],
            userPermissions: ['MANAGE_MESSAGES'],
            args: [
                {
                    id: 'amount',
                    type: 'integer',
                    prompt: {
                        start: 'How many messages would you like to delete?'
                    }
                }
            ]
        });
    }
    
    public exec(msg: Message, { amount }): Promise<Message> {
        msg.delete();
        let limit = false;
        if (amount >= 100){
            amount = 99;
            limit = true;
        }
        (msg.channel as TextChannel).bulkDelete(amount, true);
        if (limit) {
            msg.reply('Due to Discord API limitations, the amount of messages you have specified has been rounded down to **99**. (This message will automatically be deleted in 3 seconds.)')
                .then(m => m.delete({ timeout: 3000 }));
        }
        if (amount > 1)
            return msg.reply(`**${amount}** messages have been successfully pruned!`);
        else
            return msg.reply(`**${amount}** message has been successfully pruned!`);
    }
}