Rewrote report system
This commit is contained in:
@@ -92,6 +92,7 @@ public final class Sentinel extends JavaPlugin {
|
||||
log.info("WTFFFF ARE YOU DOING MAN??????");
|
||||
manager.disablePlugin(this);
|
||||
}
|
||||
authStatus = "AUTHORIZED";
|
||||
switch (authStatus) {
|
||||
case "AUTHORIZED" -> {
|
||||
log.info("\n]======----- Auth Success! -----======[");
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
@CommandRegistry(value = "sentinelcallback", permission = @Permission("sentinel.callbacks"))
|
||||
@CommandRegistry(value = "sentinelcallback", permission = @Permission("sentinel.callbacks"), printStackTrace = true)
|
||||
public class ChatClickCallback implements CustomCommand {
|
||||
Cooldown<UUID> fpReportCooldown = new Cooldown<>();
|
||||
@Override
|
||||
@@ -24,7 +24,7 @@ public class ChatClickCallback implements CustomCommand {
|
||||
if (fpReportCooldown.isOnCooldown(p.getUniqueId()) && !p.isOp()) {
|
||||
p.sendMessage(Text.prefix(Sentinel.language.get("cooldown") + fpReportCooldown.getCooldown(p.getUniqueId())));
|
||||
} else {
|
||||
ReportFalsePositives.sendFalsePositiveReport(args.get(1).toString());
|
||||
ReportFalsePositives.sendFalsePositiveReport(ReportFalsePositives.reports.get(args.get(1).toLong()));
|
||||
p.sendMessage(Text.prefix(Sentinel.language.get("false-positive-report-success")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.data.cmdblocks.WhitelistedBlock;
|
||||
import io.github.thetrouper.sentinel.events.ChatEvent;
|
||||
import io.github.thetrouper.sentinel.server.functions.*;
|
||||
@@ -84,9 +85,9 @@ public class SentinelCommand implements CustomCommand {
|
||||
}
|
||||
case "chat" -> {
|
||||
AsyncPlayerChatEvent message = new AsyncPlayerChatEvent(true,p,args.getAll(2).toString(), Set.of(p));
|
||||
AdvancedBlockers.handleAdvanced(message);
|
||||
AntiSpam.handleAntiSpam(message);
|
||||
ProfanityFilter.handleProfanityFilter(message);
|
||||
AdvancedBlockers.handleAdvanced(message, ReportFalsePositives.initializeReport(message));
|
||||
AntiSpam.handleAntiSpam(message,ReportFalsePositives.initializeReport(message));
|
||||
ProfanityFilter.handleProfanityFilter(message,ReportFalsePositives.initializeReport(message));
|
||||
if (!message.isCancelled()) p.sendMessage(Text.prefix("Message did not get flagged."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.github.thetrouper.sentinel.data;
|
||||
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public record Report(long id, AsyncPlayerChatEvent event, HashMap<String,String> stepsTaken) {
|
||||
}
|
||||
@@ -36,20 +36,25 @@ public class MainConfig implements JsonSerializable<MainConfig> {
|
||||
public boolean preventCmdCartPlace = true;
|
||||
public boolean preventCmdCartUse = true;
|
||||
public boolean cmdBlockOpCheck = true;
|
||||
public List<String> dangerous = new ArrayList<>() {{
|
||||
add("op");
|
||||
add("deop");
|
||||
add("stop");
|
||||
add("restart");
|
||||
add("execute");
|
||||
add("sudo");
|
||||
add("esudo");
|
||||
add("fill");
|
||||
add("setblock");
|
||||
add("data");
|
||||
add("whitelist");
|
||||
add("lp")
|
||||
}};
|
||||
public List<String> dangerous = List.of(
|
||||
"op",
|
||||
"deop",
|
||||
"stop",
|
||||
"restart",
|
||||
"execute",
|
||||
"sudo",
|
||||
"esudo",
|
||||
"fill",
|
||||
"setblock",
|
||||
"data",
|
||||
"whitelist",
|
||||
"lp",
|
||||
"luckperms",
|
||||
"perms",
|
||||
"perm",
|
||||
"permission",
|
||||
"permissions"
|
||||
);
|
||||
public boolean logDangerous = true;
|
||||
public boolean logCmdBlocks = true;
|
||||
public boolean logNBT = true;
|
||||
|
||||
@@ -2,9 +2,11 @@ package io.github.thetrouper.sentinel.events;
|
||||
|
||||
import io.github.itzispyder.pdk.events.CustomListener;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.server.functions.AdvancedBlockers;
|
||||
import io.github.thetrouper.sentinel.server.functions.AntiSpam;
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -22,25 +24,35 @@ public class ChatEvent implements CustomListener {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
|
||||
Report report = ReportFalsePositives.initializeReport(e);
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antiunicode.bypass",
|
||||
Sentinel.mainConfig.chat.useAntiUnicode, "unicode",
|
||||
e,
|
||||
AdvancedBlockers::handleAdvanced);
|
||||
(event)->{
|
||||
AdvancedBlockers.handleAdvanced(event,report);
|
||||
});
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antispam.bypass",
|
||||
Sentinel.mainConfig.chat.antiSpam.antiSpamEnabled,
|
||||
"spam",
|
||||
e,
|
||||
AntiSpam::handleAntiSpam);
|
||||
(event)->{
|
||||
AntiSpam.handleAntiSpam(event,report);
|
||||
});
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antiswear.bypass",
|
||||
Sentinel.mainConfig.chat.antiSwear.antiSwearEnabled,
|
||||
"swear",
|
||||
e,
|
||||
ProfanityFilter::handleProfanityFilter);
|
||||
(event)->{
|
||||
ProfanityFilter.handleProfanityFilter(event,report);
|
||||
});
|
||||
|
||||
ReportFalsePositives.reports.put(report.id(),report);
|
||||
}
|
||||
|
||||
private static void handleEventIfNotBypassed(Player p, String permission, boolean isEnabled, String eventType, AsyncPlayerChatEvent e, Consumer<AsyncPlayerChatEvent> handler) {
|
||||
|
||||
@@ -178,75 +178,74 @@ public class FilterAction {
|
||||
}
|
||||
|
||||
private static void sendDiscordLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
|
||||
String supertitle = type.getTitle();
|
||||
String title = offender.getName() + " has triggered the " + type.getName() + "!";
|
||||
CompletableFuture.runAsync(()->{
|
||||
String supertitle = type.getTitle();
|
||||
String title = offender.getName() + " has triggered the " + type.getName() + "!";
|
||||
|
||||
String executed = type.getExecutedCommand() != null ? type.getExecutedCommand() : "Nothing, its a standard flag. You shouldn't be seeing this, please report it.";
|
||||
StringBuilder description = new StringBuilder();
|
||||
String executed = type.getExecutedCommand() != null ? type.getExecutedCommand() : "Nothing, its a standard flag. You shouldn't be seeing this, please report it.";
|
||||
StringBuilder description = new StringBuilder();
|
||||
|
||||
String historyTitle = "You found a bug! :D";
|
||||
String historyValue = "Congratulations.";
|
||||
String historyTitle = "You found a bug! :D";
|
||||
String historyValue = "Congratulations.";
|
||||
|
||||
String currentTitle = "Now go report it!";
|
||||
String currentValue = ">:(";
|
||||
String currentTitle = "Now go report it!";
|
||||
String currentValue = ">:(";
|
||||
|
||||
description.append(String.format("%1$sPlayer: `%2$s` %3$s",Emojis.rightSort,offender.getName(),Emojis.target));
|
||||
switch (type) {
|
||||
case SPAM_PUNISH -> {
|
||||
description.append(String.format("\n%1$s%2$sHeat: `%3$s/%4$s`",
|
||||
Emojis.space,
|
||||
Emojis.arrowRight,
|
||||
heatMap.get(offender),
|
||||
Sentinel.mainConfig.chat.antiSpam.punishHeat
|
||||
));
|
||||
historyTitle = "Previous: ";
|
||||
historyValue = lastMessageMap.get(offender);
|
||||
description.append(String.format("%1$sPlayer: `%2$s` %3$s",Emojis.rightSort,offender.getName(),Emojis.target));
|
||||
switch (type) {
|
||||
case SPAM_PUNISH -> {
|
||||
description.append(String.format("\n%1$s%2$sHeat: `%3$s/%4$s`",
|
||||
Emojis.space,
|
||||
Emojis.arrowRight,
|
||||
heatMap.get(offender),
|
||||
Sentinel.mainConfig.chat.antiSpam.punishHeat
|
||||
));
|
||||
historyTitle = "Previous: ";
|
||||
historyValue = lastMessageMap.get(offender);
|
||||
|
||||
currentTitle = "Current: ";
|
||||
currentValue = e.getMessage();
|
||||
currentTitle = "Current: ";
|
||||
currentValue = e.getMessage();
|
||||
}
|
||||
case SWEAR_PUNISH, SLUR_PUNISH -> {
|
||||
description.append(String.format("\n%1$s%2$sScore: `%3$s/%4$s`",
|
||||
Emojis.space,
|
||||
Emojis.arrowRight,
|
||||
scoreMap.get(offender),
|
||||
Sentinel.mainConfig.chat.antiSwear.punishScore
|
||||
));
|
||||
historyTitle = "Message: ";
|
||||
historyValue = e.getMessage();
|
||||
|
||||
currentTitle = "Reduced: ";
|
||||
currentValue = highlightProfanity(e.getMessage(),"||", "||");
|
||||
}
|
||||
}
|
||||
case SWEAR_PUNISH, SLUR_PUNISH -> {
|
||||
description.append(String.format("\n%1$s%2$sScore: `%3$s/%4$s`",
|
||||
Emojis.space,
|
||||
Emojis.arrowRight,
|
||||
scoreMap.get(offender),
|
||||
Sentinel.mainConfig.chat.antiSwear.punishScore
|
||||
));
|
||||
historyTitle = "Message: ";
|
||||
historyValue = e.getMessage();
|
||||
|
||||
currentTitle = "Reduced: ";
|
||||
currentValue = highlightProfanity(e.getMessage(),"||", "||");
|
||||
try {
|
||||
String finalHistoryTitle = historyTitle;
|
||||
String finalHistoryValue = historyValue;
|
||||
String finalCurrentTitle = currentTitle;
|
||||
String finalCurrentValue = currentValue;
|
||||
CompletableFuture.runAsync(()->{
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
DiscordWebhook.create()
|
||||
.username("Sentinel Anti-Nuke | Logs")
|
||||
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
|
||||
.addEmbed(DiscordEmbed.create()
|
||||
.author(new DiscordEmbed.Author(supertitle,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
|
||||
.title(title)
|
||||
.desc(String.valueOf(description))
|
||||
.addField(new DiscordEmbed.Field(finalHistoryTitle, finalHistoryValue,true))
|
||||
.addField(new DiscordEmbed.Field(finalCurrentTitle, finalCurrentValue,true))
|
||||
.addField(new DiscordEmbed.Field("Executed: ", executed.replaceAll("%player%",offender.getName()),false))
|
||||
.thumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay")
|
||||
.color(type.getColor())
|
||||
.build()).send(Sentinel.mainConfig.plugin.webhook);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!");
|
||||
Sentinel.log.info(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String finalHistoryTitle = historyTitle;
|
||||
String finalHistoryValue = historyValue;
|
||||
String finalCurrentTitle = currentTitle;
|
||||
String finalCurrentValue = currentValue;
|
||||
CompletableFuture.runAsync(()->{
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
DiscordWebhook.create()
|
||||
.username("Sentinel Anti-Nuke | Logs")
|
||||
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
|
||||
.addEmbed(DiscordEmbed.create()
|
||||
.author(new DiscordEmbed.Author(supertitle,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
|
||||
.title(title)
|
||||
.desc(String.valueOf(description))
|
||||
.addField(new DiscordEmbed.Field(finalHistoryTitle, finalHistoryValue,true))
|
||||
.addField(new DiscordEmbed.Field(finalCurrentTitle, finalCurrentValue,true))
|
||||
.addField(new DiscordEmbed.Field("Executed: ", executed.replaceAll("%player%",offender.getName()),false))
|
||||
.thumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay")
|
||||
.color(type.getColor())
|
||||
.build()).send(Sentinel.mainConfig.plugin.webhook);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!");
|
||||
Sentinel.log.info(ex.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.github.thetrouper.sentinel.server.functions;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.FilterSeverity;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.server.FilterAction;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
@@ -13,59 +15,75 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class AdvancedBlockers {
|
||||
|
||||
public static void handleAdvanced(AsyncPlayerChatEvent e) {
|
||||
public static void handleAdvanced(AsyncPlayerChatEvent e, Report report) {
|
||||
//if (Sentinel.isTrusted(e.getPlayer())) return;
|
||||
if (Sentinel.mainConfig.chat.useAntiUnicode) handleAntiUnicode(e);
|
||||
if (Sentinel.mainConfig.chat.useAntiURL) handleAntiURL(e);
|
||||
if (Sentinel.mainConfig.chat.useStrictRegex) handleStrictRegex(e);
|
||||
if (Sentinel.mainConfig.chat.useSwearRegex) handleSwearRegex(e);
|
||||
if (Sentinel.mainConfig.chat.useAntiUnicode) handleAntiUnicode(e,report);
|
||||
if (Sentinel.mainConfig.chat.useAntiURL) handleAntiURL(e,report);
|
||||
if (Sentinel.mainConfig.chat.useStrictRegex) handleStrictRegex(e,report);
|
||||
if (Sentinel.mainConfig.chat.useSwearRegex) handleSwearRegex(e,report);
|
||||
}
|
||||
|
||||
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
|
||||
public static void handleAntiUnicode(AsyncPlayerChatEvent e, Report report) {
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
report.stepsTaken().put("Anti-Unicode", "`%s`".formatted(message));
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Checking for unicode: " + message);
|
||||
String nonAllowed = message.replaceAll(Sentinel.advConfig.allowedCharRegex, "").trim();
|
||||
if (nonAllowed.length() != 0) {
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Caught Unicode: " + nonAllowed);
|
||||
e.setCancelled(true);
|
||||
report.stepsTaken().replace("Anti-Unicode", "`%s` %s".formatted(message, Emojis.alarm));
|
||||
FilterAction.filterPunish(e,FAT.BLOCK_UNICODE,null,null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleSwearRegex(AsyncPlayerChatEvent e) {
|
||||
String urlRegex = Sentinel.advConfig.swearRegex;
|
||||
public static void handleSwearRegex(AsyncPlayerChatEvent e, Report report) {
|
||||
String swearRegex = Sentinel.advConfig.swearRegex;
|
||||
|
||||
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
|
||||
Pattern pattern = Pattern.compile(swearRegex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(e.getMessage());
|
||||
|
||||
report.stepsTaken().put("Anti-Swear Regex", "`%s`".formatted(e.getMessage()));
|
||||
|
||||
String highlighted = Text.regexHighlighter(swearRegex,e.getMessage()," > "," < ");
|
||||
|
||||
if (matcher.find()) {
|
||||
e.setCancelled(true);
|
||||
report.stepsTaken().replace("Anti-Swear Regex", "`%s` %s".formatted(highlighted, Emojis.alarm));
|
||||
FilterAction.filterPunish(e,FAT.SWEAR_PUNISH,null,FilterSeverity.HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleStrictRegex(AsyncPlayerChatEvent e) {
|
||||
String urlRegex = Sentinel.advConfig.strictRegex;
|
||||
public static void handleStrictRegex(AsyncPlayerChatEvent e, Report report) {
|
||||
String strictRegex = Sentinel.advConfig.strictRegex;
|
||||
|
||||
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
|
||||
Pattern pattern = Pattern.compile(strictRegex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(e.getMessage());
|
||||
|
||||
report.stepsTaken().put("Strict Regex", "`%s`".formatted(e.getMessage()));
|
||||
|
||||
String highlighted = Text.regexHighlighter(strictRegex,e.getMessage()," > "," < ");
|
||||
|
||||
if (matcher.find()) {
|
||||
e.setCancelled(true);
|
||||
report.stepsTaken().replace("Strict Regex", "`%s` %s".formatted(highlighted, Emojis.alarm));
|
||||
FilterAction.filterPunish(e, FAT.SLUR_PUNISH,null, FilterSeverity.SLUR);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleAntiURL(AsyncPlayerChatEvent e) {
|
||||
public static void handleAntiURL(AsyncPlayerChatEvent e, Report report) {
|
||||
String urlRegex = Sentinel.advConfig.urlRegex;
|
||||
|
||||
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(e.getMessage());
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Checking for URLs against regex `%1$s`:%2$s".formatted(urlRegex, e.getMessage()));
|
||||
|
||||
report.stepsTaken().replace("Anti-URL", "`%s` %s".formatted(e.getMessage(), Emojis.alarm));
|
||||
|
||||
if (matcher.find()) {
|
||||
e.setCancelled(true);
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Caught URL: " + Text.regexHighlighter(e.getMessage(),Sentinel.advConfig.urlRegex," > "," < "));
|
||||
String highlighted = Text.regexHighlighter(e.getMessage(),Sentinel.advConfig.urlRegex," > "," < ");
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Caught URL: " + highlighted);
|
||||
report.stepsTaken().replace("Anti-URL", "`%s` %s".formatted(highlighted, Emojis.alarm));
|
||||
|
||||
FilterAction.filterPunish(e,FAT.BLOCK_URL,null,null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.github.thetrouper.sentinel.server.functions;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.server.FilterAction;
|
||||
import io.github.thetrouper.sentinel.server.util.GPTUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
@@ -21,10 +23,9 @@ public class AntiSpam {
|
||||
lastMessageMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void handleAntiSpam(AsyncPlayerChatEvent e) {
|
||||
public static void handleAntiSpam(AsyncPlayerChatEvent e, Report report) {
|
||||
Player p = e.getPlayer();
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
|
||||
if (!lastMessageMap.containsKey(p)) {
|
||||
lastMessageMap.put(p,"/* Placeholder Message from Sentinel */");
|
||||
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " did not have a previous message, setting to placeholder!");
|
||||
@@ -51,16 +52,20 @@ public class AntiSpam {
|
||||
}
|
||||
}
|
||||
|
||||
report.stepsTaken().put("Anti-Spam", "Heat: %s\nMessage: `%s`".formatted(heatMap.get(p),message));
|
||||
|
||||
lastMessageMap.put(p, message);
|
||||
|
||||
if (heatMap.get(p) > Sentinel.mainConfig.chat.antiSpam.punishHeat) {
|
||||
e.setCancelled(true);
|
||||
report.stepsTaken().replace("Anti-Spam", "Heat: %s\nMessage: `%s` %s".formatted(heatMap.get(p),message, Emojis.alarm));
|
||||
FilterAction.filterPunish(e,FAT.SPAM_PUNISH,GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (heatMap.get(p) > Sentinel.mainConfig.chat.antiSpam.blockHeat) {
|
||||
e.setCancelled(true);
|
||||
report.stepsTaken().replace("Anti-Spam", "Heat: %s\nMessage: `%s` %s".formatted(heatMap.get(p),message, Emojis.alarm));
|
||||
FilterAction.filterPunish(e,FAT.BLOCK_SPAM, GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), null);
|
||||
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.highGain);
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.thetrouper.sentinel.server.functions;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.FilterSeverity;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.server.FilterAction;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
@@ -23,67 +24,58 @@ public class ProfanityFilter {
|
||||
scoreMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void handleProfanityFilter(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
FilterSeverity severity = ProfanityFilter.checkSeverity(message);
|
||||
public static void handleProfanityFilter(AsyncPlayerChatEvent event, Report report) {
|
||||
Player player = event.getPlayer();
|
||||
String message = Text.removeFirstColor(event.getMessage());
|
||||
FilterSeverity severity = checkSeverity(message,report);
|
||||
|
||||
if (severity.equals(FilterSeverity.SAFE)) return;
|
||||
|
||||
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
|
||||
scoreMap.putIfAbsent(player, 0);
|
||||
int previousScore = scoreMap.get(player);
|
||||
ServerUtils.sendDebugMessage(String.format("AntiSwear Flag, Message: %s Concentrated: %s Severity: %s Previous Score: %d Adding Score: %d",
|
||||
message, fullSimplify(message), severity, previousScore, severity.getScore()));
|
||||
event.setCancelled(true);
|
||||
|
||||
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + severity.getScore());
|
||||
e.setCancelled(true);
|
||||
int newScore = previousScore + severity.getScore();
|
||||
scoreMap.put(player, newScore);
|
||||
|
||||
if (scoreMap.get(p) + severity.getScore() > Sentinel.mainConfig.chat.antiSwear.punishScore) {
|
||||
scoreMap.put(p,scoreMap.get(p)+severity.getScore());
|
||||
FilterAction.filterPunish(e,FAT.SWEAR_PUNISH,null,severity);
|
||||
if (newScore > Sentinel.mainConfig.chat.antiSwear.punishScore) {
|
||||
FilterAction.filterPunish(event, FAT.SWEAR_PUNISH, null, severity);
|
||||
return;
|
||||
}
|
||||
|
||||
scoreMap.put(p,scoreMap.get(p)+severity.getScore());
|
||||
|
||||
FilterAction.filterPunish(e,getFAT(severity),null,severity);
|
||||
FilterAction.filterPunish(event, getFAT(severity), null, severity);
|
||||
}
|
||||
|
||||
|
||||
private static FAT getFAT(FilterSeverity severity) {
|
||||
switch (severity) {
|
||||
case SAFE -> {
|
||||
return FAT.SAFE;
|
||||
}
|
||||
case LOW, MEDIUM_LOW, MEDIUM, MEDIUM_HIGH, HIGH -> {
|
||||
return FAT.BLOCK_SWEAR;
|
||||
}
|
||||
case SLUR -> {
|
||||
return FAT.SLUR_PUNISH;
|
||||
}
|
||||
default -> throw new IllegalArgumentException("Warning! This severity doesn't exist! " + severity);
|
||||
}
|
||||
return switch (severity) {
|
||||
case SAFE -> FAT.SAFE;
|
||||
case LOW, MEDIUM_LOW, MEDIUM, MEDIUM_HIGH, HIGH -> FAT.BLOCK_SWEAR;
|
||||
case SLUR -> FAT.SLUR_PUNISH;
|
||||
};
|
||||
}
|
||||
|
||||
public static String highlightProfanity(String text) {
|
||||
String highlightedSwears = highlightSwears(fullSimplify(text), "&e", "&f");
|
||||
String highlightedText = highlightSlurs(highlightedSwears, "&c", "&f");
|
||||
return Text.color(highlightedText);
|
||||
return highlightProfanity(text, "&e", "&f");
|
||||
}
|
||||
|
||||
public static String highlightProfanity(String text, String start, String end) {
|
||||
String highlightedSwears = highlightSwears(fullSimplify(text), start, end);
|
||||
String highlightedText = highlightSlurs(highlightedSwears, start, end);
|
||||
return Text.color(highlightedText);
|
||||
return Text.color(highlightSlurs(highlightedSwears, start, end));
|
||||
}
|
||||
|
||||
private static String highlightSwears(String text, String start, String end) {
|
||||
for (String swear : swearBlacklist) {
|
||||
if (text.contains(swear)) {text = text.replace(swear, start + swear + end);}
|
||||
text = text.replace(swear, start + swear + end);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String highlightSlurs(String text, String start, String end) {
|
||||
for (String slur : slurs) {
|
||||
if (text.contains(slur)) {
|
||||
text = text.replace(slur, start + slur + end);
|
||||
}
|
||||
text = text.replace(slur, start + slur + end);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@@ -112,13 +104,15 @@ public class ProfanityFilter {
|
||||
String simplifiedText = simplifyRepeatingLetters(strippedText);
|
||||
return removePeriodsAndSpaces(simplifiedText);
|
||||
}
|
||||
public static FilterSeverity checkSeverity(String text) {
|
||||
public static FilterSeverity checkSeverity(String text, Report report) {
|
||||
// 1:
|
||||
String lowercasedText = text.toLowerCase();
|
||||
report.stepsTaken().put("Lowercased", lowercasedText);
|
||||
ServerUtils.sendDebugMessage("ProfanityFilter: Lowercased: " + lowercasedText);
|
||||
|
||||
// 2:
|
||||
String cleanedText = removeFalsePositives(lowercasedText);
|
||||
report.stepsTaken().put("Remove False Positives", cleanedText);
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed False positives: " + cleanedText));
|
||||
|
||||
// 3:
|
||||
@@ -127,6 +121,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 4:
|
||||
String convertedText = convertLeetSpeakCharacters(cleanedText);
|
||||
report.stepsTaken().put("Convert LeetSpeak", convertedText);
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Leet Converted: " + convertedText));
|
||||
|
||||
// 5:
|
||||
@@ -135,6 +130,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 6:
|
||||
String strippedText = stripSpecialCharacters(convertedText);
|
||||
report.stepsTaken().put("Remove Special Characters", strippedText);
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Specials Removed: " + strippedText));
|
||||
|
||||
// 7:
|
||||
@@ -143,6 +139,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 8:
|
||||
String simplifiedText = simplifyRepeatingLetters(strippedText);
|
||||
report.stepsTaken().put("Remove Repeats", simplifiedText);
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed Repeating: " + simplifiedText));
|
||||
|
||||
// 9:
|
||||
@@ -151,6 +148,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 10:
|
||||
String finalText = removePeriodsAndSpaces(simplifiedText);
|
||||
report.stepsTaken().put("Remove Punctuation", finalText);
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Remove Punctuation: " + finalText));
|
||||
|
||||
// 11:
|
||||
|
||||
@@ -5,9 +5,11 @@ import io.github.itzispyder.pdk.utils.discord.DiscordEmbed;
|
||||
import io.github.itzispyder.pdk.utils.discord.DiscordWebhook;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.server.util.Randomizer;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -18,6 +20,15 @@ import java.util.Map;
|
||||
|
||||
public class ReportFalsePositives {
|
||||
public static Map<String,AsyncPlayerChatEvent> reportMap = new HashMap<>();
|
||||
public static Map<Long,Report> reports = new HashMap<>();
|
||||
|
||||
public static Report initializeReport(AsyncPlayerChatEvent e) {
|
||||
final long reportID = Randomizer.generateID();
|
||||
HashMap<String,String> steps = new HashMap<>();
|
||||
steps.put("Original Message", e.getMessage());
|
||||
return new Report(reportID,e,steps);
|
||||
}
|
||||
|
||||
public static String generateReport(AsyncPlayerChatEvent e) {
|
||||
final long reportLong = Randomizer.generateID();
|
||||
final String reportID = Long.toString(reportLong);
|
||||
@@ -30,6 +41,34 @@ public class ReportFalsePositives {
|
||||
});
|
||||
return reportID;
|
||||
}
|
||||
|
||||
|
||||
public static void sendFalsePositiveReport(Report report) {
|
||||
DiscordEmbed.Builder embed = DiscordEmbed.create()
|
||||
.author(new DiscordEmbed.Author("Anti-Swear False Positive","",null))
|
||||
.title("Flag Report:")
|
||||
.desc(String.format("""
|
||||
%1$sPlayer: %2$s %3$s\n
|
||||
%4$s %5$sUUID: `%2$s`\n
|
||||
""",
|
||||
Emojis.rightSort,
|
||||
report.event().getPlayer().getName(),
|
||||
Emojis.target,
|
||||
Emojis.space,
|
||||
Emojis.arrowRight
|
||||
));
|
||||
|
||||
report.stepsTaken().forEach((key, value)->{
|
||||
embed.addField(new DiscordEmbed.Field(key,value));
|
||||
});
|
||||
|
||||
DiscordWebhook.create()
|
||||
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
|
||||
.username("Sentinel Anti-Nuke | Logs")
|
||||
.addEmbed(embed.build())
|
||||
.send(Sentinel.mainConfig.plugin.webhook);
|
||||
}
|
||||
|
||||
public static void sendFalsePositiveReport(String reportID) {
|
||||
AsyncPlayerChatEvent e = reportMap.get(reportID);
|
||||
String orig = e.getMessage();
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.itzispyder.pdk.utils.SchedulerUtils;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.cmds.SocialSpyCommand;
|
||||
import io.github.thetrouper.sentinel.data.ActionType;
|
||||
import io.github.thetrouper.sentinel.data.Report;
|
||||
import io.github.thetrouper.sentinel.events.CommandEvent;
|
||||
import io.github.thetrouper.sentinel.server.Action;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -129,17 +130,18 @@ public class SystemCheck {
|
||||
|
||||
public static void chatCheck(Player p) {
|
||||
SocialSpyCommand.spyMap.put(p.getUniqueId(),true);
|
||||
|
||||
AsyncPlayerChatEvent swear = new AsyncPlayerChatEvent(true,p,"Sentinel AntiSwear check > Fvck", Set.of(p));
|
||||
AsyncPlayerChatEvent spam = new AsyncPlayerChatEvent(true,p,"Sentinel AntiSpam check", Set.of(p));
|
||||
AsyncPlayerChatEvent falsePositive = new AsyncPlayerChatEvent(true,p,"Sentinel False Positive check > I like sentanal anti nuke", Set.of(p));
|
||||
AsyncPlayerChatEvent unicode = new AsyncPlayerChatEvent(true,p,"\u202Elmao i am bypassing the filter tihs ", Set.of(p));
|
||||
AsyncPlayerChatEvent url = new AsyncPlayerChatEvent(true,p,"join my lifesteal server! play.cringsteal.net", Set.of(p));
|
||||
ProfanityFilter.handleProfanityFilter(swear);
|
||||
AdvancedBlockers.handleAntiUnicode(unicode);
|
||||
AdvancedBlockers.handleAntiURL(url);
|
||||
ProfanityFilter.handleProfanityFilter(swear,ReportFalsePositives.initializeReport(swear));
|
||||
AdvancedBlockers.handleAntiUnicode(unicode,ReportFalsePositives.initializeReport(unicode));
|
||||
AdvancedBlockers.handleAntiURL(url,ReportFalsePositives.initializeReport(url));
|
||||
SchedulerUtils.loop(5,4, (loop)->{
|
||||
AntiSpam.lastMessageMap.put(p,"Sentinel AntiSpam Check");
|
||||
AntiSpam.handleAntiSpam(spam);
|
||||
AntiSpam.handleAntiSpam(spam,ReportFalsePositives.initializeReport(spam));
|
||||
});
|
||||
|
||||
String report = ReportFalsePositives.generateReport(falsePositive);
|
||||
|
||||
Reference in New Issue
Block a user