Patching bugs
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
"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-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-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-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)",
|
||||
"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)",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user