|
5 | 5 | import net.dv8tion.jda.api.entities.Emoji; |
6 | 6 | import net.dv8tion.jda.api.entities.Guild; |
7 | 7 | import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
| 8 | +import net.dv8tion.jda.api.exceptions.ContextException; |
| 9 | +import net.dv8tion.jda.api.exceptions.ErrorHandler; |
8 | 10 | import net.dv8tion.jda.api.interactions.commands.OptionMapping; |
9 | 11 | import net.dv8tion.jda.api.interactions.commands.OptionType; |
10 | 12 | import net.dv8tion.jda.api.interactions.commands.build.OptionData; |
11 | 13 | import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; |
| 14 | +import net.dv8tion.jda.api.interactions.components.ActionRow; |
12 | 15 | import net.dv8tion.jda.api.interactions.components.buttons.Button; |
| 16 | +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; |
| 17 | +import net.dv8tion.jda.api.requests.ErrorResponse; |
13 | 18 | import technobot.TechnoBot; |
14 | 19 | import technobot.commands.Category; |
15 | 20 | import technobot.commands.Command; |
16 | 21 | import technobot.data.GuildData; |
17 | 22 | import technobot.handlers.SuggestionHandler; |
| 23 | +import technobot.listeners.ButtonListener; |
18 | 24 | import technobot.util.embeds.EmbedUtils; |
19 | 25 |
|
20 | 26 | import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | +import java.util.concurrent.TimeUnit; |
21 | 29 |
|
22 | 30 | /** |
23 | 31 | * Admin command to setup and modify the suggestion board. |
@@ -110,13 +118,24 @@ public void execute(SlashCommandInteractionEvent event) { |
110 | 118 | return; |
111 | 119 | } |
112 | 120 | case "reset" -> { |
113 | | - String userID = event.getUser().getId(); |
| 121 | + long userID = event.getUser().getIdLong(); |
114 | 122 | text = "Would you like to reset the suggestions system?\nThis will delete **ALL** data!"; |
115 | | - event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)) |
116 | | - .addActionRow( |
117 | | - Button.success("suggestions:yes:"+userID, Emoji.fromMarkdown("\u2714")), |
118 | | - Button.danger("suggestions:no:"+userID, Emoji.fromUnicode("\u2716"))) |
119 | | - .queue(); |
| 123 | + List<Button> components = new ArrayList<>(); |
| 124 | + components.add(Button.success("suggestions:yes:"+userID, Emoji.fromMarkdown("\u2714"))); |
| 125 | + components.add(Button.danger("suggestions:no:"+userID, Emoji.fromUnicode("\u2716"))); |
| 126 | + ButtonListener.buttons.put(userID, components); |
| 127 | + event.getHook().sendMessageEmbeds(EmbedUtils.createDefault(text)).addActionRow(components).queue(interactionHook -> { |
| 128 | + // Timer task to disable buttons and clear cache after 3 minutes |
| 129 | + Runnable task = () -> { |
| 130 | + List<Button> actionRow = ButtonListener.buttons.get(userID); |
| 131 | + for (int i = 0; i < actionRow.size(); i++) { |
| 132 | + actionRow.set(i, actionRow.get(i).asDisabled()); |
| 133 | + } |
| 134 | + interactionHook.editMessageComponents(ActionRow.of(actionRow)).queue(null, new ErrorHandler().ignore(ErrorResponse.UNKNOWN_MESSAGE)); |
| 135 | + ButtonListener.buttons.remove(userID); |
| 136 | + }; |
| 137 | + ButtonListener.executor.schedule(task, 3, TimeUnit.MINUTES); |
| 138 | + }); |
120 | 139 | return; |
121 | 140 | } |
122 | 141 | } |
|
0 commit comments