@@ -77,6 +77,36 @@ router.post('/', async (request, env) => {
7777 }
7878 }
7979
80+ if ( interaction . type === InteractionType . APPLICATION_COMMAND_AUTOCOMPLETE ) {
81+ switch ( interaction . data . name . toLowerCase ( ) ) {
82+ case _COMMAND . name . toLowerCase ( ) :
83+ case _COMMAND_HOSHI . name . toLowerCase ( ) :
84+ case _COMMAND_NEMI . name . toLowerCase ( ) : {
85+ // I know this code doesn't look or feel too great...
86+ // Please leave me alone, I'm a C# dev... I hate JS......
87+ const optionValue = interaction . data . options ?. [ 0 ] ?. value . toLowerCase ( ) ;
88+ const focused = optionValue || '' ;
89+
90+ const matches = Object . keys ( commandMap )
91+ . filter ( key => key . toLowerCase ( ) . includes ( focused ) )
92+ . slice ( 0 , 25 ) // Discord max
93+ . map ( key => ( {
94+ name : `${ key } - ${ ( ( commandMap [ key ] || commandMap [ 'help' ] ) . split ( ' ' ) . reduce ( ( a , w ) => a . length + w . length + 1 <= 25 ? a + ( a ? ' ' : '' ) + w : a , '' ) ) } ` , // what shows up in dropdown
95+ value : key , // what gets sent back if selected
96+ } ) ) ;
97+
98+ return new JsonResponse ( {
99+ type : InteractionResponseType . APPLICATION_COMMAND_AUTOCOMPLETE_RESULT ,
100+ data : {
101+ choices : matches ,
102+ } ,
103+ } ) ;
104+ }
105+ default :
106+ return new JsonResponse ( { error : 'Unknown Type' } , { status : 400 } ) ;
107+ }
108+ }
109+
80110 console . error ( 'Unknown Type' ) ;
81111 return new JsonResponse ( { error : 'Unknown Type' } , { status : 400 } ) ;
82112} ) ;
0 commit comments