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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
@@ -89,17 +91,39 @@ public class Main extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean validateWebhook_Pub() {
|
public static boolean validateWebhook_Pub() {
|
||||||
if (getPublicMessageWebhook().startsWith("https://") || getPublicMessageWebhook().startsWith("http://"))
|
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;
|
return true;
|
||||||
else
|
} else {
|
||||||
|
System.out.println("Invalid webhook URL provided. Please create a new one.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static boolean validateWebhook_Ntfy() {
|
} catch (Exception e) {
|
||||||
if (getNotifyWebhook().startsWith("https://") || getNotifyWebhook().startsWith("http://"))
|
System.out.println("Invalid webhook URL provided. Please create a new one.. (Caught exception)");
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
public static boolean validateWebhook_Ntfy() {
|
||||||
|
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() {
|
public static String getPublicMessageWebhook() {
|
||||||
try {
|
try {
|
||||||
BufferedReader brfmsg = new BufferedReader(new FileReader(pubMessageWebhookConfig));
|
BufferedReader brfmsg = new BufferedReader(new FileReader(pubMessageWebhookConfig));
|
||||||
|
|||||||
Reference in New Issue
Block a user