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

Annotation of /trunk/commands/clear.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations)
Mon Jul 29 17:28:21 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 2078 byte(s)
Release version 1.10.0

* Added -queues command to list all queued jobs
* Added -joke command to fetch random jokes
* Added support of user tags in some user-based commands
1 rakin 26 const MessageEmbed = require("../src/MessageEmbed");
2 rakin 49 const { getUser } = require("../src/UserInput");
3 rakin 26
4     module.exports = {
5     needsOptionParse: true,
6     async handle(msg, cm) {
7     if (cm.normalArgs[0] === undefined) {
8     await msg.reply({
9     embeds: [
10     new MessageEmbed()
11     .setColor('#f14a60')
12     .setDescription('This command requires at least 1 argument.')
13     ]
14     });
15    
16     return;
17     }
18    
19 rakin 49 try {
20     var user = await getUser(cm.args[0], msg);
21 rakin 26
22 rakin 49 console.log(user);
23    
24     if (!user) {
25     throw new Error('Invalid User');
26     }
27 rakin 26 }
28 rakin 49 catch (e) {
29     console.log(e);
30 rakin 26
31     await msg.reply({
32     embeds: [
33     new MessageEmbed()
34     .setColor('#f14a60')
35 rakin 49 .setDescription(`Invalid user given.`)
36 rakin 26 ]
37     });
38    
39     return;
40     }
41    
42     let fetched;
43     let count = 0;
44    
45     const message = await msg.reply({
46     embeds: [
47     new MessageEmbed()
48     .setColor('GOLD')
49     .setDescription('Deleting messages...')
50     ]
51     });
52    
53     do {
54     fetched = await msg.channel.messages.fetch({ limit: 100 });
55     fetched = await fetched.filter(m => m.author.id === user.id);
56     await msg.channel.bulkDelete(fetched);
57 rakin 49 count += await fetched.size;
58 rakin 26 }
59 rakin 49 while (fetched.size >= 2);
60 rakin 26
61     const guild = await app.client.guilds.fetch(app.config.props.global.id);
62     let emoji = ':white_check_mark:';
63    
64     if (guild) {
65     emoji = await guild.emojis.cache.find(e => e.name === 'check');
66     }
67    
68     await message.edit({
69     embeds: [
70     new MessageEmbed()
71     .setColor('GREEN')
72     .setDescription(emoji.toString() + " Deleted " + count + " message(s) from user " + user.user.tag)
73     ]
74     });
75     }
76     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26