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
+12 -4
View File
@@ -4,8 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment="fix stuff and add more functionality (definitely) (hi again)">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment="wrong version number">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@@ -119,12 +118,21 @@
<option name="project" value="LOCAL" />
<updated>1695656657760</updated>
</task>
<option name="localTasksCounter" value="3" />
<task id="LOCAL-00003" summary="wrong version number">
<option name="closed" value="true" />
<created>1695657371321</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1695657371321</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="hmmm" />
<MESSAGE value="fix stuff and add more functionality (definitely) (hi again)" />
<option name="LAST_COMMIT_MESSAGE" value="fix stuff and add more functionality (definitely) (hi again)" />
<MESSAGE value="wrong version number" />
<option name="LAST_COMMIT_MESSAGE" value="wrong version number" />
</component>
</project>
+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...");