Patching bugs

This commit is contained in:
TheTrouper
2023-10-18 15:59:53 -05:00
parent c9603c016e
commit 5ccaf5a99d
4 changed files with 37 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.discord.DiscordWebhook; import io.github.thetrouper.sentinel.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter; import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives; import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
import io.github.thetrouper.sentinel.server.util.GPTUtils;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text; import io.github.thetrouper.sentinel.server.util.Text;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@@ -14,21 +15,27 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.fullSimplify; import static io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap;
import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.scoreMap; import static io.github.thetrouper.sentinel.server.functions.AntiSpam.lastMessageMap;
import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.*;
public class FilterAction { public class FilterAction {
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, String severity, FAT type) { public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, String severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e); String report = ReportFalsePositives.generateReport(e);
TextComponent warn = new TextComponent(); TextComponent warn = new TextComponent();
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable")))); warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
TextComponent notif = new TextComponent(); TextComponent notif = new TextComponent();
notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity)))); notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText((type != FAT.SPAM ? Sentinel.dict.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity) : Sentinel.dict.get("spam-notification-hover").formatted(e.getMessage(),lastMessageMap.get(offender),fs.format(similarity))))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey()))); warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey())));
@@ -49,21 +56,21 @@ public class FilterAction {
} }
if (type == FAT.SLUR && Config.logSwear) { if (type == FAT.SLUR && Config.logSwear) {
sendDiscordLog(offender, e, type); sendDiscordLog(offender,e,type);
sendConsoleLog(offender, e, type); sendConsoleLog(offender,e,type);
} }
if (type == FAT.SPAM && Config.logSpam) { if (type == FAT.SPAM && Config.logSpam) {
// BOOKMARK sendDiscordLog(offender,e,type);
// STATE: (bool?t:f) imp spam log for console & discord for prev/curr||Mess/Redu sendConsoleLog(offender,e,type);
} }
} }
public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) { public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
String log = "]=-" + type.getTitle() + "-=[\n" + String log = "]=-" + type.getTitle() + "-=[\n" +
"Player: " + offender.getName() + "Player: " + offender.getName() +
"> Score: (" + scoreMap.get(offender) + "/" + Config.punishScore + ")\n" + (type != FAT.BLOCK_SPAM ? "> Score: `" + scoreMap.get(offender) + "/" + Config.punishScore : "> Heat: `" + heatMap.get(offender) + "/" + Config.punishHeat) + "\n" +
"> UUID: " + offender.getUniqueId() + "\n" + "> UUID: " + offender.getUniqueId() + "\n" +
"Message: " + e.getMessage() + "\n" + (type != FAT.BLOCK_SPAM ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)) + "\n" +
"Reduced: " + fullSimplify(e.getMessage()) + "\n" + (type != FAT.BLOCK_SPAM ? "Reduced: " + fullSimplify(e.getMessage()) : "Current: " + e.getMessage()) + "\n" +
(type.getExecutedCommand() != null ? "Executed: " + type.getExecutedCommand() : "Executed: Nothing, its a standard flag. You shouldn't be seeing this, please report it."); (type.getExecutedCommand() != null ? "Executed: " + type.getExecutedCommand() : "Executed: Nothing, its a standard flag. You shouldn't be seeing this, please report it.");
Sentinel.log.info(log); Sentinel.log.info(log);
} }
@@ -83,12 +90,12 @@ public class FilterAction {
.setTitle(title) .setTitle(title)
.setDescription( .setDescription(
Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\n" + Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\n" +
Emojis.space + Emojis.arrowRight + "Score: `" + scoreMap.get(offender) + "/" + Config.punishScore + "`\n" + Emojis.space + Emojis.arrowRight + (type != FAT.BLOCK_SPAM ? "Score: `" + scoreMap.get(offender) + "/" + Config.punishScore : "Heat: `" + heatMap.get(offender) + "/" + Config.punishHeat) + "`\n" +
Emojis.space + Emojis.arrowRight + "UUID: `" + offender.getUniqueId() + "`\n" + Emojis.space + Emojis.arrowRight + "UUID: `" + offender.getUniqueId() + "`\n" +
Emojis.rightSort + "Executed: " + executed + " " + Emojis.mute + "\n" Emojis.rightSort + "Executed: " + executed + " " + Emojis.mute + "\n"
) )
.addField("Original Message", "||" + e.getMessage() + "|| " + Emojis.alarm, false) .addField((type != FAT.BLOCK_SPAM ? "Message: " : "Previous: "), (type != FAT.BLOCK_SPAM ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false)
.addField("Reduced Message", ProfanityFilter.highlightProfanity(e.getMessage(), "||", "||") + " " + Emojis.noDM, false) .addField((type != FAT.BLOCK_SPAM ? "Reduced: " : "Current: "), (type != FAT.BLOCK_SPAM ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false)
.setColor(color) .setColor(color)
.setThumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay"); .setThumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay");

View File

@@ -2,6 +2,8 @@ package io.github.thetrouper.sentinel.server.functions;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.FAT;
import io.github.thetrouper.sentinel.data.FilterAction;
import io.github.thetrouper.sentinel.discord.WebhookSender; import io.github.thetrouper.sentinel.discord.WebhookSender;
import io.github.thetrouper.sentinel.server.util.GPTUtils; import io.github.thetrouper.sentinel.server.util.GPTUtils;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
@@ -29,16 +31,17 @@ public class AntiSpam {
public static void handleAntiSpam(AsyncPlayerChatEvent e) { public static void handleAntiSpam(AsyncPlayerChatEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
String message = Text.removeFirstColor(e.getMessage()); String message = Text.removeFirstColor(e.getMessage());
Double sim = calculateSimilarity(e.getMessage(),lastMessageMap.get(p));
if (!heatMap.containsKey(p)) heatMap.put(p, 0); if (!heatMap.containsKey(p)) heatMap.put(p, 0);
if (heatMap.get(p) > Config.punishHeat) { if (heatMap.get(p) > Config.punishHeat) {
e.setCancelled(true); e.setCancelled(true);
punishSpam(p,message, lastMessageMap.get(p)); FilterAction.filterAction(p,e,null,null, sim, FAT.SPAM);
return; return;
} }
if (heatMap.get(p) > Config.blockHeat) { if (heatMap.get(p) > Config.blockHeat) {
e.setCancelled(true); e.setCancelled(true);
alertSpam(p, message, lastMessageMap.get(p)); FilterAction.filterAction(p,e,null,null, sim, FAT.BLOCK_SPAM);
heatMap.put(p, heatMap.get(p) + Config.highGain); heatMap.put(p, heatMap.get(p) + Config.highGain);
return; return;
} }
@@ -60,7 +63,7 @@ public class AntiSpam {
} }
} }
} }
/*
public static void alertSpam(Player p, String message1, String message2) { public static void alertSpam(Player p, String message1, String message2) {
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
double similarity = GPTUtils.calculateSimilarity(message1,message2 + "%"); double similarity = GPTUtils.calculateSimilarity(message1,message2 + "%");
@@ -94,4 +97,5 @@ public class AntiSpam {
}); });
if (Config.logSpam) WebhookSender.sendSpamLog(p,message1,message2,heatMap.get(p),chatCleared); if (Config.logSpam) WebhookSender.sendSpamLog(p,message1,message2,heatMap.get(p),chatCleared);
} }
*/
} }

View File

@@ -27,7 +27,7 @@ public class ProfanityFilter {
String severity = ProfanityFilter.checkSeverity(message); String severity = ProfanityFilter.checkSeverity(message);
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0); if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
// Old: if (scoreMap.get(p) > Config.punishScore) punishSwear(p,highlighted,message,e); // Old: if (scoreMap.get(p) > Config.punishScore) punishSwear(p,highlighted,message,e);
if (scoreMap.get(p) > Config.punishScore) FilterAction.filterAction(p,e,highlighted,severity, FAT.SWEAR); if (scoreMap.get(p) > Config.punishScore) FilterAction.filterAction(p,e,highlighted,severity, null, FAT.SWEAR);
switch (severity) { switch (severity) {
case "low" -> { case "low" -> {
@@ -35,35 +35,35 @@ public class ProfanityFilter {
scoreMap.put(p, scoreMap.get(p) + Config.lowScore); scoreMap.put(p, scoreMap.get(p) + Config.lowScore);
e.setCancelled(true); e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e); // Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.BLOCK_SWEAR); FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
} }
case "medium-low" -> { case "medium-low" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumLowScore); ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumLowScore);
scoreMap.put(p, scoreMap.get(p) + Config.mediumLowScore); scoreMap.put(p, scoreMap.get(p) + Config.mediumLowScore);
e.setCancelled(true); e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e); // Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.BLOCK_SWEAR); FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
} }
case "medium" -> { case "medium" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumScore); ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumScore);
scoreMap.put(p, scoreMap.get(p) + Config.mediumScore); scoreMap.put(p, scoreMap.get(p) + Config.mediumScore);
e.setCancelled(true); e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e); // Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.BLOCK_SWEAR); FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
} }
case "medium-high" -> { case "medium-high" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumHighScore); ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.mediumHighScore);
scoreMap.put(p, scoreMap.get(p) + Config.mediumHighScore); scoreMap.put(p, scoreMap.get(p) + Config.mediumHighScore);
e.setCancelled(true); e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e); // Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.BLOCK_SWEAR); FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
} }
case "high" -> { case "high" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.highScore); ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Config.highScore);
scoreMap.put(p, scoreMap.get(p) + Config.highScore); scoreMap.put(p, scoreMap.get(p) + Config.highScore);
e.setCancelled(true); e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e); // Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.BLOCK_SWEAR); FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
} }
case "slur" -> { case "slur" -> {
// Insta-Punish // Insta-Punish
@@ -71,7 +71,7 @@ public class ProfanityFilter {
scoreMap.put(p, scoreMap.get(p) + Config.highScore); scoreMap.put(p, scoreMap.get(p) + Config.highScore);
e.setCancelled(true); e.setCancelled(true);
// Old: punishSlur(p,highlighted,message,e); // Old: punishSlur(p,highlighted,message,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.SLUR); FilterAction.filterAction(p,e,highlighted,severity, null,FAT.SLUR);
} }
} }
} }

View File

@@ -27,12 +27,12 @@
"spy-message-hover" : "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f%1$S\n§bReceiver: §f%2$S\n§bMessage: §f%3$S", "spy-message-hover" : "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f%1$S\n§bReceiver: §f%2$S\n§bMessage: §f%3$S",
"action-automatic-reportable" : "§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)", "action-automatic-reportable" : "§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)",
"profanity-mute-warn" : "You have been auto muted for repeated violation of the profanity filter! §7§o(Hover for more info)", "profanity-mute-warn" : "You have been auto muted for repeated violation of the profanity filter! §7§o(Hover for more info)",
"profanity-mute-notification" : "§b§n%1$s§7 has been auto-muted by the anti-swear! §8(§c%2$s§7/§4%3$s8)", "profanity-mute-notification" : "§b§n%1$s§7 has been auto-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"slur-mute-warn" : "§cYou have been insta-punished by the anti-slur! §7§o(Hover for more info)", "slur-mute-warn" : "§cYou have been insta-punished by the anti-slur! §7§o(Hover for more info)",
"slur-mute-notification" : "§b§n%1$s§7 has been insta-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)", "slur-mute-notification" : "§b§n%1$s§7 has been insta-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"swear-block-warn" : "§cPlease do not swear in chat! Attempting to bypass this filter will result in a mute! §7§o(Hover for more info)", "swear-block-warn" : "§cPlease do not swear in chat! Attempting to bypass this filter will result in a mute! §7§o(Hover for more info)",
"swear-block-notification" : "§b§n%1$s§7 has triggered the anti-swear! §8(§c%2$s§7/§4%3$s§8)", "swear-block-notification" : "§b§n%1$s§7 has triggered the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"filter-notification-hover" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§8§o(Click to report false positive)", "filter-notification-hover" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§8§o(Click to report false positive)",
"severity-notification-hover" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§bSeverity: §c%3$s\n§7§o(click to report false positive)" "severity-notification-hover" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§bSeverity: §c%3$s\n§7§o(click to report false positive)",
} }
} }