port illegal characters from the js chomens bot
This commit is contained in:
parent
7413d5a2bd
commit
12ba6ea472
5 changed files with 23 additions and 6 deletions
src/main/java/land/chipmunk/chayapak/chomens_bot
|
@ -3,7 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.command;
|
|||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.EscapeCodeBlock;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.CodeBlockUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
|
@ -49,7 +49,7 @@ public class DiscordCommandContext extends CommandContext {
|
|||
final EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setTitle("Output");
|
||||
builder.setColor(Color.decode(bot.config().discord().embedColors().normal()));
|
||||
builder.setDescription("```ansi\n" + EscapeCodeBlock.escape(output.replace("\u001b[9", "\u001b[3")) + "\n```");
|
||||
builder.setDescription("```ansi\n" + CodeBlockUtilities.escape(output.replace("\u001b[9", "\u001b[3")) + "\n```");
|
||||
|
||||
final MessageEmbed embed = builder.build();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import land.chipmunk.chayapak.chomens_bot.chatParsers.data.ChatParser;
|
|||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.PlayerMessage;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.IllegalCharactersUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -194,7 +195,10 @@ public class ChatPlugin extends Bot.Listener {
|
|||
final String[] splitted = message.split("(?<=\\G.{255})|\\n");
|
||||
|
||||
for (String subMessage : splitted) {
|
||||
if (subMessage.trim().equals("")) continue;
|
||||
if (
|
||||
subMessage.trim().equals("") ||
|
||||
IllegalCharactersUtilities.containsIllegalCharacters(subMessage)
|
||||
) continue;
|
||||
|
||||
_queue.add(subMessage);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import land.chipmunk.chayapak.chomens_bot.Configuration;
|
|||
import land.chipmunk.chayapak.chomens_bot.Main;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.DiscordCommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.EscapeCodeBlock;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.CodeBlockUtilities;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
@ -81,7 +81,7 @@ public class DiscordPlugin {
|
|||
@Override
|
||||
public void systemMessageReceived (Component component) {
|
||||
final String content = ComponentUtilities.stringifyAnsi(component);
|
||||
sendMessage(EscapeCodeBlock.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
|
||||
sendMessage(CodeBlockUtilities.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
public class EscapeCodeBlock {
|
||||
public class CodeBlockUtilities {
|
||||
public static String escape (String message) {
|
||||
return message.replace("`", "\u200b`");
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.util;
|
||||
|
||||
public class IllegalCharactersUtilities {
|
||||
public static boolean isAllowedCharacter (char character) {
|
||||
return character != '\u00a7' && character != '\u007f';
|
||||
}
|
||||
|
||||
public static boolean containsIllegalCharacters (String string) {
|
||||
for (int i = 0; i < string.length(); i++) if (!isAllowedCharacter(string.charAt(i))) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue