Move Webhook out to main package and add send utility
Signed-off-by: Etzelia <etzelia@hotmail.com>pull/1/head
parent
6e20ef32b7
commit
bc25422492
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
<groupId>xyz.etztech</groupId>
|
||||
<artifactId>javacord</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1.0</version>
|
||||
<version>0.2.0</version>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package xyz.etztech;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Javacord {
|
||||
|
||||
public static String escapeFormat(String input) {
|
||||
|
@ -13,4 +19,22 @@ public class Javacord {
|
|||
public static String escapeQuote(String input) {
|
||||
return input.replaceAll("\"", "\\\\\"");
|
||||
}
|
||||
|
||||
public static void sendWebhook(String webhookURL, Webhook webhook) throws Exception {
|
||||
URL url = new URL(webhookURL);
|
||||
URLConnection con = url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection) con;
|
||||
http.setRequestMethod("POST");
|
||||
http.setDoOutput(true);
|
||||
|
||||
byte[] out = webhook.toString().getBytes(StandardCharsets.UTF_8);
|
||||
int length = out.length;
|
||||
http.setFixedLengthStreamingMode(length);
|
||||
http.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
http.setRequestProperty("User-Agent", "Javacord Agent");
|
||||
|
||||
try (OutputStream os = http.getOutputStream()) {
|
||||
os.write(out, 0, out.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.etztech.embed;
|
||||
package xyz.etztech;
|
||||
|
||||
import xyz.etztech.Javacord;
|
||||
import xyz.etztech.embed.Embed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
|
@ -1,7 +1,7 @@
|
|||
import xyz.etztech.Javacord;
|
||||
import xyz.etztech.embed.Author;
|
||||
import xyz.etztech.embed.Embed;
|
||||
import xyz.etztech.embed.Webhook;
|
||||
import xyz.etztech.Webhook;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
|
|
Loading…
Reference in New Issue