1 |
import { TextChannel } from "discord.js"; |
2 |
import CommandOptions from "../types/CommandOptions"; |
3 |
import { fetchEmoji } from "../utils/Emoji"; |
4 |
import Queue from "../utils/structures/Queue"; |
5 |
|
6 |
export default class CustomQueue extends Queue { |
7 |
async execute({ channelID, guildID, messageID, cmd }: { [key: string]: string }): Promise<any> { |
8 |
const guild = this.client.guilds.cache.get(guildID); |
9 |
|
10 |
if (!guild) { |
11 |
return; |
12 |
} |
13 |
|
14 |
const channel = guild.channels.cache.get(channelID) as TextChannel; |
15 |
|
16 |
if (!channel || !['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'].includes(channel.type)) { |
17 |
return; |
18 |
} |
19 |
|
20 |
try { |
21 |
const message = await channel.messages.fetch(messageID); |
22 |
|
23 |
if (message) { |
24 |
const [commandName, ...args] = cmd; |
25 |
const command = this.client.commands.get(commandName); |
26 |
|
27 |
if (!command) { |
28 |
return message.reply(":x: Command not found"); |
29 |
} |
30 |
|
31 |
if (!command.supportsLegacy) { |
32 |
return message.reply(":x: This command does not support legacy message handler."); |
33 |
} |
34 |
|
35 |
const allowed = await this.client.auth.verify(message.member!, command); |
36 |
|
37 |
if (!allowed) { |
38 |
return message.reply(":x: Operation not permitted. You don't have enough permissions."); |
39 |
} |
40 |
|
41 |
const options = { |
42 |
cmdName: commandName, |
43 |
args, |
44 |
argv: [commandName, ...args], |
45 |
normalArgs: args.filter(a => a[0] !== '-'), |
46 |
options: args.filter(a => a[0] === '-'), |
47 |
isInteraction: false |
48 |
} as CommandOptions; |
49 |
|
50 |
await command.execute(this.client, message, options); |
51 |
} |
52 |
} |
53 |
catch (e) { |
54 |
console.log(e); |
55 |
} |
56 |
} |
57 |
} |