Move Webhook out to main package and add send utility

Signed-off-by: Etzelia <etzelia@hotmail.com>
pull/1/head
Etzelia 2020-07-30 21:29:41 -05:00
parent 6e20ef32b7
commit bc25422492
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
4 changed files with 28 additions and 4 deletions

View File

@ -6,7 +6,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>javacord</artifactId> <artifactId>javacord</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.1.0</version> <version>0.2.0</version>
<developers> <developers>
<developer> <developer>

View File

@ -1,5 +1,11 @@
package xyz.etztech; 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 class Javacord {
public static String escapeFormat(String input) { public static String escapeFormat(String input) {
@ -13,4 +19,22 @@ public class Javacord {
public static String escapeQuote(String input) { public static String escapeQuote(String input) {
return input.replaceAll("\"", "\\\\\""); 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);
}
}
} }

View File

@ -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.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,7 +1,7 @@
import xyz.etztech.Javacord; import xyz.etztech.Javacord;
import xyz.etztech.embed.Author; import xyz.etztech.embed.Author;
import xyz.etztech.embed.Embed; import xyz.etztech.embed.Embed;
import xyz.etztech.embed.Webhook; import xyz.etztech.Webhook;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;