4
4
"database/sql"
5
5
"fmt"
6
6
"strconv"
7
- "strings"
8
7
"time"
9
8
10
9
"github.com/KittyBot-Org/KittyBotGo/db/.gen/kittybot-go/public/model"
@@ -29,6 +28,9 @@ var Report = dbot.Command{
29
28
"confirm" : reportConfirmHandler ,
30
29
"delete" : reportDeleteHandler ,
31
30
},
31
+ ModalHandler : map [string ]dbot.ModalHandler {
32
+ "action-confirm" : reportActionConfirmHandler ,
33
+ },
32
34
}
33
35
34
36
func reportHandler (b * dbot.Bot , p * message.Printer , e * events.ApplicationCommandInteractionCreate ) error {
@@ -188,15 +190,8 @@ func reportConfirmHandler(b *dbot.Bot, args []string, p *message.Printer, e *eve
188
190
},
189
191
},
190
192
{
191
- Label : "Timeout User for 1 hour" ,
192
- Value : "timeout:1" ,
193
- Emoji : & discord.ComponentEmoji {
194
- Name : "🚫" ,
195
- },
196
- },
197
- {
198
- Label : "Timeout User for 1 day" ,
199
- Value : "timeout:24" ,
193
+ Label : "Timeout User" ,
194
+ Value : "timeout" ,
200
195
Emoji : & discord.ComponentEmoji {
201
196
Name : "🚫" ,
202
197
},
@@ -278,13 +273,13 @@ func reportActionHandler(b *dbot.Bot, args []string, p *message.Printer, e *even
278
273
})
279
274
}
280
275
281
- reason := rest . WithReason ( fmt .Sprintf ("automod action by %s caused by report %d" , e .User ().Tag (), reportID ) )
276
+ reason := fmt .Sprintf ("AutoMod action by: %s\n Caused by report # %d" , e .User ().Tag (), reportID )
282
277
283
278
var content string
284
279
value := e .SelectMenuInteractionData ().Values [0 ]
285
280
switch value {
286
281
case "delete-message" :
287
- if err = b .Client .Rest ().DeleteMessage (snowflake .MustParse (report .ChannelID ), snowflake .MustParse (report .MessageID ), reason ); err != nil {
282
+ if err = b .Client .Rest ().DeleteMessage (snowflake .MustParse (report .ChannelID ), snowflake .MustParse (report .MessageID ), rest . WithReason ( reason ) ); err != nil {
288
283
b .Logger .Errorf ("Failed to delete message: %s" , err )
289
284
content = "Failed to delete message, please reach out to a bot developer."
290
285
} else {
@@ -333,42 +328,138 @@ func reportActionHandler(b *dbot.Bot, args []string, p *message.Printer, e *even
333
328
content = formatReports (reports , * user )
334
329
}
335
330
336
- case "timeout:1" , "timeout:24" :
331
+ case "timeout" :
332
+ return e .CreateModal (discord.ModalCreate {
333
+ CustomID : discord .CustomID (fmt .Sprintf ("cmd:report:action-confirm:timeout:%s" , report .UserID )),
334
+ Title : "Timeout User" ,
335
+ Components : []discord.ContainerComponent {
336
+ discord.ActionRowComponent {
337
+ discord.TextInputComponent {
338
+ CustomID : "duration" ,
339
+ Style : discord .TextInputStyleShort ,
340
+ Label : "Timeout Duration" ,
341
+ MinLength : json .NewPtr (2 ),
342
+ Required : true ,
343
+ Placeholder : "time units: s, m, h example: 1h3s" ,
344
+ Value : "1h" ,
345
+ },
346
+ },
347
+ discord.ActionRowComponent {
348
+ discord.TextInputComponent {
349
+ CustomID : "reason" ,
350
+ Style : discord .TextInputStyleParagraph ,
351
+ Label : "Timeout Reason" ,
352
+ Required : true ,
353
+ Placeholder : "The reason for the timeout" ,
354
+ Value : reason ,
355
+ },
356
+ },
357
+ },
358
+ })
359
+
360
+ case "kick" :
361
+ return e .CreateModal (discord.ModalCreate {
362
+ CustomID : discord .CustomID (fmt .Sprintf ("cmd:report:action-confirm:kick:%s" , report .UserID )),
363
+ Title : "Kick User" ,
364
+ Components : []discord.ContainerComponent {
365
+ discord.ActionRowComponent {
366
+ discord.TextInputComponent {
367
+ CustomID : "reason" ,
368
+ Style : discord .TextInputStyleParagraph ,
369
+ Label : "Kick Reason" ,
370
+ Required : true ,
371
+ Placeholder : "The reason for the kick" ,
372
+ Value : reason ,
373
+ },
374
+ },
375
+ },
376
+ })
377
+
378
+ case "ban" :
379
+ return e .CreateModal (discord.ModalCreate {
380
+ CustomID : discord .CustomID (fmt .Sprintf ("cmd:report:action-confirm:ban:%s" , report .UserID )),
381
+ Title : "Ban User" ,
382
+ Components : []discord.ContainerComponent {
383
+ discord.ActionRowComponent {
384
+ discord.TextInputComponent {
385
+ CustomID : "del-days" ,
386
+ Style : discord .TextInputStyleShort ,
387
+ Label : "Message Delete Days" ,
388
+ MinLength : json .NewPtr (1 ),
389
+ MaxLength : 1 ,
390
+ Required : true ,
391
+ Placeholder : "0-7" ,
392
+ Value : "0" ,
393
+ },
394
+ },
395
+ discord.ActionRowComponent {
396
+ discord.TextInputComponent {
397
+ CustomID : "reason" ,
398
+ Style : discord .TextInputStyleParagraph ,
399
+ Label : "Ban Reason" ,
400
+ Required : true ,
401
+ Placeholder : "The reason for the ban" ,
402
+ Value : reason ,
403
+ },
404
+ },
405
+ },
406
+ })
407
+
408
+ default :
409
+ b .Logger .Errorf ("Unknown report action: %s" , value )
410
+ content = "Unknown action."
411
+ }
412
+ return e .CreateMessage (discord.MessageCreate {
413
+ Content : content ,
414
+ Flags : discord .MessageFlagEphemeral ,
415
+ })
416
+ }
417
+
418
+ func reportActionConfirmHandler (b * dbot.Bot , args []string , p * message.Printer , e * events.ModalSubmitInteractionCreate ) error {
419
+ userID := snowflake .MustParse (args [1 ])
420
+ reason := e .Data .Text ("reason" )
421
+
422
+ var content string
423
+ switch args [0 ] {
424
+ case "timeout" :
337
425
until := time .Now ()
338
- if strings .HasSuffix (value , "24" ) {
339
- until = until .Add (24 * time .Hour )
340
- } else {
341
- until = until .Add (1 * time .Hour )
342
- }
343
- if _ , err = b .Client .Rest ().UpdateMember (* e .GuildID (), snowflake .MustParse (report .UserID ), discord.MemberUpdate {
344
- CommunicationDisabledUntil : json .NewOptional (until ),
345
- }, reason ); err != nil {
346
- b .Logger .Errorf ("Failed to update member: %s" , err )
347
- content = "Failed to timeout user, please reach out to a bot developer."
426
+ duration , err := time .ParseDuration (e .Data .Text ("duration" ))
427
+ if err != nil {
428
+ content = "Invalid duration. Please use a valid duration."
348
429
} else {
349
- content = "User timed out."
430
+ until = until .Add (duration )
431
+ if _ , err = b .Client .Rest ().UpdateMember (* e .GuildID (), userID , discord.MemberUpdate {
432
+ CommunicationDisabledUntil : json .NewOptional (until ),
433
+ }, rest .WithReason (reason )); err != nil {
434
+ b .Logger .Errorf ("Failed to update member: %s" , err )
435
+ content = "Failed to timeout user, please reach out to a bot developer."
436
+ } else {
437
+ content = fmt .Sprintf ("Timed out user until %s." , discord .TimestampStyleShortDateTime .FormatTime (until ))
438
+ }
350
439
}
351
440
352
441
case "kick" :
353
- if err = b .Client .Rest ().RemoveMember (* e .GuildID (), snowflake . MustParse ( report . UserID ), reason ); err != nil {
442
+ if err : = b .Client .Rest ().RemoveMember (* e .GuildID (), userID , rest . WithReason ( reason ) ); err != nil {
354
443
b .Logger .Errorf ("Failed to kick user: %s" , err )
355
444
content = "Failed to kick user, please reach out to a bot developer."
356
445
} else {
357
446
content = "User kicked."
358
447
}
359
448
360
449
case "ban" :
361
- if err = b . Client . Rest (). AddBan ( * e . GuildID (), snowflake . MustParse ( report . UserID ), 0 , reason ); err != nil {
362
- b . Logger . Errorf ( "Failed to ban user: %s" , err )
363
- content = "Failed to ban user, please reach out to a bot developer ."
450
+ delDays , err := strconv . Atoi ( e . Data . Text ( "del-days" ))
451
+ if err != nil || delDays < 0 || delDays > 7 {
452
+ content = "Invalid message deletion days. Make sure it's a number between 0 and 7 ."
364
453
} else {
365
- content = "User banned."
454
+ if err = b .Client .Rest ().AddBan (* e .GuildID (), userID , 0 , rest .WithReason (reason )); err != nil {
455
+ b .Logger .Errorf ("Failed to ban user: %s" , err )
456
+ content = "Failed to ban user, please reach out to a bot developer."
457
+ } else {
458
+ content = fmt .Sprintf ("Banned %s. And deleted messages of the last %d days." , discord .UserMention (userID ), delDays )
459
+ }
366
460
}
367
-
368
- default :
369
- b .Logger .Errorf ("Unknown report action: %s" , value )
370
- content = "Unknown action."
371
461
}
462
+
372
463
return e .CreateMessage (discord.MessageCreate {
373
464
Content : content ,
374
465
Flags : discord .MessageFlagEphemeral ,
0 commit comments