1 |
const MessageEmbed = require("../src/MessageEmbed"); |
2 |
const { getUser } = require("../src/UserInput"); |
3 |
|
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 |
try { |
20 |
var user = await getUser(cm.args[0], msg); |
21 |
|
22 |
console.log(user); |
23 |
|
24 |
if (!user) { |
25 |
throw new Error('Invalid User'); |
26 |
} |
27 |
} |
28 |
catch (e) { |
29 |
console.log(e); |
30 |
|
31 |
await msg.reply({ |
32 |
embeds: [ |
33 |
new MessageEmbed() |
34 |
.setColor('#f14a60') |
35 |
.setDescription(`Invalid user given.`) |
36 |
] |
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 |
count += await fetched.size; |
58 |
} |
59 |
while (fetched.size >= 2); |
60 |
|
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 |
}; |