Skip to content

Commit 6fc8dbd

Browse files
BullSharkCreativeCodeCat
authored andcommitted
Added Leet api into the bot
1 parent 698dca3 commit 6fc8dbd

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/main/java/jrobo/Leet.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@
2020

2121
import com.google.gson.Gson;
2222
import com.google.gson.GsonBuilder;
23-
//import java.io.BufferedReader;
23+
import com.google.gson.JsonSyntaxException;
2424
import java.io.IOException;
2525
import java.net.URI;
26-
//import java.io.InputStreamReader;
27-
//import java.io.OutputStreamWriter;
2826
import java.util.Arrays;
2927
import java.net.URL;
3028
import java.net.URLEncoder;
3129
import java.net.http.HttpClient;
32-
//import java.net.HttpRequest;
3330
import java.net.http.HttpResponse;
3431
import java.net.http.HttpResponse.BodyHandlers;
3532
import java.nio.charset.StandardCharsets;
36-
//import org.apache.http.HttpRequest;
3733
import java.net.http.HttpRequest;
3834
import java.util.logging.Level;
3935
import java.util.logging.Logger;
@@ -59,7 +55,7 @@ public class Leet {
5955
private static final String BASE_URL = "http://expectusafterlun.ch:5000/1337x";
6056
private String fullUrl;
6157
private String json;
62-
private final int MAX_RESULTS = 5; //@TODO Use me
58+
private final int MAX_RESULTS = 3;
6359
private String query;
6460
private final String API_KEY;
6561
private final Config CONFIG;
@@ -145,7 +141,7 @@ public Leet(final Config CONFIG, final String SEARCH) throws NullPointerExceptio
145141
// There is no CATEGORY. Search ALL.
146142
category = "";
147143
query = SEARCH;
148-
ex.printStackTrace();
144+
Logger.getLogger(Leet.class.getName()).log(Level.SEVERE, null, ex);
149145
}
150146

151147
/**
@@ -242,20 +238,30 @@ public String getFormattedResult(final boolean HAS_COLORS) {
242238
gson = new GsonBuilder().setPrettyPrinting().create();
243239
RESULTS = gson.fromJson(this.getJson(), LeetJsonItem[].class);
244240

245-
} catch (IllegalStateException | NullPointerException ex) {
246-
ex.printStackTrace();
247-
return "";
241+
} catch (IllegalStateException | NullPointerException | JsonSyntaxException ex) {
242+
Logger.getLogger(Leet.class.getName()).log(Level.SEVERE, null, ex);
243+
json = "{ \"data\": \"Unable to retrieve Torrent json data\" }";
244+
return json;
248245
}
249246

250247
String output = "";
248+
int count = 0;
251249

252250
if (HAS_COLORS) {
253251
for (LeetJsonItem result : RESULTS) {
254252
output += result.getColorString();
253+
count++;
254+
if(MAX_RESULTS <= count) {
255+
break;
256+
}
255257
}
256258
} else {
257259
for (LeetJsonItem result : RESULTS) {
258260
output += result.toString();
261+
count++;
262+
if(MAX_RESULTS <= count) {
263+
break;
264+
}
259265
}
260266
}
261267
return output;
@@ -291,9 +297,9 @@ public class LeetJsonItem {
291297

292298
public String date;
293299
public String href;
294-
public String leeches;
300+
public int leeches;
295301
public String name;
296-
public String seeds;
302+
public int seeds;
297303
public String size;
298304
public String user;
299305
// public String tinyurl = "https://not.implemented.yet";

0 commit comments

Comments
 (0)