Skip to content

Commit bda5de2

Browse files
committed
Version 5.2.1
1 parent 23cdcf0 commit bda5de2

File tree

8 files changed

+87
-85
lines changed

8 files changed

+87
-85
lines changed

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins{
99
id 'net.kyori.blossom' version '1.1.0'
1010
}
1111

12-
def ver = new Version(major: 5, minor: 2, revision: 0)
12+
def ver = new Version(major: 5, minor: 2, revision: 1)
1313

1414
group = "org.botblock"
1515
version = "$ver"

Diff for: src/main/java/org/botblock/javabotblockapi/BotBlockAPI.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.botblock.javabotblockapi;
1919

2020
import org.botblock.javabotblockapi.annotations.DeprecatedSince;
21+
import org.botblock.javabotblockapi.requests.CheckUtil;
2122
import org.botblock.javabotblockapi.requests.PostAction;
2223
import org.jetbrains.annotations.NotNull;
2324

@@ -104,8 +105,7 @@ public Builder(){}
104105
* @since 2.1.0
105106
*/
106107
public Builder addAuthToken(@NotNull Site site, @NotNull String token){
107-
if(token.isEmpty())
108-
throw new NullPointerException("Token may not be null.");
108+
CheckUtil.notEmpty(token, "Token");
109109

110110
tokens.put(site.getSite(), token);
111111

@@ -129,9 +129,9 @@ public Builder addAuthToken(@NotNull Site site, @NotNull String token){
129129
* @return The Builder after the site and token were set. Useful for chaining.
130130
*/
131131
public Builder addAuthToken(@NotNull String site, @NotNull String token){
132-
if(site.isEmpty() || token.isEmpty())
133-
throw new NullPointerException("Site and/or token may not be null.");
134-
132+
CheckUtil.notEmpty(site, "Site");
133+
CheckUtil.notEmpty(token, "Token");
134+
135135
tokens.put(site, token);
136136

137137
return this;
@@ -150,8 +150,7 @@ public Builder addAuthToken(@NotNull String site, @NotNull String token){
150150
* @return The Builder after the Map was set. Useful for chaining.
151151
*/
152152
public Builder setAuthTokens(@NotNull Map<String, String> tokens){
153-
if(tokens.isEmpty())
154-
throw new NullPointerException("Tokens may not be empty.");
153+
CheckUtil.notEmpty(tokens, "Tokens");
155154

156155
this.tokens = tokens;
157156

@@ -165,14 +164,13 @@ public Builder setAuthTokens(@NotNull Map<String, String> tokens){
165164
* @param updateDelay
166165
* The update interval in minutes that should be used. This can't be less than 2.
167166
*
168-
* @throws java.lang.IllegalArgumentException
167+
* @throws java.lang.IllegalStateException
169168
* When the updateInterval is less than 2.
170169
*
171170
* @return The Builder after the updateInterval was set. Useful for chaining.
172171
*/
173172
public Builder setUpdateDelay(@NotNull Integer updateDelay){
174-
if(updateDelay < 2)
175-
throw new IllegalArgumentException("Update interval may not be less than 2.");
173+
CheckUtil.condition(updateDelay < 2, "UpdateDelay may not be less than 2.");
176174

177175
this.updateDelay = updateDelay;
178176

@@ -181,10 +179,15 @@ public Builder setUpdateDelay(@NotNull Integer updateDelay){
181179

182180
/**
183181
* Builds the instance of {@link org.botblock.javabotblockapi.BotBlockAPI BotBlockAPI}.
182+
*
183+
* @throws java.lang.NullPointerException
184+
* When the Tokens Map is empty.
184185
*
185186
* @return The built, usable {@link org.botblock.javabotblockapi.BotBlockAPI BotBlockAPI}.
186187
*/
187188
public BotBlockAPI build(){
189+
CheckUtil.notEmpty(tokens, "Tokens");
190+
188191
return new BotBlockAPI(tokens, updateDelay);
189192
}
190193
}

Diff for: src/main/java/org/botblock/javabotblockapi/Site.java

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public enum Site {
9898
*/
9999
DISCORDLIST_CO("discordlist.co"),
100100

101+
/**
102+
* <a href="https://discordlistology.com" target="_blank">discordlistology.com</a>
103+
*
104+
* @since 5.2.1
105+
*/
106+
DISCORDLISTOLOGY_COM("discordlistology.com"),
107+
101108
/**
102109
* <a href="https://glennbotlist.xyz" target="_blank">glennbotlist.xyz</a>
103110
*/
@@ -113,6 +120,13 @@ public enum Site {
113120
*/
114121
SPACE_BOT_LIST_ORG("space-bot-list.org"),
115122

123+
/**
124+
* <a href="https://vultrex.io" target="_blank">vultrex.io</a>
125+
*
126+
* @since 5.2.1
127+
*/
128+
VULTREX_IO("vultrex.io"),
129+
116130
/**
117131
* <a href="https://wonderbotlist.com" target="_blank">wonderbotlist.com</a>
118132
*/

Diff for: src/main/java/org/botblock/javabotblockapi/exceptions/RatelimitedException.java

+20-19
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
import org.json.JSONObject;
2121

2222
/**
23-
* Class used to indicate when the bot gets Ratelimited by the BotBlock API.
24-
* <br>You can use {@link #getDelay() getDelay()} to find out how long you have to wait before you can access
25-
* {@link #getRoute() the route} again.
23+
* Indicates that the Wrapper got rate limited by the BotBlock API.
24+
* <br>Use {@link #getDelay() getDelay()} to find out how long you have to wait until you can perform another request
25+
* towards {@link #getRoute() the targeted route}.
2626
*/
2727
public class RatelimitedException extends RuntimeException{
28-
private int delay;
29-
private String botId;
30-
private String ip;
31-
private String route;
28+
private final int delay;
29+
private final String botId;
30+
private final String ip;
31+
private final String route;
3232

3333
public RatelimitedException(String response){
3434
JSONObject json = new JSONObject(response);
@@ -49,27 +49,27 @@ public int getDelay(){
4949
}
5050

5151
/**
52-
* Returns the bot id that was ratelimited.
52+
* Returns the bot id that was rate limited.
5353
*
54-
* @return The id of the bot that was ratelimited
54+
* @return The id of the bot that was rate limited
5555
*/
5656
public String getBotId(){
5757
return botId;
5858
}
5959

6060
/**
61-
* Returns the ip that was ratelimited.
61+
* Returns the ip that was rate limited.
6262
*
63-
* @return The ip that was ratelimited
63+
* @return The ip that was rate limited
6464
*/
6565
public String getIp(){
6666
return ip;
6767
}
6868

6969
/**
70-
* Returns the route on which the bot was ratelimited.
70+
* Returns the route on which the bot was rate limited.
7171
*
72-
* @return The route on which the bot was ratelimited
72+
* @return The route on which the bot was rate limited
7373
*/
7474
public String getRoute(){
7575
return route;
@@ -82,18 +82,19 @@ public String getRoute(){
8282
*/
8383
@Override
8484
public String toString(){
85-
return "RatelimitedException{delay=" + delay
86-
+ ", botId=" + botId
87-
+ ", ip=" + ip
88-
+ ", route=" + route
85+
return "RatelimitedException{"
86+
+ "delay=" + delay + ", "
87+
+ "botId=" + botId + ", "
88+
+ "ip=" + ip + ", "
89+
+ "route=" + route + ", "
8990
+ "}";
9091
}
9192

9293
/**
9394
* Returns a formatted message displaying the various information returned in this exception.
94-
* <br>This essentially calls {@link #toString() toString()} in this class.
95+
* <br>This essentially returns the same value as {@link #toString() toString()} does.
9596
*
96-
* @return Same output as {@link #toString() toString()}
97+
* @return Formatted String containing the provided information from the response. Same format as {@link #toString() toString()}.
9798
*/
9899
@Override
99100
public String getMessage(){

Diff for: src/main/java/org/botblock/javabotblockapi/requests/CheckUtil.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@
1818

1919
package org.botblock.javabotblockapi.requests;
2020

21-
class CheckUtil{
21+
import java.util.Map;
22+
23+
public class CheckUtil{
2224

2325
public static void notEmpty(String value, String name){
2426
if(value.isEmpty())
2527
throw new NullPointerException(name + " may not be empty.");
2628
}
2729

30+
public static void notEmpty(Map<?, ?> value, String name){
31+
if(value.isEmpty())
32+
throw new NullPointerException(name + " may not be empty.");
33+
}
34+
35+
public static void condition(boolean check, String message){
36+
if(check)
37+
throw new IllegalStateException(message);
38+
}
39+
2840
}

Diff for: src/main/java/org/botblock/javabotblockapi/requests/GetBotAction.java

+2-40
Original file line numberDiff line numberDiff line change
@@ -398,44 +398,6 @@ public String getGitHub(@NotNull String id){
398398
return json.getString("github");
399399
}
400400

401-
/**
402-
* Gets the OAuth invite of the bot.
403-
* <br>The invite is based on the most common appearance of it.
404-
*
405-
* @param id
406-
* The id of the bot to get the OAuth link from.
407-
*
408-
* @return Possibly-empty String containing the OAuth invite for the bot.
409-
*
410-
* @deprecated Replaced with {@link #getOAuthInvite(Long) getOAuthInvite(Long)} to be more clear.
411-
*/
412-
@Deprecated
413-
@DeprecatedSince(version = "5.2.0", replacements = {"#getOAuthInvite(Long)"})
414-
public String getInvite(@NotNull Long id){
415-
JSONObject json = REQUEST_HANDLER.performGetBot(Long.toString(id), disableCache);
416-
417-
return json.getString("invite");
418-
}
419-
420-
/**
421-
* Gets the OAuth invite of the bot.
422-
* <br>The invite is based on the most common appearance of it.
423-
*
424-
* @param id
425-
* The id of the bot to get the OAuth link from.
426-
*
427-
* @return Possibly-empty String containing the OAuth invite for the bot.
428-
*
429-
* @deprecated Replaced with {@link #getOAuthInvite(String) getOAuthInvite(String)} to be more clear.
430-
*/
431-
@Deprecated
432-
@DeprecatedSince(version = "5.2.0", replacements = {"#getOAuthInvite(String)"})
433-
public String getInvite(@NotNull String id){
434-
JSONObject json = REQUEST_HANDLER.performGetBot(id, disableCache);
435-
436-
return json.getString("invite");
437-
}
438-
439401
/**
440402
* Gets the currently used library of the bot.
441403
* <br>The library is based on the most common appearance of it.
@@ -513,7 +475,7 @@ public String getName(@NotNull String id){
513475
*
514476
* @return Possibly-empty String containing the OAuth link for the bot.
515477
*
516-
* @since 5.2.0
478+
* @since 5.1.13
517479
*/
518480
public String getOAuthInvite(@NotNull Long id){
519481
JSONObject json = REQUEST_HANDLER.performGetBot(String.valueOf(id), disableCache);
@@ -530,7 +492,7 @@ public String getOAuthInvite(@NotNull Long id){
530492
*
531493
* @return Possibly-empty String containing the OAuth link for the bot.
532494
*
533-
* @since 5.2.0
495+
* @since 5.1.13
534496
*/
535497
public String getOAuthInvite(@NotNull String id){
536498
JSONObject json = REQUEST_HANDLER.performGetBot(id, disableCache);

Diff for: src/main/java/org/botblock/javabotblockapi/requests/RequestHandler.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import org.json.JSONObject;
3030

3131
import java.io.IOException;
32-
import java.util.ArrayList;
33-
import java.util.List;
3432
import java.util.concurrent.TimeUnit;
3533

3634
class RequestHandler{
@@ -136,8 +134,7 @@ private JSONObject performGET(@NotNull String url, String header) throws IOExcep
136134
}
137135

138136
void performPOST(@NotNull JSONObject json, int sites) throws IOException{
139-
if(sites < 1)
140-
throw new IllegalStateException("POST action requires at least one site!");
137+
CheckUtil.condition(sites < 1, "The POST action requires at least 1 site!");
141138

142139
String url = BASE_URL + "count";
143140
final long timeout = sites * 10;
@@ -179,27 +176,30 @@ void performPOST(@NotNull JSONObject json, int sites) throws IOException{
179176
JSONObject responseJson = new JSONObject(responseBody);
180177
if(responseJson.has("failure")){
181178
JSONObject failure = responseJson.getJSONObject("failure");
182-
List<String> failedSites = new ArrayList<>();
179+
JSONArray failures = new JSONArray();
183180

184181
for(String key : failure.keySet()){
185182
try{
186183
JSONArray array = failure.getJSONArray(key);
187-
failedSites.add(String.format(
188-
"%s{code=%d, message=%s}",
189-
key,
190-
array.getInt(0),
191-
array.getString(1)
192-
));
184+
failures.put(getJson(key, array));
193185
}catch(JSONException ex){
194-
failedSites.add("unknown{}");
186+
failures.put(getJson(key, null));
195187
}
196188
}
197189

198190
throw new IOException(String.format(
199-
"One or multiple post requests failed! Response(s): failed{[%s]}",
200-
String.join(", ", failedSites)
191+
"One or multiple post requests failed! Response(s): failed{%s}",
192+
failures.toString()
201193
));
202194
}
203195
}
204196
}
197+
198+
private JSONObject getJson(String key, JSONArray array){
199+
JSONObject json = new JSONObject()
200+
.put("code", array == null ? "?" : array.get(0))
201+
.put("message", array == null ? "?" : array.get(1));
202+
203+
return new JSONObject().put(key, json);
204+
}
205205
}

Diff for: wiki/docs/wiki/changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ This page lists all versions of JavaBotBlockAPI and the changes being made.
1111
Split up the different `GET` actions into bot and list related actions.
1212
Many new `GET` actions added for list related stuff.
1313

14+
### 5.2.1
15+
- Site updated:
16+
- Added [`DISCORDLISTOLOGY_COM`](https://discordlistology.com)
17+
- Added [`VULTREX_IO`](https://vultrex.io)
18+
- Dependencies updated:
19+
- JDA: `4.1.1_156` to `4.1.1_165`
20+
- Improved Javadoc
21+
- Removed deprecated `getInvite` methods from `GetBotAction`
22+
- Make the RequestHandler return proper JSON on (partially) failed POST
23+
1424
### 5.2.0
1525

1626
!!! warning "Important"

0 commit comments

Comments
 (0)