@@ -58,6 +58,8 @@ const prCommand: ApplicationCommand = {
5858
5959const commands = [ repositoryCommand , branchCommand , issueCommand , prCommand ] ;
6060
61+ const GUILD_ID = "683939861539192860" ;
62+
6163export type Handler = ( message : Message ) => Promise < void > ;
6264
6365export class InteractionsCommandReceiver {
@@ -67,16 +69,23 @@ export class InteractionsCommandReceiver {
6769 return ;
6870 }
6971 this . initialized = true ;
70- const registrar = client . guilds . cache . get ( "683939861539192860" ) ?. commands ;
72+ const registrar = client . guilds . cache . get ( GUILD_ID ) ?. commands ;
7173 if ( ! registrar ) {
7274 return ;
7375 }
76+ const oldCommands = await registrar . fetch ( ) ;
77+ await Promise . all (
78+ [ ...oldCommands . values ( ) ] . map ( ( com ) => registrar . delete ( com ) ) ,
79+ ) ;
7480 await Promise . all ( commands . map ( ( command ) => registrar . create ( command ) ) ) ;
7581 } ) ;
7682 client . on ( "interactionCreate" , ( interaction ) => {
7783 if ( ! interaction . isCommand ( ) ) {
7884 return ;
7985 }
86+ if ( interaction . guildId !== GUILD_ID ) {
87+ return ;
88+ }
8089 this . onCommand ( interaction ) ;
8190 } ) ;
8291 }
@@ -123,14 +132,28 @@ export class InteractionsCommandReceiver {
123132
124133 private buildCommandStr ( interaction : CommandInteraction ) : string {
125134 let commandStr = `/${ interaction . commandName } ` ;
126- commandStr += interaction . options . data
127- . filter ( ( { name } ) => name !== "branch" )
128- . map ( ( { value } ) => value )
129- . join ( "/" ) ;
130- commandStr += interaction . options . data
131- . filter ( ( { name } ) => name === "branch" )
132- . map ( ( { value } ) => value )
133- . join ( " " ) ;
135+ const [ orgArg ] = interaction . options . data . filter (
136+ ( { name } ) => name === "org" ,
137+ ) ;
138+ if ( orgArg ) {
139+ commandStr += `${ orgArg . value } /` ;
140+ }
141+ const [ repoArg ] = interaction . options . data . filter (
142+ ( { name } ) => name === "repo" ,
143+ ) ;
144+ commandStr += repoArg . value ;
145+ const [ issueArg ] = interaction . options . data . filter (
146+ ( { name } ) => name === "issue" ,
147+ ) ;
148+ if ( issueArg ) {
149+ commandStr += `/${ issueArg . value } ` ;
150+ }
151+ const [ branchArg ] = interaction . options . data . filter (
152+ ( { name } ) => name === "branch" ,
153+ ) ;
154+ if ( branchArg ) {
155+ commandStr += ` ${ branchArg . value } ` ;
156+ }
134157 return commandStr ;
135158 }
136159}
0 commit comments