mirror of
https://github.com/darverdevs/Uranium.git
synced 2024-11-21 15:06:03 -08:00
feat(ipcheck): implement webhook reporting functionality
This commit is contained in:
parent
80f7df8eb4
commit
c5ebf307d9
|
@ -7,6 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import uranium.listeners.*;
|
||||
import uranium.tasks.IPCheck;
|
||||
import uranium.user.*;
|
||||
|
||||
public class Main extends JavaPlugin implements PluginMessageListener {
|
||||
|
@ -34,11 +35,12 @@ public class Main extends JavaPlugin implements PluginMessageListener {
|
|||
}
|
||||
|
||||
private void setupCommands() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void setupTasks() {
|
||||
|
||||
getLogger().info("Initializing tasks...");
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new IPCheck(this), 30, 30); // 1.5 seconds
|
||||
}
|
||||
|
||||
private void setupPluginChannels() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
|||
import uranium.Main;
|
||||
import uranium.user.UserManager;
|
||||
import uranium.util.Util;
|
||||
import uranium.util.WebhookUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -37,6 +38,14 @@ public class IPCheck implements Runnable {
|
|||
Util.sendStaff(prefix + "&c" + user.getName() + "&7 joined using the debug runtime.");
|
||||
else
|
||||
Util.sendStaff(prefix + "&c" + user.getName() + "&7 joined using a strange domain: &c" + user.getDomain());
|
||||
|
||||
if (plugin.getConfig().getBoolean("suspicious-domains.enable-webhook"))
|
||||
WebhookUtil.sendSusDomain(user.getName(),
|
||||
user.getDomain().equalsIgnoreCase("null")
|
||||
? "Offline Download"
|
||||
: user.getDomain().equalsIgnoreCase("")
|
||||
? "Debug Runtime"
|
||||
: user.getDomain());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
60
src/main/java/uranium/util/WebhookUtil.java
Normal file
60
src/main/java/uranium/util/WebhookUtil.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
package uranium.util;
|
||||
|
||||
import club.minnced.discord.webhook.WebhookClient;
|
||||
import club.minnced.discord.webhook.WebhookClientBuilder;
|
||||
import club.minnced.discord.webhook.send.WebhookEmbed;
|
||||
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import uranium.Main;
|
||||
|
||||
public class WebhookUtil {
|
||||
|
||||
private static final Main plugin;
|
||||
|
||||
static {
|
||||
plugin = JavaPlugin.getPlugin(Main.class);
|
||||
}
|
||||
|
||||
private static String filterForDiscord(String message) {
|
||||
return message
|
||||
.replace("_", "\\_")
|
||||
.replace("*", "\\*")
|
||||
.replace("~", "\\~")
|
||||
.replace("`", "\\`")
|
||||
.replace("|", "\\|")
|
||||
.replace("> ", "\\> ")
|
||||
.replace("@everyone", "")
|
||||
.replace("@here", "");
|
||||
}
|
||||
|
||||
public static void sendSusDomain(String username, String domain) {
|
||||
String webhookURI = plugin.getConfig().getString("suspicious-domains.webhook-url");
|
||||
if (webhookURI.equalsIgnoreCase("")) {
|
||||
plugin.getLogger().warning("The webhook URL for suspicious domains has been incorrectly configured.");
|
||||
return;
|
||||
}
|
||||
WebhookClientBuilder builder = new WebhookClientBuilder(webhookURI);
|
||||
builder.setThreadFactory((job) -> {
|
||||
Thread thread = new Thread(job);
|
||||
thread.setName("Webhook");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
builder.setWait(true);
|
||||
try (WebhookClient client = builder.build()) {
|
||||
WebhookEmbed embed = new WebhookEmbedBuilder()
|
||||
.setColor(0xFF0000)
|
||||
.setDescription("A user has logged onto the server using a suspicious domain.")
|
||||
.addField(new WebhookEmbed.EmbedField(true, "Username", filterForDiscord(username)))
|
||||
.addField(new WebhookEmbed.EmbedField(true, "Domain", "http://" + filterForDiscord(domain)))
|
||||
.build();
|
||||
|
||||
client.send(embed);
|
||||
} catch(Exception ex) {
|
||||
plugin.getLogger().severe("An error occurred while attempting to deliver the webhook. Please report the following stacktrace to Cold.");
|
||||
plugin.getLogger().severe("Webhook URL: " + webhookURI);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user