/[sudobot]/branches/6.x/src/events/message/MessageCreateEvent.ts
ViewVC logotype

Contents of /branches/6.x/src/events/message/MessageCreateEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 1 week ago) by rakinar2
File MIME type: application/typescript
File size: 2899 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2023 OSN Developers.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { ChannelType, GuildMember, Message, MessageType } from "discord.js";
21 import Client from "../../core/Client";
22 import EventListener from "../../core/EventListener";
23 import { Events } from "../../types/ClientEvents";
24 import { log, logError } from "../../utils/logger";
25
26 export default class MessageCreateEvent extends EventListener<Events.MessageCreate> {
27 public readonly name = Events.MessageCreate;
28
29 public types = [MessageType.Default, MessageType.Reply];
30
31 constructor(protected client: Client) {
32 super(client);
33 }
34
35 async execute(message: Message) {
36 /**
37 * For performance reasons, ignore bots completely.
38 */
39 if (message.author.bot) return;
40
41 super.execute(message);
42
43 if (!this.types.includes(message.type)) return;
44
45 if (message.channel.type === ChannelType.DM) return;
46
47 let member: GuildMember = <any>message.member!;
48
49 if (!(member.permissions as any)?.has) {
50 try {
51 member = await message.guild!.members.fetch(member.user.id);
52
53 if (!member) {
54 throw new Error("Invalid member");
55 }
56
57 (message.member as any) = member;
58 } catch (e) {
59 logError(e);
60 }
61 }
62
63 let deleted = await this.client.messageFilter.onMessageCreate(message).catch(logError);
64
65 if (deleted) return;
66
67 deleted = await this.client.messageRuleService.onMessageCreate(message).catch(logError);
68
69 if (deleted) return;
70
71 deleted = await this.client.fileFilter.onMessageCreate(message).catch(logError);
72
73 if (deleted) return;
74
75 deleted = await this.client.aiAutoMod.onMessageCreate(message).catch(logError);
76
77 if (deleted) return;
78
79 await this.client.antispam.onMessageCreate(message).catch(logError);
80 this.client.triggerService.onMessageCreate(message);
81
82 const value = await this.client.commandManager.runCommandFromMessage(message).catch(logError);
83
84 if (value === false) {
85 log("Command or snippet not found: all strategies failed");
86 }
87 }
88 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26