/[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 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2652 byte(s)
Release version 2.0
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     const allowed = await client.auth.verify(message.member!, cmdName);
30    
31     if (command && command.supportsLegacy) {
32     if (allowed) {
33     await command.run(client, message, {
34     cmdName,
35     args,
36     argv: [cmdName, ...args],
37     normalArgs: args.filter(a => a[0] !== '-'),
38     options: args.filter(a => a[0] === '-'),
39     isInteraction: false
40     } as CommandOptions);
41     }
42     else {
43     await message.reply({
44     embeds: [
45     new MessageEmbed()
46     .setColor('#f14a60')
47     .setDescription(":x: You don't have permission to run this command.")
48     ]
49     });
50     }
51    
52     return;
53     }
54    
55     const snippet = await client.snippetManager.get(message.guild!.id, cmdName);
56    
57     if (snippet) {
58     await message.channel.send({
59     content: snippet.content,
60     files: snippet.files.map(name => {
61     return {
62     name,
63     attachment: path.resolve(__dirname, '../../../storage', name)
64     } as FileOptions
65     }),
66     });
67    
68     return;
69     }
70     }
71    
72     await client.afkEngine.start(message);
73     }
74     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26