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

Contents of /branches/7.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 ago) by rakinar2
File MIME type: application/typescript
File size: 2966 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 public readonly types = [MessageType.Default, MessageType.Reply];
29
30 constructor(protected client: Client) {
31 super(client);
32 }
33
34 async execute(message: Message) {
35 /**
36 * For performance reasons, ignore bots completely.
37 */
38 if (message.author.bot) return;
39
40 super.execute(message);
41
42 if (!this.types.includes(message.type)) return;
43 if (message.channel.type === ChannelType.DM) return;
44
45 let member: GuildMember = <any>message.member!;
46
47 if (!(member.permissions as any)?.has) {
48 try {
49 member = await message.guild!.members.fetch(member.user.id);
50
51 if (!member) {
52 throw new Error("Invalid member");
53 }
54
55 (message.member as any) = member;
56 } catch (e) {
57 logError(e);
58 }
59 }
60
61 let deleted = await this.client.messageFilter.onMessageCreate(message).catch(logError);
62
63 if (deleted) return;
64
65 deleted = await this.client.messageRuleService.onMessageCreate(message).catch(logError);
66
67 if (deleted) return;
68
69 deleted = await this.client.fileFilter.onMessageCreate(message).catch(logError);
70
71 if (deleted) return;
72
73 deleted = await this.client.aiAutoMod.onMessageCreate(message).catch(logError);
74
75 if (deleted) return;
76
77 await this.client.antispam.onMessageCreate(message).catch(logError);
78
79 this.client.statsService.onMessageCreate(message);
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