From e0d6d31ecf9bc04a32ee1bb1c369a9a98ebd5fad Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 13:09:52 +0530 Subject: [PATCH 1/6] refactor: extract necessary bot permissions to utility Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- .../handlers/command/DebugCommandHandler.java | 18 +++------------- .../papertrail/bot/utils/PermissionUtils.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 src/main/java/io/github/eggy03/papertrail/bot/utils/PermissionUtils.java diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java index c9ce6e9..6953b01 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/command/DebugCommandHandler.java @@ -2,6 +2,7 @@ import io.github.eggy03.papertrail.bot.configuration.PaperTrailConfig; import io.github.eggy03.papertrail.bot.utils.BooleanUtils; +import io.github.eggy03.papertrail.bot.utils.PermissionUtils; import io.github.eggy03.papertrail.sdk.client.AuditLogRegistrationClient; import io.github.eggy03.papertrail.sdk.client.MessageLogRegistrationClient; import jakarta.enterprise.context.ApplicationScoped; @@ -19,7 +20,6 @@ import java.awt.Color; import java.time.Instant; import java.util.EnumSet; -import java.util.Set; @ApplicationScoped public final class DebugCommandHandler { @@ -28,18 +28,6 @@ public final class DebugCommandHandler { private final @NonNull MessageLogRegistrationClient messageLogRegistrationClient; private final @NonNull PaperTrailConfig paperTrailConfig; - // necessary permissions for the bot to function - @NonNull - private final Set necessaryPermissions = EnumSet.of( - Permission.VIEW_CHANNEL, - Permission.VIEW_AUDIT_LOGS, - Permission.MANAGE_SERVER, - Permission.MESSAGE_SEND, - Permission.MESSAGE_SEND_IN_THREADS, - Permission.MESSAGE_EMBED_LINKS, - Permission.MESSAGE_HISTORY - ); - @Inject public DebugCommandHandler(@NonNull AuditLogRegistrationClient auditLogRegistrationClient, @NonNull MessageLogRegistrationClient messageLogRegistrationClient, @NonNull PaperTrailConfig paperTrailConfig) { this.auditLogRegistrationClient = auditLogRegistrationClient; @@ -92,10 +80,10 @@ private String formatPermissions(@NonNull EnumSet grantedGuildOrChan // 2) RETAIN those GRANTED PERMISSIONS that match with the NECESSARY ONES // there may be cases where GRANTED PERMISSIONS is NOT a perfect SUPERSET of NECESSARY PERMISSIONS // this indicates that some NECESSARY PERMISSIONS have been DENIED - grantedPermissions.retainAll(necessaryPermissions); + grantedPermissions.retainAll(PermissionUtils.necessaryPermissions()); // create a copy of necessary permissions - EnumSet deniedPermissions = EnumSet.copyOf(necessaryPermissions); + EnumSet deniedPermissions = EnumSet.copyOf(PermissionUtils.necessaryPermissions()); // now if you calculate necessary - granted, you will get the set of necessary permissions which are DENIED deniedPermissions.removeAll(grantedPermissions); diff --git a/src/main/java/io/github/eggy03/papertrail/bot/utils/PermissionUtils.java b/src/main/java/io/github/eggy03/papertrail/bot/utils/PermissionUtils.java new file mode 100644 index 0000000..4c4e970 --- /dev/null +++ b/src/main/java/io/github/eggy03/papertrail/bot/utils/PermissionUtils.java @@ -0,0 +1,21 @@ +package io.github.eggy03.papertrail.bot.utils; + +import lombok.NonNull; +import lombok.experimental.UtilityClass; +import net.dv8tion.jda.api.Permission; + +import java.util.EnumSet; +import java.util.Set; + +@UtilityClass +public final class PermissionUtils { + + @NonNull + public Set necessaryPermissions() { + return EnumSet.of( + Permission.VIEW_CHANNEL, Permission.VIEW_AUDIT_LOGS, Permission.MANAGE_SERVER, + Permission.MESSAGE_SEND, Permission.MESSAGE_SEND_IN_THREADS, Permission.MESSAGE_EMBED_LINKS, + Permission.MESSAGE_HISTORY + ); + } +} From 4f57fe61e41d6417e2ecb8ca5e73dbccd126bd8f Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 13:52:16 +0530 Subject: [PATCH 2/6] fix: improve message jump url error handling - Wrap `retrieveMessageById` in `try-catch` for `InsufficientPermissionException` and `ErrorResponseException` and return a fallback message. Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- .../bot/utils/auditlog/MessageUtils.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/eggy03/papertrail/bot/utils/auditlog/MessageUtils.java b/src/main/java/io/github/eggy03/papertrail/bot/utils/auditlog/MessageUtils.java index b93b493..8fda6a9 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/utils/auditlog/MessageUtils.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/utils/auditlog/MessageUtils.java @@ -3,13 +3,17 @@ import io.github.eggy03.papertrail.bot.utils.NumberParseUtils; import lombok.NonNull; import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.guild.GenericGuildEvent; +import net.dv8tion.jda.api.exceptions.ErrorResponseException; +import net.dv8tion.jda.api.exceptions.InsufficientPermissionException; import org.jetbrains.annotations.Blocking; import org.jetbrains.annotations.Nullable; @UtilityClass +@Slf4j public final class MessageUtils { private static final String FALLBACK_STRING = "N/A"; @@ -28,10 +32,14 @@ public static String resolveMessageJumpUrlFromId(@Nullable Object channelId, @Nu return FALLBACK_STRING; // Blocking REST Action - Message message = textChannel.retrieveMessageById(messageIdLong).complete(); - if (message == null) - return FALLBACK_STRING; + // read retrieveMessageById doc for try catch explanation + try { + Message message = textChannel.retrieveMessageById(messageIdLong).complete(); + return message.getJumpUrl(); + } catch (InsufficientPermissionException | ErrorResponseException e) { + log.debug("Error while retrieving message by ID", e); + return "Unable to resolve the message jump URL due to insufficient permissions or access."; + } - return message.getJumpUrl(); } } From a6a3e2984c6099f79089cffdd955a71ee306cc3b Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:01:37 +0530 Subject: [PATCH 3/6] feat: added formatting for new keys - Server Splash - Server Banner - Server Theme Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- .../guild/auditlog/GuildUpdateActionTypeHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java index dab9983..234fada 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/GuildUpdateActionTypeHandler.java @@ -122,6 +122,15 @@ public void onGuildUpdate(@NonNull GuildAuditLogEntryCreateEvent event) { case "explicit_content_filter" -> eb.addField(MarkdownUtil.underline("Explicit Content Filter"), "╰┈➤" + GuildUtils.resolveExplicitContentFilterLevel(newValue), false); + case "theme" -> + eb.addField(MarkdownUtil.underline("Server Theme"), "╰┈➤ Server Theme has been updated", false); + + case "splash_hash" -> + eb.addField(MarkdownUtil.underline("Server Splash"), "╰┈➤ Server Splash image has been updated", false); + + case "banner_hash" -> + eb.addField(MarkdownUtil.underline("Server Banner"), "╰┈➤ Server Banner image has been updated", false); + default -> { eb.addField("Unimplemented Change Key", changeKey, false); log.info("Unimplemented Change Key for Guild Update: {}\nOLD_VALUE: {}\nNEW_VALUE: {}", changeKey, oldValue, newValue); From 335afad246a3a79819a54e94d3b4abf8e4c0ae0a Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:22:36 +0530 Subject: [PATCH 4/6] feat: added topic and rtc_region keys for create events Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- .../handlers/guild/auditlog/ChannelActionTypeHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java index 7e373dd..faea722 100644 --- a/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java +++ b/src/main/java/io/github/eggy03/papertrail/bot/service/handlers/guild/auditlog/ChannelActionTypeHandler.java @@ -89,6 +89,10 @@ public void onChannelCreate(@NonNull GuildAuditLogEntryCreateEvent event) { // the second two are forum only cases which stay empty during creation } + case "topic" -> eb.addField(MarkdownUtil.underline("Channel Topic"), "╰┈➤" + newValue, false); + + case "rtc_region" -> eb.addField(MarkdownUtil.underline("RTC Region"), "╰┈➤" + newValue, false); + default -> { eb.addField("Unimplemented Change Key", changeKey, false); log.info("Unimplemented Change Key for Channel Create: {}\nOLD_VALUE: {}\nNEW_VALUE: {}", changeKey, oldValue, newValue); From 9dc807e4175b79896452d7aaad7abfe1041d23d9 Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:24:14 +0530 Subject: [PATCH 5/6] build: bump quarkus to 3.37.3 Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58e13a2..4f2477c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ quarkus-bom io.quarkus.platform - 3.37.2 + 3.37.3 true From c1de3722cb1db4880d991fc5b29cca00e94668dd Mon Sep 17 00:00:00 2001 From: Egg-03 <111327101+eggy03@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:24:36 +0530 Subject: [PATCH 6/6] build: bump project version to 4.2.2 Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4f2477c..712f4f3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 io.github.eggy03 papertrailbot - 4.2.1 + 4.2.2 PaperTrail Bot A simple bot for logging all server and member actions quarkus