forked from Minecraft/javacord
41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
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) {
|
|
return input
|
|
.replaceAll("_", "\\\\\\\\_")
|
|
.replaceAll("\\*", "\\\\\\\\*")
|
|
.replaceAll("~", "\\\\\\\\~")
|
|
.replaceAll("\\|", "\\\\\\\\|");
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|