/[sudobot]/trunk/src/events/interaction/InteractionCreateEvent.ts
ViewVC logotype

Diff of /trunk/src/events/interaction/InteractionCreateEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/events/interaction/InteractionCreate.ts revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC trunk/src/events/interaction/InteractionCreateEvent.ts revision 125 by rakin, Mon Jul 29 17:28:41 2024 UTC
# Line 3  import { GuildMember, Interaction, Messa Line 3  import { GuildMember, Interaction, Messa
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
5  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
6    import AutoCompleteOptions from '../../types/AutoCompleteOptions';
7    
8  export default class InteractionCreateEvent extends BaseEvent {  export default class InteractionCreateEvent extends BaseEvent {
9      constructor() {      constructor() {
# Line 10  export default class InteractionCreateEv Line 11  export default class InteractionCreateEv
11      }      }
12    
13      async run(client: DiscordClient, interaction: Interaction) {      async run(client: DiscordClient, interaction: Interaction) {
14          console.log('inside');          if (!interaction.guild || !interaction.channel || interaction.channel.type === 'DM') {
15                        if (interaction.isRepliable())
16          if (interaction.isCommand()) {                  await interaction.reply({
17                        content: 'You cannot use this bot on DMs.',
18                        ephemeral: true
19                    });
20    
21                return;
22            }
23    
24            if (interaction.isCommand() || interaction.isContextMenu()) {
25              await client.setMessage(interaction);              await client.setMessage(interaction);
26    
27              const { commandName } = interaction;              const { commandName } = interaction;
28    
29              const command = await client.commands.get(commandName);              const command = await client.commands.get(commandName);
             const allowed = await client.auth.verify(interaction.member! as GuildMember, commandName);  
30    
31              if (command && command.supportsInteractions) {              if (command && ((interaction.isCommand() && command.supportsInteractions) || (interaction.isContextMenu() && command.supportsContextMenu))) {
32                    const allowed = await client.auth.verify(interaction.member! as GuildMember, command);
33    
34                  if (!allowed) {                  if (!allowed) {
35                      await interaction.reply({                      await interaction.reply({
36                          embeds: [                          embeds: [
# Line 34  export default class InteractionCreateEv Line 44  export default class InteractionCreateEv
44                      return;                      return;
45                  }                  }
46    
47                  await command.run(client, interaction, {                  const options = {
48                      cmdName: commandName,                      cmdName: commandName,
49                      options: interaction.options,                      options: interaction.options,
50                      isInteraction: true                      isInteraction: true
51                  } as InteractionOptions);                  } as InteractionOptions;
52    
53                    if (!await client.cooldown.start(interaction, options))
54                        return;
55    
56                    await command.run(client, interaction, options);
57                    (global as any).lastCommand = commandName;
58                }
59            }
60            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                    const options = {
75                        cmdName: commandName,
76                        options: interaction.options,
77                        isInteraction: true,
78                        optionName: interaction.options.getFocused(true).name,
79                        query: interaction.options.getFocused(true).value.toString()
80                    } as AutoCompleteOptions;
81    
82                    await command.autoComplete(client, interaction, options);
83                    (global as any).lastCommand = commandName;
84                }
85            }
86            else {
87                if (!(global as any).commandName)
88                    return;
89    
90                await client.setMessage(interaction);
91    
92                const command = await client.commands.get((global as any).commandName);
93    
94                if (command && command.supportsInteractions) {
95                    const allowed = await client.auth.verify(interaction.member! as GuildMember, command);
96    
97                    if (!allowed) {
98                        return;
99                    }
100    
101                    await command.default(client, interaction);
102              }              }
103          }          }
104      }      }

Legend:
Removed from v.51  
changed lines
  Added in v.125

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26