Fully sanitize Discord messages

This commit is contained in:
Business Goose 2022-03-29 22:35:52 +01:00
parent c71cf1a14c
commit 97c337d5a4
No known key found for this signature in database
GPG key ID: 77DCA801362E9645
2 changed files with 9 additions and 4 deletions

View file

@ -211,4 +211,10 @@ public class DiscordBridge {
Log.info("TFM 4.3 Reloaded Discord stopped."); Log.info("TFM 4.3 Reloaded Discord stopped.");
} }
public static String fullySanitizeDiscordMessage(String message)
{
String partiallySanitized = sanitizeMessage(message);
return partiallySanitized.replaceAll("\\\\", "\\\\\\").replaceAll("([`_~*|])", "\\\\$1");
}
} }

View file

@ -19,7 +19,6 @@ import me.StevenLawson.TotalFreedomMod.util.Utilities;
import me.StevenLawson.TotalFreedomMod.world.AdminWorld; import me.StevenLawson.TotalFreedomMod.world.AdminWorld;
import me.StevenLawson.TotalFreedomMod.world.RollbackManager; import me.StevenLawson.TotalFreedomMod.world.RollbackManager;
import me.StevenLawson.TotalFreedomMod.world.RollbackManager.RollbackEntry; import me.StevenLawson.TotalFreedomMod.world.RollbackManager.RollbackEntry;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -632,7 +631,7 @@ public class PlayerListener implements Listener {
event.setFormat(ChatColor.translateAlternateColorCodes('&', MainConfig.getString(ConfigurationEntry.CHAT_FORMAT)).replace("{RANK}", playerdata.getTag().replaceAll("%", "%%"))); event.setFormat(ChatColor.translateAlternateColorCodes('&', MainConfig.getString(ConfigurationEntry.CHAT_FORMAT)).replace("{RANK}", playerdata.getTag().replaceAll("%", "%%")));
} }
DiscordBridge.transmitMessage(String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()).replaceAll("([`_~*])", "\\\\$1")); DiscordBridge.transmitMessage(String.format(event.getFormat(), event.getPlayer().getDisplayName(), DiscordBridge.fullySanitizeDiscordMessage(event.getMessage())));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -756,7 +755,7 @@ public class PlayerListener implements Listener {
} }
if (PlayerList.existsEntry(player)) { if (PlayerList.existsEntry(player)) {
DiscordBridge.transmitMessage(String.format("**%s left the server**", DiscordBridge.sanitizeMessage(player.getDisplayName()))); DiscordBridge.transmitMessage(String.format("**%s left the server**", DiscordBridge.fullySanitizeDiscordMessage(player.getDisplayName())));
} }
PlayerList.removeEntry(player); PlayerList.removeEntry(player);
@ -908,7 +907,7 @@ public class PlayerListener implements Listener {
PlayerData.getPlayerData(player).setTag(playerTag); PlayerData.getPlayerData(player).setTag(playerTag);
} }
} }
DiscordBridge.transmitMessage(String.format("**%s joined the server**", DiscordBridge.sanitizeMessage(player.getDisplayName()))); DiscordBridge.transmitMessage(String.format("**%s joined the server**", DiscordBridge.fullySanitizeDiscordMessage(player.getDisplayName())));
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)