22
33import net .dv8tion .jda .api .Permission ;
44import net .dv8tion .jda .api .entities .ChannelType ;
5+ import net .dv8tion .jda .api .entities .Emoji ;
56import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
7+ import net .dv8tion .jda .api .exceptions .ErrorHandler ;
68import net .dv8tion .jda .api .interactions .commands .OptionMapping ;
79import net .dv8tion .jda .api .interactions .commands .OptionType ;
810import net .dv8tion .jda .api .interactions .commands .build .OptionData ;
911import net .dv8tion .jda .api .interactions .commands .build .SubcommandData ;
12+ import net .dv8tion .jda .api .interactions .components .ActionRow ;
13+ import net .dv8tion .jda .api .interactions .components .buttons .Button ;
14+ import net .dv8tion .jda .api .requests .ErrorResponse ;
1015import technobot .TechnoBot ;
1116import technobot .commands .Category ;
1217import technobot .commands .Command ;
1318import technobot .data .GuildData ;
1419import technobot .data .cache .Greetings ;
1520import technobot .handlers .GreetingHandler ;
21+ import technobot .listeners .ButtonListener ;
1622import technobot .util .embeds .EmbedUtils ;
1723
24+ import java .util .ArrayList ;
25+ import java .util .List ;
26+ import java .util .UUID ;
27+ import java .util .concurrent .TimeUnit ;
28+
1829/**
1930 * Command that displays and modifies greetings config.
2031 *
@@ -28,10 +39,11 @@ public GreetingsCommand(TechnoBot bot) {
2839 this .description = "Modify this server's greetings config." ;
2940 this .category = Category .GREETINGS ;
3041 this .permission = Permission .MANAGE_SERVER ;
31- this .subCommands .add (new SubcommandData ("channel" , "Sets a channel to send welcome messages to." )
42+ this .subCommands .add (new SubcommandData ("channel" , "Set a channel to send welcome messages to." )
3243 .addOptions (new OptionData (OptionType .CHANNEL , "channel" , "The channel to send welcome messages to" )
3344 .setChannelTypes (ChannelType .TEXT , ChannelType .NEWS )));
34- this .subCommands .add (new SubcommandData ("config" , "Displays the greetings config for this server." ));
45+ this .subCommands .add (new SubcommandData ("config" , "Display the greetings config for this server." ));
46+ this .subCommands .add (new SubcommandData ("reset" , "Reset all greetings data and settings." ));
3547 }
3648
3749 @ Override
@@ -59,6 +71,28 @@ public void execute(SlashCommandInteractionEvent event) {
5971 event .getHook ().sendMessage (text ).queue ();
6072 return ;
6173 }
74+ case "reset" -> {
75+ long userID = event .getUser ().getIdLong ();
76+ String uuid = userID + ":" + UUID .randomUUID ();
77+ text = "Would you like to reset the greeting system?\n This will delete **ALL** data!" ;
78+ List <Button > components = new ArrayList <>();
79+ components .add (Button .success ("greetings:yes:" +uuid , Emoji .fromMarkdown ("\u2714 " )));
80+ components .add (Button .danger ("greetings:no:" +uuid , Emoji .fromUnicode ("\u2716 " )));
81+ ButtonListener .buttons .put (uuid , components );
82+ event .getHook ().sendMessageEmbeds (EmbedUtils .createDefault (text )).addActionRow (components ).queue (interactionHook -> {
83+ // Timer task to disable buttons and clear cache after 3 minutes
84+ Runnable task = () -> {
85+ List <Button > actionRow = ButtonListener .buttons .get (uuid );
86+ for (int i = 0 ; i < actionRow .size (); i ++) {
87+ actionRow .set (i , actionRow .get (i ).asDisabled ());
88+ }
89+ interactionHook .editMessageComponents (ActionRow .of (actionRow )).queue (null , new ErrorHandler ().ignore (ErrorResponse .UNKNOWN_MESSAGE ));
90+ ButtonListener .buttons .remove (uuid );
91+ };
92+ ButtonListener .executor .schedule (task , 3 , TimeUnit .MINUTES );
93+ });
94+ return ;
95+ }
6296 }
6397 event .getHook ().sendMessageEmbeds (EmbedUtils .createDefault (text )).queue ();
6498 }
0 commit comments