/[sudobot]/trunk/src/events/message/MessageCreateEvent.ts
ViewVC logotype

Annotation of /trunk/src/events/message/MessageCreateEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 3800 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
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 rakin 51 import BaseEvent from '../../utils/structures/BaseEvent';
21     import { FileOptions, Message } from 'discord.js';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import path from 'path';
25     import MessageEmbed from '../../client/MessageEmbed';
26    
27     export default class MessageCreateEvent extends BaseEvent {
28     constructor() {
29     super('messageCreate');
30     }
31    
32     async run(client: DiscordClient, message: Message) {
33     if (message.author.bot || !message.guild || message.channel.type === 'DM')
34     return;
35    
36     await client.setMessage(message);
37    
38     await client.spamFilter.start(message);
39     await client.messageFilter.start(message);
40    
41     if (message.content.startsWith(client.config.get('prefix'))) {
42     const [cmdName, ...args] = await message.content
43     .slice(client.config.get('prefix').length)
44     .trim()
45     .split(/ +/);
46    
47     const command = await client.commands.get(cmdName);
48    
49     if (command && command.supportsLegacy) {
50 rakin 58 const allowed = await client.auth.verify(message.member!, command);
51    
52 rakin 51 if (allowed) {
53 rakin 54 const options = {
54 rakin 51 cmdName,
55     args,
56     argv: [cmdName, ...args],
57     normalArgs: args.filter(a => a[0] !== '-'),
58     options: args.filter(a => a[0] === '-'),
59     isInteraction: false
60 rakin 54 } as CommandOptions;
61    
62 rakin 207 await command.execute(client, message, options);
63 rakin 51 }
64     else {
65     await message.reply({
66     embeds: [
67     new MessageEmbed()
68     .setColor('#f14a60')
69     .setDescription(":x: You don't have permission to run this command.")
70     ]
71     });
72     }
73    
74     return;
75     }
76    
77 rakin 255 const snippet = await client.snippetManager.getParsed(message.guild!.id, cmdName);
78 rakin 51
79 rakin 256 if (snippet) {
80     try {
81     await message.channel.send({
82     content: snippet.content.trim() === '' ? undefined : snippet.content,
83     files: snippet.files.map(name => {
84     return {
85     name,
86 rakin 362 attachment: path.resolve(process.env.SUDO_PREFIX ?? path.join(__dirname, '../../..'), 'storage', name)
87 rakin 256 } as FileOptions
88     }),
89     embeds: snippet.embeds
90     });
91     }
92     catch (e) {
93     console.log(e);
94     }
95 rakin 51
96     return;
97     }
98     }
99    
100     await client.afkEngine.start(message);
101     }
102 rakin 362 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26