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

Contents of /branches/2.x/src/automod/AntiRaid.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: 2008 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { Collection, Guild, GuildMember, TextChannel } from 'discord.js';
2 import DiscordClient from '../client/Client';
3 import { lockAll } from '../commands/moderation/LockallCommand';
4
5 export default class AntiRaid {
6 constructor(private client: DiscordClient, private joins = 0, private maxJoins = 0, private channels: string[] = [], private exclude = false, private time = 0, private enabled = false) {
7
8 }
9
10 load(guild: Guild) {
11 this.maxJoins = this.client.config.props[guild.id].raid.max_joins;
12 this.channels = this.client.config.props[guild.id].raid.channels;
13 this.time = this.client.config.props[guild.id].raid.time;
14 this.enabled = this.client.config.props[guild.id].raid.enabled;
15 this.exclude = this.client.config.props[guild.id].raid.exclude;
16 }
17
18 async start(member: GuildMember) {
19 if (member.user.bot) {
20 console.log('bot');
21 return;
22 }
23
24 await this.load(member.guild);
25
26 if (!this.enabled)
27 return;
28
29 console.log('Joined');
30
31 setTimeout(() => {
32 this.joins = 0;
33 console.log('RAID reset');
34 }, this.time);
35
36 this.joins++;
37
38 if (this.joins === this.maxJoins) {
39 await this.trigger(member.guild);
40 }
41 }
42
43 async trigger(guild: Guild) {
44 let role = guild.roles.everyone;
45
46 let channels = <Collection <string, TextChannel>> guild.channels.cache.filter(channel => {
47 let cond: boolean;
48
49 if (this.exclude) {
50 cond = this.channels.indexOf(channel.id) === -1 && this.channels.indexOf(channel.parent?.id!) === -1;
51 }
52 else {
53 cond = this.channels.indexOf(channel.id) !== -1 || this.channels.indexOf(channel.parent?.id!) !== -1;
54 }
55
56 return cond && channel.type === 'GUILD_TEXT';
57 });
58
59 await lockAll(this.client, role, channels, this.client.user!, true);
60 }
61 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26