1- import glob from "glob" ;
21import type { Command , MyContext } from "../interfaces" ;
3- import {
4- ButtonInteraction ,
5- CommandInteraction ,
6- Interaction ,
7- Message ,
8- MessageActionRow ,
9- SelectMenuInteraction ,
10- } from "discord.js" ;
2+ import type { ButtonInteraction , CommandInteraction , Interaction , Message , SelectMenuInteraction } from "discord.js" ;
3+ import type { APIEmbed } from "discord-api-types" ;
4+
115import { commandCooldownCheck , commandPermissionCheck , deleteButton } from "../utils/CommandUtils" ;
126import { getSingleMDNSearchResults } from "../commands/docs/mdn" ;
137import { searchDJSDoc } from "../commands/docs/djs" ;
8+ import { MessageActionRow } from "discord.js" ;
9+
10+ import glob from "glob" ;
1411import Doc from "discord.js-docs" ;
15- import { APIEmbed } from "discord-api-types" ;
1612
1713export async function interactionCreateHandler ( context : MyContext , interaction : Interaction < "cached" > ) {
1814 if ( interaction . isCommand ( ) ) {
@@ -69,32 +65,48 @@ async function commandInteractionHandler(context: MyContext, interaction: Comman
6965}
7066async function selectMenuInteractionHandler ( context : MyContext , interaction : SelectMenuInteraction ) {
7167 const CommandName = interaction . customId . split ( "/" ) [ 0 ] ;
72- if ( ! CommandName ) interaction . reply ( { content : "Unknown menu" , ephemeral : true } ) . catch ( console . error ) ;
68+ if ( ! CommandName )
69+ switch ( CommandName ) {
70+ case "mdnselect" : {
71+ const Initiator = interaction . customId . split ( "/" ) [ 1 ] ;
72+ const deleteButtonRow = new MessageActionRow ( ) . addComponents ( [ deleteButton ( Initiator ) ] ) ;
73+ const selectedValue = interaction . values [ 0 ] ;
74+ const resultEmbed = await getSingleMDNSearchResults ( selectedValue ) ;
7375
74- if ( CommandName === "mdnselect" ) {
75- const Initiator = interaction . customId . split ( "/" ) [ 1 ] ;
76- const deleteButtonRow = new MessageActionRow ( ) . addComponents ( [ deleteButton ( Initiator ) ] ) ;
77- const selectedValue = interaction . values [ 0 ] ;
78- const resultEmbed = await getSingleMDNSearchResults ( selectedValue ) ;
76+ // Remove the menu and update the ephemeral message
77+ await interaction
78+ . update ( { content : "Sent documentation for " + selectedValue , components : [ ] } )
79+ . catch ( console . error ) ;
80+ // Send documentation
81+ await interaction
82+ . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } )
83+ . catch ( console . error ) ;
84+ break ;
85+ }
7986
80- await interaction
81- . update ( { content : "Sent documentation for " + selectedValue , components : [ ] } )
82- . catch ( console . error ) ;
83- await interaction . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } ) . catch ( console . error ) ;
84- } else if ( CommandName === "djsselect" ) {
85- const selectedValue = interaction . values [ 0 ] ;
86- const [ , source , searchPrivate , Initiator ] = interaction . customId . split ( "/" ) ;
87- const deleteButtonRow = new MessageActionRow ( ) . addComponents ( [ deleteButton ( Initiator ) ] ) ;
87+ case "djsselect" : {
88+ const selectedValue = interaction . values [ 0 ] ;
89+ const [ , source , searchPrivate , Initiator ] = interaction . customId . split ( "/" ) ;
90+ const deleteButtonRow = new MessageActionRow ( ) . addComponents ( [ deleteButton ( Initiator ) ] ) ;
8891
89- const doc = await Doc . fetch ( source , { force : true } ) ;
92+ const doc = await Doc . fetch ( source , { force : true } ) ;
9093
91- const resultEmbed = searchDJSDoc ( doc , selectedValue , searchPrivate === "true" ) as APIEmbed ;
94+ const resultEmbed = searchDJSDoc ( doc , selectedValue , searchPrivate === "true" ) as APIEmbed ;
9295
93- await interaction
94- . update ( { content : "Sent documentation for " + selectedValue , components : [ ] } )
95- . catch ( console . error ) ;
96- await interaction . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } ) . catch ( console . error ) ;
97- }
96+ // Remove the menu and update the ephemeral message
97+ await interaction
98+ . update ( { content : "Sent documentation for " + selectedValue , components : [ ] } )
99+ . catch ( console . error ) ;
100+ // Send documentation
101+ await interaction
102+ . followUp ( { embeds : [ resultEmbed ] , components : [ deleteButtonRow ] } )
103+ . catch ( console . error ) ;
104+ break ;
105+ }
106+ default : {
107+ interaction . reply ( { content : "Unknown menu" , ephemeral : true } ) . catch ( console . error ) ;
108+ }
109+ }
98110}
99111async function buttonInteractionHandler ( context : MyContext , interaction : ButtonInteraction < "cached" > ) {
100112 // The delete button
@@ -112,4 +124,5 @@ async function buttonInteractionHandler(context: MyContext, interaction: ButtonI
112124 . catch ( console . error ) ;
113125 }
114126}
115- // async function autocompleteInteractionHandler(context: MyContext, interaction: AutocompleteInteraction) {}
127+ // TODO add autocomplete
128+ // async function autocompleteInteractionHandler(context: MyContext, interaction: AutocompleteInteraction) {}s
0 commit comments