1 |
rakinar2 |
577 |
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 |
|
|
const allowed = await client.auth.verify(message.member!, command); |
32 |
|
|
|
33 |
|
|
if (allowed) { |
34 |
|
|
const options = { |
35 |
|
|
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 |
|
|
} as CommandOptions; |
42 |
|
|
|
43 |
|
|
await command.execute(client, message, options); |
44 |
|
|
} |
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 |
|
|
const snippet = await client.snippetManager.getParsed(message.guild!.id, cmdName); |
59 |
|
|
|
60 |
|
|
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 |
|
|
attachment: path.resolve(__dirname, '../../../storage', name) |
68 |
|
|
} as FileOptions |
69 |
|
|
}), |
70 |
|
|
embeds: snippet.embeds |
71 |
|
|
}); |
72 |
|
|
} |
73 |
|
|
catch (e) { |
74 |
|
|
console.log(e); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
return; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
await client.afkEngine.start(message); |
82 |
|
|
} |
83 |
|
|
} |