/[sudobot]/branches/2.x/src/automod/AutoClear.ts
ViewVC logotype

Contents of /branches/2.x/src/automod/AutoClear.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2786 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { channelMention } from "@discordjs/builders";
2 import { Collection, Emoji, Guild, GuildMember, TextChannel } from "discord.js";
3 import DiscordClient from "../client/Client";
4 import MessageEmbed from "../client/MessageEmbed";
5 import { fetchEmoji } from "../utils/Emoji";
6
7 export default class AutoClear {
8 constructor(protected client: DiscordClient) {
9
10 }
11
12 async start(member: GuildMember, guild: Guild) {
13 const config = await this.client.config.props[guild.id].autoclear;
14
15 if (config.enabled) {
16 for await (const channelID of config.channels) {
17 try {
18 const channels = (<Collection<string, TextChannel>> await guild.channels.cache.filter(c => c.id === channelID || c.parent?.id === channelID)).toJSON();
19
20 if (channels) {
21 for await (const channel of channels) {
22 if (channel && channel.type === 'GUILD_TEXT') {
23 let fetched, count = 0;
24
25 do {
26 fetched = await channel!.messages.fetch({ limit: 100 });
27 fetched = await fetched.filter(m => m.author.id === member!.id);
28 await channel.bulkDelete(fetched);
29 count += await fetched.size;
30 }
31 while (fetched.size >= 2);
32
33 const messageOptions = {
34 embeds: [
35 new MessageEmbed()
36 .setColor('RED')
37 .setAuthor({
38 name: member.user.tag,
39 iconURL: member.displayAvatarURL()
40 })
41 .setDescription((await fetchEmoji('check') as Emoji).toString() + " Deleted " + count + " message(s) from user " + member.user.tag + ' in channel ' + channelMention(channel.id))
42 .addField('Reason', 'They left the server')
43 ]
44 };
45
46 await this.client.logger.channelJoinLeft(async (ch) => {
47 await ch.send(messageOptions);
48 }, member);
49 }
50 }
51 }
52 }
53 catch (e) {
54 console.log(e);
55 }
56 }
57 }
58 }
59 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26