better webhook validation ft. gpt4

This commit is contained in:
mangorifo
2023-03-29 16:52:22 +08:00
parent ef7609dccf
commit 99e9c784cd
+30 -6
View File
@@ -21,6 +21,8 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Objects;
public class Main extends JavaPlugin {
@@ -89,16 +91,38 @@ public class Main extends JavaPlugin {
}
public static boolean validateWebhook_Pub() {
if (getPublicMessageWebhook().startsWith("https://") || getPublicMessageWebhook().startsWith("http://"))
return true;
else
try {
URL url = new URL(getPublicMessageWebhook());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
return true;
} else {
System.out.println("Invalid webhook URL provided. Please create a new one.");
return false;
}
} catch (Exception e) {
System.out.println("Invalid webhook URL provided. Please create a new one.. (Caught exception)");
return false;
}
}
public static boolean validateWebhook_Ntfy() {
if (getNotifyWebhook().startsWith("https://") || getNotifyWebhook().startsWith("http://"))
return true;
else
try {
URL url = new URL(getNotifyWebhook());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
return true;
} else {
System.out.println("Invalid webhook URL provided. Please create a new one.");
return false;
}
} catch (Exception e) {
System.out.println("Invalid webhook URL provided. Please create a new one.. (Caught exception)");
return false;
}
}
public static String getPublicMessageWebhook() {
try {