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.server.functions.ProfanityFilter;
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.Text;
import net.md_5.bungee.api.chat.ClickEvent;
@@ -14,21 +15,27 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.awt.*;
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.ProfanityFilter.scoreMap;
import static io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap;
import static io.github.thetrouper.sentinel.server.functions.AntiSpam.lastMessageMap;
import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.*;
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);
TextComponent warn = new TextComponent();
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));
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
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));
warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey())));
@@ -49,21 +56,21 @@ public class FilterAction {
}
if (type == FAT.SLUR && Config.logSwear) {
sendDiscordLog(offender, e, type);
sendConsoleLog(offender, e, type);
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SPAM && Config.logSpam) {
// BOOKMARK
// STATE: (bool?t:f) imp spam log for console & discord for prev/curr||Mess/Redu
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
}
public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
String log = "]=-" + type.getTitle() + "-=[\n" +
"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" +
"Message: " + e.getMessage() + "\n" +
"Reduced: " + fullSimplify(e.getMessage()) + "\n" +
(type != FAT.BLOCK_SPAM ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)) + "\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.");
Sentinel.log.info(log);
}
@@ -83,12 +90,12 @@ public class FilterAction {
.setTitle(title)
.setDescription(
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.rightSort + "Executed: " + executed + " " + Emojis.mute + "\n"
)
.addField("Original Message", "||" + e.getMessage() + "|| " + Emojis.alarm, false)
.addField("Reduced Message", ProfanityFilter.highlightProfanity(e.getMessage(), "||", "||") + " " + Emojis.noDM, false)
.addField((type != FAT.BLOCK_SPAM ? "Message: " : "Previous: "), (type != FAT.BLOCK_SPAM ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false)
.addField((type != FAT.BLOCK_SPAM ? "Reduced: " : "Current: "), (type != FAT.BLOCK_SPAM ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false)
.setColor(color)
.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.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.server.util.GPTUtils;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
@@ -29,16 +31,17 @@ public class AntiSpam {
public static void handleAntiSpam(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
String message = Text.removeFirstColor(e.getMessage());
Double sim = calculateSimilarity(e.getMessage(),lastMessageMap.get(p));
if (!heatMap.containsKey(p)) heatMap.put(p, 0);
if (heatMap.get(p) > Config.punishHeat) {
e.setCancelled(true);
punishSpam(p,message, lastMessageMap.get(p));
FilterAction.filterAction(p,e,null,null, sim, FAT.SPAM);
return;
}
if (heatMap.get(p) > Config.blockHeat) {
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);
return;
}
@@ -60,7 +63,7 @@ public class AntiSpam {
}
}
}
/*
public static void alertSpam(Player p, String message1, String message2) {
TextComponent text = new TextComponent();
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);
}
*/
}

View File

@@ -27,7 +27,7 @@ public class ProfanityFilter {
String severity = ProfanityFilter.checkSeverity(message);
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
// 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) {
case "low" -> {
@@ -35,35 +35,35 @@ public class ProfanityFilter {
scoreMap.put(p, scoreMap.get(p) + Config.lowScore);
e.setCancelled(true);
// 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" -> {
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);
e.setCancelled(true);
// 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" -> {
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);
e.setCancelled(true);
// 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" -> {
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);
e.setCancelled(true);
// 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" -> {
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);
e.setCancelled(true);
// 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" -> {
// Insta-Punish
@@ -71,7 +71,7 @@ public class ProfanityFilter {
scoreMap.put(p, scoreMap.get(p) + Config.highScore);
e.setCancelled(true);
// Old: punishSlur(p,highlighted,message,e);
FilterAction.filterAction(p,e,highlighted,severity, FAT.SLUR);
FilterAction.filterAction(p,e,highlighted,severity, null,FAT.SLUR);
}
}
}