From 6bc879b1a73f6b19b3e3ff32f9e45f5d7dedd121 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 12 Mar 2025 08:14:36 +0700 Subject: [PATCH] feat: copyable discord messages --- build-number.txt | 2 +- .../chomens_bot/plugins/DiscordPlugin.java | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/build-number.txt b/build-number.txt index 0bd8d3cb..84a3f856 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1772 \ No newline at end of file +1774 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java index 365e4d20..3e9875c2 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -377,17 +377,17 @@ public class DiscordPlugin { if (nameComponent.color() == null) nameComponent = nameComponent.color(NamedTextColor.RED); + final String replacedMessageContent = message.getContentDisplay() + // replaces skull emoji + .replace("\uD83D\uDC80", "☠") + // replaces all ANSI codes (used when a user replies to the bot's log message) with nothing + .replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", "") + // replaces all ZWSP with nothing + .replace("\u200b", ""); + final Component deserialized = LegacyComponentSerializer .legacyAmpersand() - .deserialize( - message.getContentDisplay() - // replaces skull emoji - .replace("\uD83D\uDC80", "☠") - // replaces all ANSI codes (used when a user replies to the bot's log message) with nothing - .replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", "") - // replaces all ZWSP with nothing - .replace("\u200b", "") - ); + .deserialize(replacedMessageContent); final Component messageComponent = Component .empty() @@ -397,6 +397,18 @@ public class DiscordPlugin { .append(attachmentsComponent) .append(embedsComponent) .append(stickersComponent) + ) + .hoverEvent( + HoverEvent.showText( + Component + .text("Click here to copy the message to your clipboard") + .color(NamedTextColor.GREEN) + ) + ) + .clickEvent( + ClickEvent.copyToClipboard( + replacedMessageContent + ) ); return Component.translatable(