fixed it not being able to get the webhook

This commit is contained in:
rrryfu
2023-09-26 15:58:26 +08:00
parent ace02fa9e8
commit fb4baac9d4
3 changed files with 27 additions and 19 deletions
+14 -14
View File
@@ -55,7 +55,7 @@ public class Main extends JavaPlugin {
//FileWriter pubMessageWebhookConfigWriter = new FileWriter(pubMessageWebhookConfig);
//notifyWebhookConfigWriter.write("{\"url_notify\": \"default-ns\"}");
FileWriter linkConfigWriter = new FileWriter(webhookConfig);
linkConfigWriter.write("{\n \"url_publicmsg\": \"default-ns\", \n \"url_notify\": \"default-ns\"\n}");
linkConfigWriter.write("{\"url_publicmsg\": \"default-ns\",\"url_notify\": \"default-ns\"}");
linkConfigWriter.close();
//notifyWebhookConfigWriter.close();
} else {
@@ -93,6 +93,10 @@ public class Main extends JavaPlugin {
public static boolean validateWebhook_Pub() {
try {
if (getPublicMessageWebhook().equals("default-ns") || !getPublicMessageWebhook().contains("https://")) {
System.out.println("There was no webhook set for the public messages function. The send-message command cannot be used until you do.");
return true;
}
URL url = new URL(getPublicMessageWebhook());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
@@ -100,11 +104,12 @@ public class Main extends JavaPlugin {
if (responseCode == HttpURLConnection.HTTP_OK) {
return true;
} else {
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
System.out.println("Invalid webhook URL provided for your public messages. Please provide the correct webhook and check for any typos.");
return false;
}
} catch (Exception e) {
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
System.out.println("Invalid webhook URL provide for your public messages. Please provide the correct webhook and check for any typos. (Caught exception)");
System.out.println("Exception: %s".formatted(e));
return false;
}
}
@@ -117,11 +122,12 @@ public class Main extends JavaPlugin {
if (responseCode == HttpURLConnection.HTTP_OK) {
return true;
} else {
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos.");
return false;
}
} catch (Exception e) {
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos. (Caught exception)");
System.out.println("Exception: %s".formatted(e));
return false;
}
}
@@ -133,18 +139,12 @@ public class Main extends JavaPlugin {
String lineMsg = MsgParse.getAsJsonObject().get("url_publicmsg").getAsString();
brfmsg.close();
if (lineMsg.equals("default-ns")) {
System.out.printf("Please set the public message webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
webhooksAreValidUrls = false;
return lineMsg;
} else if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) {
if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) {
webhooksAreValidUrls = true;
return lineMsg;
} else {
System.out.printf("Please set the public message webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
webhooksAreValidUrls = false;
return lineMsg;
}
return "default-ns";
} catch (IOException e) {
throw new RuntimeException(e);
}
+1 -1
View File
@@ -19,7 +19,7 @@ public class ServerUtils {
Socket s = new Socket();
s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15);
s.close();
System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + serverAddress + ":" + server.getPort() + ")");
System.out.println("Server is online. Test notifying by sending a message to your webhook... (Pinged " + serverAddress + ":" + server.getPort() + ")");
return true;
} catch (Exception e) {
System.out.println("Server is inactive. Pinging fallback address...");