System check + webhook refactor

This commit is contained in:
TheTrouper
2024-02-01 17:00:56 -06:00
parent d6bebef07c
commit 781026ddd0
8 changed files with 67 additions and 43 deletions

View File

@@ -30,7 +30,7 @@ dependencies {
compileOnly 'org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT' compileOnly 'org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT'
implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.google.code.gson:gson:2.10.1'
implementation 'club.minnced:discord-webhooks:0.8.4' implementation 'club.minnced:discord-webhooks:0.8.4'
implementation files("libs/PDK-1.3.3.jar") implementation files("libs/PDK-1.3.4.jar")
} }
def targetJavaVersion = 16 def targetJavaVersion = 16

BIN
libs/JDWebHooks-1.0.1.jar Normal file

Binary file not shown.

View File

@@ -45,7 +45,6 @@ public final class Sentinel extends JavaPlugin {
public static String serverID; public static String serverID;
public static String license; public static String license;
public static String IP; public static String IP;
public static WebhookClient webclient;
/** /**
* Plugin startup logic * Plugin startup logic

View File

@@ -33,6 +33,9 @@ public class SentinelCommand implements CustomCommand {
p.sendMessage(Text.prefix("Reloading Sentinel!")); p.sendMessage(Text.prefix("Reloading Sentinel!"));
Sentinel.log.info("[Sentinel] Re-Initializing Sentinel!"); Sentinel.log.info("[Sentinel] Re-Initializing Sentinel!");
instance.loadConfig(); instance.loadConfig();
}
case "full-system-check" -> {
} }
case "debug" -> { case "debug" -> {
switch (args.get(1).toString()) { switch (args.get(1).toString()) {
@@ -86,7 +89,7 @@ public class SentinelCommand implements CustomCommand {
@Override @Override
public void dispatchCompletions(CompletionBuilder b) { public void dispatchCompletions(CompletionBuilder b) {
b.then(b.arg("reload","getheat")); b.then(b.arg("reload","getheat","full-system-check"));
b.then(b.arg("debug").then( b.then(b.arg("debug").then(
b.arg("antiswear","antispam","lang","toggle"))); b.arg("antiswear","antispam","lang","toggle")));
} }

View File

@@ -5,10 +5,11 @@ import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder; import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessage; import club.minnced.discord.webhook.send.WebhookMessage;
import club.minnced.discord.webhook.send.WebhookMessageBuilder; import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import io.github.itzispyder.pdk.PDK;
import io.github.itzispyder.pdk.utils.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.data.Emojis; import io.github.thetrouper.sentinel.data.Emojis;
import io.github.thetrouper.sentinel.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.server.util.FileUtils; import io.github.thetrouper.sentinel.server.util.FileUtils;
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;
@@ -173,6 +174,7 @@ public class Action {
actions += (revertGM) ? Emojis.rightSort + " **GM Reverted:** " + Emojis.success + "\n" : ""; actions += (revertGM) ? Emojis.rightSort + " **GM Reverted:** " + Emojis.success + "\n" : "";
actions += Emojis.rightSort + " **Logged:** " + Emojis.success; actions += Emojis.rightSort + " **Logged:** " + Emojis.success;
Webhook
WebhookMessage message = new WebhookMessageBuilder() WebhookMessage message = new WebhookMessageBuilder()
.setUsername("Sentinel Anti-Nuke | Logs") .setUsername("Sentinel Anti-Nuke | Logs")
.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png"). .setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png").

View File

@@ -0,0 +1,30 @@
package io.github.thetrouper.sentinel.server.functions;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.cmds.SocialSpyCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.Set;
public class SystemCheck {
public static void fullCheck(Player p) {
chatCheck(p);
}
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));
ProfanityFilter.handleProfanityFilter(swear);
SchedulerUtils.loop(10,5, (loop)->{
AntiSpam.lastMessageMap.put(p,"Sentinel AntiSpam Check");
AntiSpam.handleAntiSpam(spam);
});
Message.messagePlayer(p,p,"Sentinel Automatic System Check > Private Message");
}
}

View File

@@ -6,6 +6,8 @@ import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder; import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessage; import club.minnced.discord.webhook.send.WebhookMessage;
import club.minnced.discord.webhook.send.WebhookMessageBuilder; import club.minnced.discord.webhook.send.WebhookMessageBuilder;
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.Sentinel;
import io.github.thetrouper.sentinel.data.Emojis; import io.github.thetrouper.sentinel.data.Emojis;
import io.github.thetrouper.sentinel.server.util.CipherUtils; import io.github.thetrouper.sentinel.server.util.CipherUtils;
@@ -20,34 +22,25 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Telemetry { public class Telemetry {
public static WebhookClient telemetryHook; public static String webhook;
public static void initTelemetryHook() { public static void initTelemetryHook() {
WebhookClientBuilder builder = new WebhookClientBuilder(fetchTelemetryHook()); webhook = fetchTelemetryHook();
builder.setThreadFactory((job) -> {
Thread thread = new Thread(job);
thread.setName("WebhookThread");
thread.setDaemon(true);
return thread;
});
builder.setWait(true);
telemetryHook = builder.build();
} }
public static boolean sendStartupLog() { public static boolean sendStartupLog() {
WebhookMessage embed = new WebhookMessageBuilder() try {
.setUsername("Sentinel Anti-Nuke | Telemetry") DiscordWebhook.create()
.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png"). .username("Sentinel Anti-Nuke | Telemetry")
addEmbeds(new WebhookEmbedBuilder() .avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.setAuthor(new WebhookEmbed.EmbedAuthor("Server Startup Log",null,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/")) .addEmbed(DiscordEmbed.create()
.setTitle(new WebhookEmbed.EmbedTitle("A server has started up successfully",null)) .author(new DiscordEmbed.Author("Server Startup Log","https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.setDescription("Server " + Sentinel.serverID + "\n" + .title("A server has started up successfully")
.desc("Server " + Sentinel.serverID + "\n" +
Emojis.rightSort + " License: ||" + Sentinel.license + "||\n" + Emojis.rightSort + " License: ||" + Sentinel.license + "||\n" +
Emojis.rightSort + " IP: ||" + Sentinel.IP + "||") Emojis.rightSort + " IP: ||" + Sentinel.IP + "||")
.setColor(Color.GREEN.getRGB()) .color(0x44FF44)
.build()) .build()
.build(); ).send(webhook);
try {
telemetryHook.send(embed);
return true; return true;
} catch (Exception ex) { } catch (Exception ex) {
Sentinel.log.info("Failed to initialize dynamic auth!"); Sentinel.log.info("Failed to initialize dynamic auth!");
@@ -55,25 +48,22 @@ public class Telemetry {
} }
} }
public static boolean sendShutdownLog() { public static void sendShutdownLog() {
WebhookMessage embed = new WebhookMessageBuilder() try {
.setUsername("Sentinel Anti-Nuke | Telemetry") DiscordWebhook.create()
.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png"). .username("Sentinel Anti-Nuke | Telemetry")
addEmbeds(new WebhookEmbedBuilder() .avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.setAuthor(new WebhookEmbed.EmbedAuthor("Server Shutdown Log",null,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/")) .addEmbed(DiscordEmbed.create()
.setTitle(new WebhookEmbed.EmbedTitle("A server has shut down successfully",null)) .author(new DiscordEmbed.Author("Server Shutdown Log","https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.setDescription("Server " + Sentinel.serverID + "\n" + .title("A server has shut down")
.desc("Server " + Sentinel.serverID + "\n" +
Emojis.rightSort + " License: ||" + Sentinel.license + "||\n" + Emojis.rightSort + " License: ||" + Sentinel.license + "||\n" +
Emojis.rightSort + " IP: ||" + Sentinel.IP + "||") Emojis.rightSort + " IP: ||" + Sentinel.IP + "||")
.setColor(Color.RED.getRGB()) .color(0xFF0000)
.build()) .build()
.build(); ).send(webhook);
try {
telemetryHook.send(embed);
return true;
} catch (Exception ex) { } catch (Exception ex) {
Sentinel.log.info("Failed to send dynamic shutdown!"); Sentinel.log.info("Failed to send dynamic shutdown!");
return false;
} }
} }