add version checking, update discord URL, and add a message when you don't have perms

This commit is contained in:
Badbird5907
2022-11-06 14:52:35 -05:00
parent a44913aed6
commit bd9328d452
7 changed files with 83 additions and 4 deletions

View File

@@ -0,0 +1,52 @@
package net.nuggetmc.tplus.utils;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.HttpsURLConnection;
/**
* Used for debug logs.
* https://github.com/kaimu-kun/hastebin.java/blob/master/src/me/kaimu/hastebin/Hastebin.java
*/
public class Hastebin {
public String post(String text, boolean raw) throws IOException {
byte[] postData = text.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String requestURL = "https://hastebin.com/documents";
URL url = new URL(requestURL);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Hastebin Java Api");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
conn.setUseCaches(false);
String response = null;
DataOutputStream wr;
try {
wr = new DataOutputStream(conn.getOutputStream());
wr.write(postData);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
response = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (response.contains("\"key\"")) {
response = response.substring(response.indexOf(":") + 2, response.length() - 2);
String postURL = raw ? "https://hastebin.com/raw/" : "https://hastebin.com/";
response = postURL + response;
}
return response;
}
}