29
29
30
30
import com .grack .nanojson .JsonArray ;
31
31
import com .grack .nanojson .JsonObject ;
32
+ import com .mewna .catnip .entity .interaction .InteractionResponseType ;
32
33
import com .mewna .catnip .entity .interaction .command .ApplicationCommand ;
33
34
import com .mewna .catnip .entity .interaction .command .ApplicationCommandOption ;
34
- import com .mewna .catnip .entity .interaction .InteractionResponseType ;
35
+ import com .mewna .catnip .entity .interaction .command . ApplicationCommandType ;
35
36
import com .mewna .catnip .entity .message .MentionParseFlag ;
36
37
import com .mewna .catnip .entity .message .Message ;
37
38
import com .mewna .catnip .entity .message .MessageFlag ;
@@ -67,34 +68,34 @@ public RestInteraction(final CatnipImpl catnip) {
67
68
// Initial response
68
69
69
70
public Completable createInteractionInitialResponse (@ Nonnull final InteractionResponseType type ,
70
- @ Nonnull final String interactionId ,
71
- @ Nonnull final String interactionToken ,
72
- @ Nonnull final MessageOptions options ) {
71
+ @ Nonnull final String interactionId ,
72
+ @ Nonnull final String interactionToken ,
73
+ @ Nonnull final MessageOptions options ) {
73
74
return createInteractionInitialResponse (type , interactionId , interactionToken , null , null , options );
74
75
}
75
76
76
77
public Completable createInteractionInitialResponse (@ Nonnull final InteractionResponseType type ,
77
- @ Nonnull final String interactionId ,
78
- @ Nonnull final String interactionToken ,
79
- @ Nullable final String username ,
80
- @ Nonnull final MessageOptions options ) {
78
+ @ Nonnull final String interactionId ,
79
+ @ Nonnull final String interactionToken ,
80
+ @ Nullable final String username ,
81
+ @ Nonnull final MessageOptions options ) {
81
82
return createInteractionInitialResponse (type , interactionId , interactionToken , username , null , options );
82
83
}
83
84
84
85
public Completable createInteractionInitialResponse (@ Nonnull final InteractionResponseType type ,
85
- @ Nonnull final String interactionId ,
86
- @ Nonnull final String interactionToken ,
87
- @ Nullable final String username , @ Nullable final String avatarUrl ,
88
- @ Nonnull final MessageOptions options ) {
86
+ @ Nonnull final String interactionId ,
87
+ @ Nonnull final String interactionToken ,
88
+ @ Nullable final String username , @ Nullable final String avatarUrl ,
89
+ @ Nonnull final MessageOptions options ) {
89
90
return createInteractionInitialResponseRaw (type , interactionId , interactionToken , username , avatarUrl , options );
90
91
}
91
92
92
93
public Completable createInteractionInitialResponseRaw (@ Nonnull final InteractionResponseType type ,
93
- @ Nonnull final String interactionId ,
94
- @ Nonnull final String interactionToken ,
95
- @ Nullable final String username ,
96
- @ Nullable final String avatarUrl ,
97
- @ Nonnull final MessageOptions options ) {
94
+ @ Nonnull final String interactionId ,
95
+ @ Nonnull final String interactionToken ,
96
+ @ Nullable final String username ,
97
+ @ Nullable final String avatarUrl ,
98
+ @ Nonnull final MessageOptions options ) {
98
99
final var body = createSendBody (type , username , avatarUrl , options );
99
100
return Completable .fromObservable (catnip ().requester ().
100
101
queue (new OutboundRequest (Routes .CREATE_INTERACTION_INITIAL_RESPONSE .withMajorParam (interactionId )
@@ -231,34 +232,38 @@ public Observable<ApplicationCommand> getGlobalApplicationCommands() {
231
232
232
233
public Observable <JsonArray > getGlobalApplicationCommandsRaw () {
233
234
return catnip ().requester ().queue (new OutboundRequest (Routes .GET_GLOBAL_APPLICATION_COMMANDS .withMajorParam (catnip ().clientId ()),
234
- Map .of ()))
235
+ Map .of ()))
235
236
.map (ResponsePayload ::array );
236
237
}
237
238
238
- public Single <ApplicationCommand > createGlobalApplicationCommand (@ Nonnull final String name , @ Nonnull final String description ,
239
+ public Single <ApplicationCommand > createGlobalApplicationCommand (@ Nonnull final ApplicationCommandType type ,
240
+ @ Nonnull final String name , @ Nonnull final String description ,
239
241
@ Nonnull final Collection <ApplicationCommandOption > options ) {
240
- return Single .fromObservable (createGlobalApplicationCommandRaw (name , description , options )
242
+ return Single .fromObservable (createGlobalApplicationCommandRaw (type , name , description , options )
241
243
.map (entityBuilder ()::createApplicationCommand ));
242
244
}
243
245
244
- public Observable <JsonObject > createGlobalApplicationCommandRaw (@ Nonnull final String name , @ Nonnull final String description ,
246
+ public Observable <JsonObject > createGlobalApplicationCommandRaw (@ Nonnull final ApplicationCommandType type ,
247
+ @ Nonnull final String name , @ Nonnull final String description ,
245
248
@ Nonnull final Collection <ApplicationCommandOption > options ) {
246
- final JsonObject body = createCommandBody (name , description , options );
249
+ final JsonObject body = createCommandBody (type , name , description , options );
247
250
return catnip ().requester ().queue (new OutboundRequest (Routes .CREATE_GLOBAL_APPLICATION_COMMAND
248
251
.withMajorParam (catnip ().clientId ()), Map .of ()).object (body )).map (ResponsePayload ::object );
249
252
}
250
253
251
- public Single <ApplicationCommand > editGlobalApplicationCommand (@ Nonnull final String name , @ Nonnull final String description ,
254
+ public Single <ApplicationCommand > editGlobalApplicationCommand (@ Nonnull final ApplicationCommandType type ,
255
+ @ Nonnull final String name , @ Nonnull final String description ,
252
256
@ Nonnull final String commandId ,
253
257
@ Nonnull final Collection <ApplicationCommandOption > options ) {
254
- return Single .fromObservable (editGlobalApplicationCommandRaw (name , description , commandId , options )
258
+ return Single .fromObservable (editGlobalApplicationCommandRaw (type , name , description , commandId , options )
255
259
.map (entityBuilder ()::createApplicationCommand ));
256
260
}
257
261
258
- public Observable <JsonObject > editGlobalApplicationCommandRaw (@ Nonnull final String name , @ Nonnull final String description ,
262
+ public Observable <JsonObject > editGlobalApplicationCommandRaw (@ Nonnull final ApplicationCommandType type ,
263
+ @ Nonnull final String name , @ Nonnull final String description ,
259
264
@ Nonnull final String commandId ,
260
265
@ Nonnull final Collection <ApplicationCommandOption > options ) {
261
- final var body = createCommandBody (name , description , options );
266
+ final var body = createCommandBody (type , name , description , options );
262
267
return catnip ().requester ().queue (new OutboundRequest (Routes .EDIT_GLOBAL_APPLICATION_COMMAND
263
268
.withMajorParam (catnip ().clientId ()), Map .of ("command" , commandId )).object (body )).map (ResponsePayload ::object );
264
269
}
@@ -278,40 +283,44 @@ public Observable<ApplicationCommand> getGuildApplicationCommands(@Nonnull final
278
283
279
284
public Observable <JsonArray > getGuildApplicationCommandsRaw (@ Nonnull final String guildId ) {
280
285
return catnip ().requester ().queue (new OutboundRequest (Routes .GET_GUILD_APPLICATION_COMMANDS .withMajorParam (catnip ().clientId ()),
281
- Map .of ("guild" , guildId )))
286
+ Map .of ("guild" , guildId )))
282
287
.map (ResponsePayload ::array );
283
288
}
284
289
285
- public Single <ApplicationCommand > createGuildApplicationCommand (@ Nonnull final String guildId , @ Nonnull final String name ,
290
+ public Single <ApplicationCommand > createGuildApplicationCommand (@ Nonnull final ApplicationCommandType type ,
291
+ @ Nonnull final String guildId , @ Nonnull final String name ,
286
292
@ Nonnull final String description ,
287
293
@ Nonnull final Collection <ApplicationCommandOption > options ) {
288
- return Single .fromObservable (createGuildApplicationCommandRaw (guildId , name , description , options )
294
+ return Single .fromObservable (createGuildApplicationCommandRaw (type , guildId , name , description , options )
289
295
.map (entityBuilder ()::createApplicationCommand ));
290
296
}
291
297
292
- public Observable <JsonObject > createGuildApplicationCommandRaw (@ Nonnull final String guildId , @ Nonnull final String name ,
298
+ public Observable <JsonObject > createGuildApplicationCommandRaw (@ Nonnull final ApplicationCommandType type ,
299
+ @ Nonnull final String guildId , @ Nonnull final String name ,
293
300
@ Nonnull final String description ,
294
301
@ Nonnull final Collection <ApplicationCommandOption > options ) {
295
- final var body = createCommandBody (name , description , options );
302
+ final var body = createCommandBody (type , name , description , options );
296
303
return catnip ().requester ().queue (new OutboundRequest (Routes .CREATE_GUILD_APPLICATION_COMMAND
297
304
.withMajorParam (catnip ().clientId ()), Map .of ("guild" , guildId )).object (body )).map (ResponsePayload ::object );
298
305
}
299
306
300
- public Single <ApplicationCommand > editGuildApplicationCommand (@ Nonnull final String guildId , @ Nonnull final String name ,
307
+ public Single <ApplicationCommand > editGuildApplicationCommand (@ Nonnull final ApplicationCommandType type ,
308
+ @ Nonnull final String guildId , @ Nonnull final String name ,
301
309
@ Nonnull final String description ,
302
310
@ Nonnull final String commandId ,
303
311
@ Nonnull final Collection <ApplicationCommandOption > options ) {
304
- return Single .fromObservable (editGuildApplicationCommandRaw (guildId , name , description , commandId , options )
312
+ return Single .fromObservable (editGuildApplicationCommandRaw (type , guildId , name , description , commandId , options )
305
313
.map (entityBuilder ()::createApplicationCommand ));
306
314
}
307
315
308
- public Observable <JsonObject > editGuildApplicationCommandRaw (@ Nonnull final String guildId , @ Nonnull final String name ,
316
+ public Observable <JsonObject > editGuildApplicationCommandRaw (@ Nonnull final ApplicationCommandType type ,
317
+ @ Nonnull final String guildId , @ Nonnull final String name ,
309
318
@ Nonnull final String description ,
310
319
@ Nonnull final String commandId ,
311
320
@ Nonnull final Collection <ApplicationCommandOption > options ) {
312
- final var body = createCommandBody (name , description , options );
321
+ final var body = createCommandBody (type , name , description , options );
313
322
return catnip ().requester ().queue (new OutboundRequest (Routes .EDIT_GUILD_APPLICATION_COMMAND
314
- .withMajorParam (catnip ().clientId ()), Map .of ("guild" , guildId , "command" , commandId )).object (body ))
323
+ .withMajorParam (catnip ().clientId ()), Map .of ("guild" , guildId , "command" , commandId )).object (body ))
315
324
.map (ResponsePayload ::object );
316
325
}
317
326
@@ -393,11 +402,12 @@ private JsonObject createSendBody(@Nullable final InteractionResponseType type,
393
402
return builder .done ();
394
403
}
395
404
396
- private JsonObject createCommandBody (@ Nonnull final String name , @ Nonnull final String description ,
397
- @ Nonnull final Collection <ApplicationCommandOption > options ) {
405
+ private JsonObject createCommandBody (@ Nonnull final ApplicationCommandType type , @ Nonnull final String name ,
406
+ @ Nonnull final String description , @ Nonnull final Collection <ApplicationCommandOption > options ) {
398
407
final var builder = JsonObject .builder ();
399
408
builder .value ("name" , name );
400
409
builder .value ("description" , description );
410
+ builder .value ("type" , type .id ());
401
411
if (!options .isEmpty ()) {
402
412
final List <JsonObject > optionJson = options .stream ()
403
413
.map (ApplicationCommandOption ::toJson )
0 commit comments