@@ -10,7 +10,8 @@ import {
10
10
import { Embed , Markup } from 'detritus-client/lib/utils' ;
11
11
import { Response } from 'detritus-rest' ;
12
12
13
- import { EmbedColors , PermissionsText } from '../../constants' ;
13
+ import { createUserCommand } from '../../api' ;
14
+ import { CommandTypes , EmbedColors , PermissionsText } from '../../constants' ;
14
15
import { DefaultParameters , Parameters , editOrReply } from '../../utils' ;
15
16
16
17
@@ -166,17 +167,69 @@ export class BaseInteractionCommand<ParsedArgsFinished = Interaction.ParsedArgs>
166
167
] . join ( '\n' ) ) ;
167
168
}
168
169
169
- return context . editOrRespond ( {
170
+ await context . editOrRespond ( {
170
171
embed,
171
172
flags : MessageFlags . EPHEMERAL ,
172
173
} ) ;
174
+
175
+ if ( context . invoker && context . invoker . metadata ) {
176
+ let commandType : null | number = null ;
177
+ switch ( context . command . type ) {
178
+ case ApplicationCommandTypes . CHAT_INPUT : commandType = CommandTypes . APPLICATION_SLASH ; break ;
179
+ case ApplicationCommandTypes . MESSAGE : commandType = CommandTypes . APPLICATION_MENU_MESSAGE ; break ;
180
+ case ApplicationCommandTypes . USER : commandType = CommandTypes . APPLICATION_MENU_USER ; break ;
181
+ default : commandType = null ;
182
+ }
183
+
184
+ if ( commandType !== null ) {
185
+ const metadata = context . invoker . metadata ;
186
+ const commandId = metadata . id || context . name . split ( ' ' ) . join ( '.' )
187
+ await createUserCommand (
188
+ context ,
189
+ context . userId ,
190
+ commandId ,
191
+ {
192
+ commandType,
193
+ channelId : context . channelId ! ,
194
+ failedReason : String ( error . message || error . stack ) . slice ( 0 , 256 ) ,
195
+ guildId : context . guildId ,
196
+ messageId : context . interactionId ,
197
+ responseId : context . responseId ,
198
+ } ,
199
+ ) ;
200
+ }
201
+ }
173
202
}
174
203
175
- /*
176
204
async onSuccess ( context : Interaction . InteractionContext , args : ParsedArgsFinished ) {
177
205
// log usage
206
+ if ( context . invoker && context . invoker . metadata ) {
207
+ let commandType : null | number = null ;
208
+ switch ( context . command . type ) {
209
+ case ApplicationCommandTypes . CHAT_INPUT : commandType = CommandTypes . APPLICATION_SLASH ; break ;
210
+ case ApplicationCommandTypes . MESSAGE : commandType = CommandTypes . APPLICATION_MENU_MESSAGE ; break ;
211
+ case ApplicationCommandTypes . USER : commandType = CommandTypes . APPLICATION_MENU_USER ; break ;
212
+ default : commandType = null ;
213
+ }
214
+
215
+ if ( commandType !== null ) {
216
+ const metadata = context . invoker . metadata ;
217
+ const commandId = metadata . id || context . name . split ( ' ' ) . join ( '.' )
218
+ await createUserCommand (
219
+ context ,
220
+ context . userId ,
221
+ commandId ,
222
+ {
223
+ commandType,
224
+ channelId : context . channelId ! ,
225
+ guildId : context . guildId ,
226
+ messageId : context . interactionId ,
227
+ responseId : context . responseId ,
228
+ } ,
229
+ ) ;
230
+ }
231
+ }
178
232
}
179
- */
180
233
}
181
234
182
235
0 commit comments