diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeHistoryCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeHistoryCommand.java index 6ee27c5888..c3c14ddb99 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeHistoryCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeHistoryCommand.java @@ -57,7 +57,7 @@ public PurgeHistoryCommand(Database database) { @Override public void onSlashCommand(SlashCommandInteractionEvent event) { - event.deferReply().queue(); + event.deferReply(true).queue(); OptionMapping targetOption = Objects.requireNonNull(event.getOption(USER_OPTION), "target is null"); @@ -77,9 +77,7 @@ private void handleHistory(SlashCommandInteractionEvent event, Member author, St String sourceChannelId = event.getChannel().getId(); if (!validateHierarchy(author, targetOption)) { - hook.sendMessage("Cannot purge history of user with a higher role than you") - .setEphemeral(true) - .queue(); + hook.sendMessage("Cannot purge history of user with a higher role than you").queue(); return; } @@ -103,19 +101,18 @@ private void handleHistory(SlashCommandInteractionEvent event, Member author, St } handleDelete(messageIdsForDeletion, event.getJDA(), event.getChannel(), event.getHook(), - targetUser, reason); + targetUser, reason, author); } private void handleDelete(List messageIdsForDeletion, JDA jda, - MessageChannelUnion channel, InteractionHook hook, User targetUser, String reason) { + MessageChannelUnion channel, InteractionHook hook, User targetUser, String reason, + Member author) { if (messageIdsForDeletion.isEmpty()) { handleEmptyMessageHistory(hook, targetUser); return; } - registerPurgeAction(reason); - if (hasSingleElement(messageIdsForDeletion)) { String messageId = messageIdsForDeletion.get(0); @@ -124,12 +121,12 @@ private void handleDelete(List messageIdsForDeletion, JDA jda, .queue(); } - int noOfMessagesToPurge = messageIdsForDeletion.size(); channel.purgeMessagesById(messageIdsForDeletion); - String messageForMod = "%s messages purged from user %s".formatted(noOfMessagesToPurge, - targetUser.getName()); - hook.sendMessage(messageForMod).setEphemeral(true).queue(); + String messageForMod = "messages purged from user %s".formatted(targetUser.getName()); + hook.sendMessage(messageForMod) + .queue(onSuccess -> logger.info("{} purged messages from {} because: {}", + author.getUser(), targetUser, reason)); } private boolean hasSingleElement(List messageIdsForDeletion) { @@ -140,7 +137,7 @@ private void handleEmptyMessageHistory(InteractionHook hook, User targetUser) { String messageForMod = "%s has no message history in this channel within last %s hr" .formatted(targetUser, PURGE_MESSAGES_AFTER_LIMIT_HOURS); - hook.sendMessage(messageForMod).setEphemeral(true).queue(); + hook.sendMessage(messageForMod).queue(); } private boolean validateHierarchy(Member author, OptionMapping target) { @@ -153,8 +150,4 @@ private boolean validateHierarchy(Member author, OptionMapping target) { return targetUserRole.getPosition() >= authorRole.getPosition(); } - - private void registerPurgeAction(String reason) { - // TODO - } } diff --git a/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeMessageListener.java b/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeMessageListener.java index 7cd2f12a13..2bd585a22d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeMessageListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/moderation/history/PurgeMessageListener.java @@ -53,8 +53,4 @@ private void updateHistory(MessageReceivedEvent event) { private boolean shouldIgnoreMessages(MessageReceivedEvent event) { return event.isWebhookMessage() || event.getAuthor().isBot(); } - - private void limitHistoryRecords() { - // TODO - } }