/[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 362 - (hide annotations)
Mon Jul 29 17:29:47 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 3076 byte(s)
feat: make the system prefix changable
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 rakin 207 await command.execute(client, message, options);
44 rakin 51 }
45     else {
46     await message.reply({
47     embeds: [
48     new MessageEmbed()
49     .setColor('#f14a60')
50     .setDescription(":x: You don't have permission to run this command.")
51     ]
52     });
53     }
54    
55     return;
56     }
57    
58 rakin 255 const snippet = await client.snippetManager.getParsed(message.guild!.id, cmdName);
59 rakin 51
60 rakin 256 if (snippet) {
61     try {
62     await message.channel.send({
63     content: snippet.content.trim() === '' ? undefined : snippet.content,
64     files: snippet.files.map(name => {
65     return {
66     name,
67 rakin 362 attachment: path.resolve(process.env.SUDO_PREFIX ?? path.join(__dirname, '../../..'), 'storage', name)
68 rakin 256 } as FileOptions
69     }),
70     embeds: snippet.embeds
71     });
72     }
73     catch (e) {
74     console.log(e);
75     }
76 rakin 51
77     return;
78     }
79     }
80    
81     await client.afkEngine.start(message);
82     }
83 rakin 362 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26