Truncate Discord interaction messages to proper length (#4686)

This commit is contained in:
Josh Roy 2021-12-14 13:46:59 -05:00 committed by GitHub
parent 20a7d1c7ee
commit 840035944a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package net.essentialsx.discord.interactions;
import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.FormatUtil;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import net.dv8tion.jda.api.MessageBuilder; 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.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.essentialsx.api.v2.services.discord.InteractionChannel; import net.essentialsx.api.v2.services.discord.InteractionChannel;
@ -33,7 +34,7 @@ public class InteractionEventImpl implements InteractionEvent {
public void reply(String message) { public void reply(String message) {
message = FormatUtil.stripFormat(message).replace("§", ""); // Don't ask message = FormatUtil.stripFormat(message).replace("§", ""); // Don't ask
replyBuffer.add(message); 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)); .queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error));
} }

View File

@ -81,7 +81,6 @@ public class ConsoleInjector extends AbstractAppender {
entry = "[" + event.getLoggerName() + "] " + entry; entry = "[" + event.getLoggerName() + "] " + entry;
} }
//noinspection UnstableApiUsage
messageQueue.addAll(Splitter.fixedLength(Message.MAX_CONTENT_LENGTH - 2).splitToList( messageQueue.addAll(Splitter.fixedLength(Message.MAX_CONTENT_LENGTH - 2).splitToList(
MessageUtil.formatMessage(jda.getSettings().getConsoleFormat(), MessageUtil.formatMessage(jda.getSettings().getConsoleFormat(),
TimeFormat.TIME_LONG.format(Instant.now()), TimeFormat.TIME_LONG.format(Instant.now()),