/[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 58 - (hide annotations)
Mon Jul 29 17:28:25 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 2844 byte(s)
Added debug info support and startup manager
1 rakin 51 import BaseEvent from '../../utils/structures/BaseEvent';
2     import { FileOptions, Message } from 'discord.js';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import path from 'path';
6     import MessageEmbed from '../../client/MessageEmbed';
7    
8     export default class MessageCreateEvent extends BaseEvent {
9     constructor() {
10     super('messageCreate');
11     }
12    
13     async run(client: DiscordClient, message: Message) {
14     if (message.author.bot || !message.guild || message.channel.type === 'DM')
15     return;
16    
17     await client.setMessage(message);
18    
19     await client.spamFilter.start(message);
20     await client.messageFilter.start(message);
21    
22     if (message.content.startsWith(client.config.get('prefix'))) {
23     const [cmdName, ...args] = await message.content
24     .slice(client.config.get('prefix').length)
25     .trim()
26     .split(/ +/);
27    
28     const command = await client.commands.get(cmdName);
29    
30     if (command && command.supportsLegacy) {
31 rakin 58 const allowed = await client.auth.verify(message.member!, command);
32    
33 rakin 51 if (allowed) {
34 rakin 54 const options = {
35 rakin 51 cmdName,
36     args,
37     argv: [cmdName, ...args],
38     normalArgs: args.filter(a => a[0] !== '-'),
39     options: args.filter(a => a[0] === '-'),
40     isInteraction: false
41 rakin 54 } as CommandOptions;
42    
43     if (!await client.cooldown.start(message, options))
44     return;
45    
46     await command.run(client, message, options);
47 rakin 51 }
48     else {
49     await message.reply({
50     embeds: [
51     new MessageEmbed()
52     .setColor('#f14a60')
53     .setDescription(":x: You don't have permission to run this command.")
54     ]
55     });
56     }
57    
58     return;
59     }
60    
61     const snippet = await client.snippetManager.get(message.guild!.id, cmdName);
62    
63     if (snippet) {
64     await message.channel.send({
65     content: snippet.content,
66     files: snippet.files.map(name => {
67     return {
68     name,
69     attachment: path.resolve(__dirname, '../../../storage', name)
70     } as FileOptions
71     }),
72     });
73    
74     return;
75     }
76     }
77    
78     await client.afkEngine.start(message);
79     }
80     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26