Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.eggy03</groupId>
<artifactId>papertrailbot</artifactId>
<version>4.2.1</version>
<version>4.2.2</version>
<name>PaperTrail Bot</name>
<description>A simple bot for logging all server and member actions</description>
<packaging>quarkus</packaging>
Expand All @@ -18,7 +18,7 @@
<!-- Quarkus Properties -->
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.37.2</quarkus.platform.version>
<quarkus.platform.version>3.37.3</quarkus.platform.version>
<skipITs>true</skipITs>

<!-- Dependency Versions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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<Permission> 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;
Expand Down Expand Up @@ -92,10 +80,10 @@ private String formatPermissions(@NonNull EnumSet<Permission> 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<Permission> deniedPermissions = EnumSet.copyOf(necessaryPermissions);
EnumSet<Permission> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Permission> 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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}
}
Loading