better webhook validation ft. gpt4
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user