diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java index d784016..000b159 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java @@ -49,6 +49,8 @@ public class UrbanDictionaryCommand implements MessageCommand .withEmoji(Emoji.fromFormatted("⬅️")); static final Button nextPageButton = Button.primary("urban_nextpage", "Next") .withEmoji(Emoji.fromFormatted("➡️")); + static final Button deleteButton = Button.danger("urban_delete", "Delete") + .withEmoji(Emoji.fromFormatted("\uD83D\uDDD1️")); private static MessageEmbed buildEmbed(String term, String url, @@ -196,7 +198,8 @@ public class UrbanDictionaryCommand implements MessageCommand event.getChannel() .sendMessageEmbeds(embed) .addActionRow(previousPageButton.asDisabled(), //disabled by default because we're on page 0 - nextPageBtnLocal) + nextPageBtnLocal, + deleteButton) .queue(message -> { @@ -238,6 +241,19 @@ public class UrbanDictionaryCommand implements MessageCommand } } + public static void delete(ButtonInteractionEvent event) + { + String messageId = event.getMessageId(); + DatabaseSource database = Cache.getDatabaseSource(); + + // check if the user interacting is the same one who ran the command + if (!(database.isUserTrackedFor(event.getUser().getId(), messageId))) { + event.reply("❌ You did not run this command!").setEphemeral(true).queue(); + return; + } + + event.getInteraction().getMessage().delete().queue(); + } public static void changePage(ButtonInteractionEvent event, boolean increase) { @@ -298,6 +314,8 @@ public class UrbanDictionaryCommand implements MessageCommand components.add(nextPageButton.asEnabled()); } + components.add(deleteButton); + ActionRow currentRow = ActionRow.of(components); List actionRows = new ArrayList<>(Collections.singletonList(currentRow)); @@ -305,6 +323,5 @@ public class UrbanDictionaryCommand implements MessageCommand event.editComponents(actionRows).complete(); database.setUrbanPage(messageId, page); database.resetExpiryTimestamp(messageId); - } } diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java index 8fb267c..c115276 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/ButtonInteractionListener.java @@ -24,6 +24,7 @@ public class ButtonInteractionListener extends ListenerAdapter // urban dictionary navigation case "urban_nextpage" -> UrbanDictionaryCommand.changePage(event, true); case "urban_previouspage" -> UrbanDictionaryCommand.changePage(event, false); + case "urban_delete" -> UrbanDictionaryCommand.delete(event); }