1 |
rakin |
51 |
import BaseEvent from '../../utils/structures/BaseEvent'; |
2 |
|
|
import { GuildMember, Interaction, Message, MessageEmbed } from 'discord.js'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
rakin |
64 |
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
7 |
rakin |
51 |
|
8 |
|
|
export default class InteractionCreateEvent extends BaseEvent { |
9 |
|
|
constructor() { |
10 |
|
|
super('interactionCreate'); |
11 |
|
|
} |
12 |
|
|
|
13 |
|
|
async run(client: DiscordClient, interaction: Interaction) { |
14 |
rakin |
67 |
if (!interaction.guild || !interaction.channel || interaction.channel.type === 'DM') { |
15 |
|
|
if (interaction.isRepliable()) |
16 |
|
|
await interaction.reply({ |
17 |
|
|
content: 'You cannot use this bot on DMs.', |
18 |
|
|
ephemeral: true |
19 |
|
|
}); |
20 |
|
|
|
21 |
|
|
return; |
22 |
|
|
} |
23 |
rakin |
81 |
|
24 |
rakin |
125 |
if (interaction.isCommand() || interaction.isContextMenu()) { |
25 |
rakin |
51 |
await client.setMessage(interaction); |
26 |
|
|
|
27 |
|
|
const { commandName } = interaction; |
28 |
|
|
|
29 |
|
|
const command = await client.commands.get(commandName); |
30 |
|
|
|
31 |
rakin |
125 |
if (command && ((interaction.isCommand() && command.supportsInteractions) || (interaction.isContextMenu() && command.supportsContextMenu))) { |
32 |
rakin |
58 |
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
33 |
|
|
|
34 |
rakin |
51 |
if (!allowed) { |
35 |
|
|
await interaction.reply({ |
36 |
|
|
embeds: [ |
37 |
|
|
new MessageEmbed() |
38 |
|
|
.setColor('#f14a60') |
39 |
|
|
.setDescription(":x: You don't have permission to run this command.") |
40 |
|
|
], |
41 |
|
|
ephemeral: true |
42 |
|
|
}); |
43 |
|
|
|
44 |
|
|
return; |
45 |
|
|
} |
46 |
|
|
|
47 |
rakin |
55 |
const options = { |
48 |
rakin |
51 |
cmdName: commandName, |
49 |
|
|
options: interaction.options, |
50 |
|
|
isInteraction: true |
51 |
rakin |
55 |
} as InteractionOptions; |
52 |
|
|
|
53 |
|
|
if (!await client.cooldown.start(interaction, options)) |
54 |
|
|
return; |
55 |
|
|
|
56 |
rakin |
207 |
await command.execute(client, interaction, options); |
57 |
rakin |
81 |
(global as any).lastCommand = commandName; |
58 |
rakin |
51 |
} |
59 |
|
|
} |
60 |
rakin |
64 |
else if (interaction.isAutocomplete()) { |
61 |
|
|
await client.setMessage(interaction); |
62 |
|
|
|
63 |
|
|
const { commandName } = interaction; |
64 |
|
|
|
65 |
|
|
const command = await client.commands.get(commandName); |
66 |
|
|
|
67 |
|
|
if (command && command.supportsInteractions) { |
68 |
|
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
69 |
|
|
|
70 |
|
|
if (!allowed) { |
71 |
|
|
return; |
72 |
|
|
} |
73 |
|
|
|
74 |
rakin |
207 |
if (!(await command.perms(client, interaction))) { |
75 |
|
|
return; |
76 |
|
|
} |
77 |
|
|
|
78 |
rakin |
64 |
const options = { |
79 |
|
|
cmdName: commandName, |
80 |
|
|
options: interaction.options, |
81 |
|
|
isInteraction: true, |
82 |
|
|
optionName: interaction.options.getFocused(true).name, |
83 |
|
|
query: interaction.options.getFocused(true).value.toString() |
84 |
|
|
} as AutoCompleteOptions; |
85 |
|
|
|
86 |
|
|
await command.autoComplete(client, interaction, options); |
87 |
rakin |
81 |
(global as any).lastCommand = commandName; |
88 |
rakin |
64 |
} |
89 |
|
|
} |
90 |
rakin |
81 |
else { |
91 |
|
|
if (!(global as any).commandName) |
92 |
|
|
return; |
93 |
|
|
|
94 |
|
|
await client.setMessage(interaction); |
95 |
|
|
|
96 |
|
|
const command = await client.commands.get((global as any).commandName); |
97 |
|
|
|
98 |
|
|
if (command && command.supportsInteractions) { |
99 |
|
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
100 |
|
|
|
101 |
|
|
if (!allowed) { |
102 |
|
|
return; |
103 |
|
|
} |
104 |
rakin |
207 |
|
105 |
|
|
if (!(await command.perms(client, interaction))) { |
106 |
|
|
return; |
107 |
|
|
} |
108 |
rakin |
81 |
|
109 |
|
|
await command.default(client, interaction); |
110 |
|
|
} |
111 |
|
|
} |
112 |
rakin |
51 |
} |
113 |
|
|
} |