/[sudobot]/trunk/commands/clear.js
ViewVC logotype

Annotation of /trunk/commands/clear.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (hide annotations)
Mon Jul 29 17:28:16 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 1957 byte(s)
Added AFK engine
1 rakin 26 const MessageEmbed = require("../src/MessageEmbed");
2    
3     module.exports = {
4     needsOptionParse: true,
5     async handle(msg, cm) {
6     if (cm.normalArgs[0] === undefined) {
7     await msg.reply({
8     embeds: [
9     new MessageEmbed()
10     .setColor('#f14a60')
11     .setDescription('This command requires at least 1 argument.')
12     ]
13     });
14    
15     return;
16     }
17    
18     let user = msg.mentions.members.first();
19    
20     if (!user) {
21     user = msg.guild.members.cache.find(m => m.id === cm.normalArgs[0]);
22     }
23    
24     if (!user) {
25     await msg.reply({
26     embeds: [
27     new MessageEmbed()
28     .setColor('#f14a60')
29     .setDescription('Invalid user given.')
30     ]
31     });
32    
33     return;
34     }
35    
36     let fetched;
37     let count = 0;
38    
39     const message = await msg.reply({
40     embeds: [
41     new MessageEmbed()
42     .setColor('GOLD')
43     .setDescription('Deleting messages...')
44     ]
45     });
46    
47     do {
48     fetched = await msg.channel.messages.fetch({ limit: 100 });
49     fetched = await fetched.filter(m => m.author.id === user.id);
50     await msg.channel.bulkDelete(fetched);
51     count += fetched.size;
52     }
53     while(fetched.size >= 2);
54    
55     const guild = await app.client.guilds.fetch(app.config.props.global.id);
56     let emoji = ':white_check_mark:';
57    
58     if (guild) {
59     emoji = await guild.emojis.cache.find(e => e.name === 'check');
60     }
61    
62     await message.edit({
63     embeds: [
64     new MessageEmbed()
65     .setColor('GREEN')
66     .setDescription(emoji.toString() + " Deleted " + count + " message(s) from user " + user.user.tag)
67     ]
68     });
69     }
70     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26