fixed code from last commit

This commit is contained in:
5gi 2022-11-04 15:31:37 -04:00
parent e25bff8f07
commit e0f590b2bf

View File

@ -1,4 +1,4 @@
package tech.nevets.deepj; package tech.nevets.DeepJ;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
@ -8,12 +8,14 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects;
public class Translator { public class Translator {
//TODO Test class to make sure multiple contructors work. //TODO Test class to make sure multiple contructors work.
public static String globalAuthKey = "null"; public static String globalAuthKey = "null";
public static void setGlobalAuthKey(String key) { public static void setGlobalAuthKey(String key) {
this.globalAuthKey = key; globalAuthKey = key;
} }
private Request request; private Request request;
public Translator() { public Translator() {
@ -22,18 +24,18 @@ public class Translator {
"\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you are trying to use global auth keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." +
"\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n"); "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
} else { } else {
request = new request(globalAuthKey); request = new Request(globalAuthKey);
} }
} }
public Translator(@NotNull String authKey) { public Translator(String authKey) {
if (globalAuthKey != "null") { if (!Objects.equals(globalAuthKey, "null")) {
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" +
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)"); "\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)");
} }
request = new Request(authKey); request = new Request(authKey);
} }
public Translator(@NotNull String authKey, @NotNull boolean silence) { public Translator(String authKey, boolean silence) {
if (globalAuthKey != "null" && silence == false) { if (!Objects.equals(globalAuthKey, "null") && !silence) {
System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" + System.out.println("[DeepJ] Looks like you have defined a global auth key already! You can use if by just typing \"new Traslator()\"" +
"\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)"); "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
} }
@ -53,7 +55,7 @@ public class Translator {
JSONArray jsonArray = jsonObject.getJSONArray("translations"); JSONArray jsonArray = jsonObject.getJSONArray("translations");
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i); JSONObject jsonObject1 = jsonArray.getJSONObject(i);
message = jsonObject.getString("text"); message = jsonObject1.getString("text");
} }
return message; return message;
} }