From 840035944a980bca6addfed08362d83e5d4300a8 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 14 Dec 2021 13:46:59 -0500 Subject: [PATCH] Truncate Discord interaction messages to proper length (#4686) --- .../essentialsx/discord/interactions/InteractionEventImpl.java | 3 ++- .../java/net/essentialsx/discord/util/ConsoleInjector.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java index f6b062227..dd78c232d 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java @@ -3,6 +3,7 @@ package net.essentialsx.discord.interactions; import com.earth2me.essentials.utils.FormatUtil; import com.google.common.base.Joiner; import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.essentialsx.api.v2.services.discord.InteractionChannel; @@ -33,7 +34,7 @@ public class InteractionEventImpl implements InteractionEvent { public void reply(String message) { message = FormatUtil.stripFormat(message).replace("ยง", ""); // Don't ask replyBuffer.add(message); - event.getHook().editOriginal(new MessageBuilder().setContent(Joiner.on('\n').join(replyBuffer)).setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build()) + event.getHook().editOriginal(new MessageBuilder().setContent(Joiner.on('\n').join(replyBuffer).substring(0, Message.MAX_CONTENT_LENGTH)).setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build()) .queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error)); } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java index 91cc5f464..e6ce349c8 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java @@ -81,7 +81,6 @@ public class ConsoleInjector extends AbstractAppender { entry = "[" + event.getLoggerName() + "] " + entry; } - //noinspection UnstableApiUsage messageQueue.addAll(Splitter.fixedLength(Message.MAX_CONTENT_LENGTH - 2).splitToList( MessageUtil.formatMessage(jda.getSettings().getConsoleFormat(), TimeFormat.TIME_LONG.format(Instant.now()),