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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 54 - (show annotations)
Mon Jul 29 17:28:24 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 2823 byte(s)
Added -emoji command and cooldown support
1 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 const options = {
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 if (!await client.cooldown.start(message, options))
43 return;
44
45 await command.run(client, message, options);
46 }
47 else {
48 await message.reply({
49 embeds: [
50 new MessageEmbed()
51 .setColor('#f14a60')
52 .setDescription(":x: You don't have permission to run this command.")
53 ]
54 });
55 }
56
57 return;
58 }
59
60 const snippet = await client.snippetManager.get(message.guild!.id, cmdName);
61
62 if (snippet) {
63 await message.channel.send({
64 content: snippet.content,
65 files: snippet.files.map(name => {
66 return {
67 name,
68 attachment: path.resolve(__dirname, '../../../storage', name)
69 } as FileOptions
70 }),
71 });
72
73 return;
74 }
75 }
76
77 await client.afkEngine.start(message);
78 }
79 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26