From f6a23e4888dfcafb60dbc6486262688b8add0f77 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 4 Jul 2024 18:15:05 +0100 Subject: [PATCH] update role log embed --- .../cc/fascinated/bat/common/RoleUtils.java | 29 +++++++++++++++++++ .../logging/listeners/RoleListener.java | 14 ++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/common/RoleUtils.java b/src/main/java/cc/fascinated/bat/common/RoleUtils.java index ef6c87e..c6e8ce0 100644 --- a/src/main/java/cc/fascinated/bat/common/RoleUtils.java +++ b/src/main/java/cc/fascinated/bat/common/RoleUtils.java @@ -6,6 +6,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; +import java.awt.*; + /** * @author Fascinated (fascinated7) */ @@ -36,4 +38,31 @@ public class RoleUtils { } return formattedPermissions.substring(0, formattedPermissions.length() - 2); } + + /** + * Gets the formatted color of a role + * + * @param color the color string to get the formatted color of + * @return the formatted color + */ + public String getFormattedColor(Color color) { + if (color == null) { + return "Default"; + } + String colorHex = HexColorUtils.colorToHex(color); + return "`%s` *[(view)](%s)*".formatted( + colorHex, + "https://www.colorhexa.com/%s".formatted(colorHex.substring(1)) + ); + } + + /** + * Gets the formatted color of a role + * + * @param role the role to get the formatted icon of + * @return the formatted icon + */ + public String getFormattedColor(Role role) { + return getFormattedColor(role.getColor()); + } } diff --git a/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java b/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java index bcbf553..30371e7 100644 --- a/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java +++ b/src/main/java/cc/fascinated/bat/features/logging/listeners/RoleListener.java @@ -75,9 +75,7 @@ public class RoleListener implements EventListener { logFeature.sendLog(guild, LogType.ROLE_CREATE, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Role Created") .appendLine("Role: %s".formatted(role.getAsMention()), true) - .appendLine("Color: `%s`".formatted( - role.getColor() == null ? "Default" : HexColorUtils.colorToHex(role.getColor()) - ), true) + .appendLine("Color: %s".formatted(RoleUtils.getFormattedColor(role)), true) .appendLine("Permissions: %s".formatted(RoleUtils.getFormattedPermissions(role)), true) .build()) .build()); @@ -90,9 +88,7 @@ public class RoleListener implements EventListener { logFeature.sendLog(guild, LogType.ROLE_DELETE, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Role Deleted") .appendLine("Role: `%s`".formatted(role.getName()), true) - .appendLine("Color: `%s`".formatted( - role.getColor() == null ? "Default" : HexColorUtils.colorToHex(role.getColor()) - ), true) + .appendLine("Color: %s".formatted(RoleUtils.getFormattedColor(role)), true) .appendLine("Permissions: %s".formatted(RoleUtils.getFormattedPermissions(role)), true) .build()) .build()); @@ -120,9 +116,9 @@ public class RoleListener implements EventListener { logFeature.sendLog(guild, LogType.ROLE_CONFIGURATION, EmbedUtils.successEmbed() .setDescription(new EmbedDescriptionBuilder("Role Color Updated") .appendLine("Role: %s".formatted(event.getRole().getAsMention()), true) - .appendLine("Color: `%s` -> `%s`".formatted( - oldColor == null ? "Default" : HexColorUtils.colorToHex(oldColor), - newColor == null ? "Default" : HexColorUtils.colorToHex(newColor) + .appendLine("Color: %s -> %s".formatted( + RoleUtils.getFormattedColor(oldColor), + RoleUtils.getFormattedColor(newColor) ), true) .build()) .build());