From b044fed2861942a8033a4695ead7b32436cb22dd Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Fri, 28 Jun 2019 20:42:23 +0200 Subject: [PATCH 01/11] Update to JDA V4 --- build.gradle | 2 +- .../andre601/javabotblockapi/BotBlockAPI.java | 21 +++++++- .../javabotblockapi/RequestHandler.java | 54 +++++++++++-------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index b95ddcf..8d6063e 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ dependencies{ implementation group: 'org.json', name: 'json', version: '20180813' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2' - api(group: 'net.dv8tion', name: 'JDA', version: '3.8.3_463'){ + api(group: 'net.dv8tion', name: 'JDA', version: '4.BETA.0_11'){ exclude(module: 'opus-java') } } diff --git a/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java b/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java index 1e1010c..873e7a1 100644 --- a/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java +++ b/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java @@ -29,14 +29,30 @@ * {@link com.andre601.javabotblockapi.RequestHandler RequestHandler}. */ public class BotBlockAPI{ + private static final int DEFAULT_DELAY = 30; + private Map authTokens; private int updateInterval; + /** + * Constructor to set the Map with the sites and tokens. + *
This will also set the update interval to 30 minutes. + * + * @param authTokens + * A Map of sites and their tokens. May not be null. + *
You may receive the API-token from your botlist. + */ + public BotBlockAPI(@NotNull Map authTokens){ + this.authTokens = authTokens; + this.updateInterval = DEFAULT_DELAY; + } + /** * Creates an instance of BotBlockAPI with the provided api tokens (as Map) and update interval. * * @param authTokens * A Map of sites and their tokens. May not be null. + *
You may receive the API-token from your botlist. * @param updateInterval * The update interval to set. */ @@ -58,7 +74,7 @@ int getUpdateInterval(){ */ public static class Builder{ private Map authTokens = new HashMap<>(); - private int updateInterval = 30; + private int updateInterval = DEFAULT_DELAY; /** * Empty constructor to get the class. @@ -67,13 +83,14 @@ public Builder(){} /** * Adds the provided Site name and token to the Map. - *
If there is already an entry with the same key, it will be overwritten. + *
Entries with the same key will be overwritten. * * @param site * The name of the site. May not be null. *
A list of supported sites can be found here. * @param token * The API token you get from the corresponding botlist. May not be null. + *
You may receive the API-token from your botlist. * * @throws NullPointerException * When either the site or token are empty ({@code ""}). diff --git a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java index cdc4fbd..b425687 100644 --- a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java +++ b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java @@ -19,12 +19,13 @@ package com.andre601.javabotblockapi; import com.andre601.javabotblockapi.exceptions.RatelimitedException; -import net.dv8tion.jda.bot.sharding.ShardManager; -import net.dv8tion.jda.core.JDA; +import net.dv8tion.jda.api.sharding.ShardManager; +import net.dv8tion.jda.api.JDA; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.commons.lang3.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; @@ -53,10 +54,10 @@ public class RequestHandler { public RequestHandler(){} /** - * Posts guilds from the provided {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager}. + * Posts guilds from the provided {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager}. * * @param shardManager - * The {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager instance} that should be used. + * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. * @@ -64,11 +65,13 @@ public RequestHandler(){} * When the post request couldn't be performed properly. * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. + * @throws NullPointerException + * When the ShardManager gives an invalid shard (Shard id 0 is null). * * @see #postGuilds(JDA, BotBlockAPI) postGuilds(JDA, BotBlockAPI) for posting with JDA. */ public void postGuilds(@NotNull ShardManager shardManager, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ - this.id = shardManager.getShardById(0).getSelfUser().getId(); + this.id = Objects.requireNonNull(shardManager.getShardById(0), "The provided ShardManager had an invalid Shard ID.").getSelfUser().getId(); json.put("server_count", shardManager.getGuilds().size()) .put("bot_id", id) @@ -82,17 +85,18 @@ public void postGuilds(@NotNull ShardManager shardManager, @NotNull BotBlockAPI botBlockAPI.getAuthTokens().forEach(json::put); - performRequest(); + postRequest(); } /** - * Posts the guilds from the provided {@link net.dv8tion.jda.core.JDA JDA}. - *
If the Bot is sharded (JDA has ShardInfo) then the {@code shard_id} and {@code shard_count} are posted too. + * Posts the guilds from the provided {@link net.dv8tion.jda.api.JDA JDA}. + *
If the bot is part of sharding and the shard count is bigger than 1, then {@code shard_id} and + * {@code shard_count} are added too. Those values are not supported by all sites! * *

If you use this on a sharded bot, better use {@link #postGuilds(ShardManager, BotBlockAPI)}. * * @param jda - * The {@link net.dv8tion.jda.core.JDA JDA instance} that should be used. + * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. * @@ -109,13 +113,13 @@ public void postGuilds(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI) throw json.put("server_count", jda.getGuildCache().size()) .put("bot_id", id); - if(jda.getShardInfo() != null) + if(jda.getShardInfo().getShardTotal() > 1) json.put("shard_id", jda.getShardInfo().getShardId()) .put("shard_count", jda.getShardInfo().getShardTotal()); botBlockAPI.getAuthTokens().forEach(json::put); - performRequest(); + postRequest(); } /** @@ -161,20 +165,25 @@ public void postGuilds(Long botId, int guilds, @NotNull BotBlockAPI botBlockAPI) * @see #postGuilds(JDA, BotBlockAPI) postGuilds(JDA, BotBlockAPI) for posting with JDA. */ public void postGuilds(@NotNull String botId, int guilds, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ + if(ObjectUtils.isEmpty(botId)) + throw new NullPointerException("botId may not be empty!"); + + this.id = botId; + json.put("server_count", guilds) .put("bot_id", botId); botBlockAPI.getAuthTokens().forEach(json::put); - performRequest(); + postRequest(); } /** - * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager} + * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} * every X minutes. * * @param shardManager - * The {@link net.dv8tion.jda.bot.sharding.ShardManager ShardManager instance} that should be used. + * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. * @@ -191,11 +200,11 @@ public void startAutoPosting(@NotNull ShardManager shardManager, @NotNull BotBlo } /** - * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.core.JDA JDA} + * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.api.JDA JDA} * every X minutes. * * @param jda - * The {@link net.dv8tion.jda.core.JDA JDA instance} that should be used. + * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. * @@ -258,16 +267,19 @@ public void startAutoPosting(@NotNull String botId, int guilds, @NotNull BotBloc } /** - * Shuts down the scheduler. + * Stops the auto-posting by shutting down the scheduler. */ public void stopAutoPosting(){ scheduler.shutdown(); } - private void performRequest() throws IOException, RatelimitedException{ + private void postRequest() throws IOException, RatelimitedException{ Objects.requireNonNull(json, "JSON may not be null."); Objects.requireNonNull(id, "Id may not be null."); + if(ObjectUtils.isEmpty(id)) + throw new NullPointerException("botId may not be empty!"); + RequestBody body = RequestBody.create(null, json.toString()); Request request = new Request.Builder() .url("https://botblock.org/api/count") @@ -298,8 +310,8 @@ private void performRequest() throws IOException, RatelimitedException{ JSONObject failure = json.getJSONObject("failure"); List sites = new ArrayList<>(); - for (String key : failure.keySet()) { - try { + for(String key : failure.keySet()){ + try{ JSONArray array = failure.getJSONArray(key); sites.add(String.format( "Name: %s, Error code: %d, Error Message: %s", @@ -307,7 +319,7 @@ private void performRequest() throws IOException, RatelimitedException{ array.getInt(0), array.getString(1) )); - } catch (JSONException ex) { + }catch (JSONException ex){ Map notFound = failure.toMap(); sites.add("Errors: " + notFound.toString()); } From 82d2bf641d6ec85901e839c6e19bbbd379b78409 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sat, 29 Jun 2019 01:45:47 +0200 Subject: [PATCH 02/11] Add get-methods for (certain) bot info. --- .../javabotblockapi/RequestHandler.java | 360 ++++++++++++++++-- 1 file changed, 338 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java index b425687..45423a2 100644 --- a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java +++ b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java @@ -44,6 +44,8 @@ public class RequestHandler { private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final OkHttpClient CLIENT = new OkHttpClient(); + private String baseUrl = "https://botblock.org/api/"; + private String id = null; private JSONObject json = new JSONObject(); @@ -67,8 +69,6 @@ public RequestHandler(){} * When the Bot (IP or ID) got ratelimited. * @throws NullPointerException * When the ShardManager gives an invalid shard (Shard id 0 is null). - * - * @see #postGuilds(JDA, BotBlockAPI) postGuilds(JDA, BotBlockAPI) for posting with JDA. */ public void postGuilds(@NotNull ShardManager shardManager, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ this.id = Objects.requireNonNull(shardManager.getShardById(0), "The provided ShardManager had an invalid Shard ID.").getSelfUser().getId(); @@ -104,8 +104,6 @@ public void postGuilds(@NotNull ShardManager shardManager, @NotNull BotBlockAPI * When the post request couldn't be performed properly. * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. - * - * @see #postGuilds(ShardManager, BotBlockAPI) postGuilds(ShardManager, BotBlockAPI) for posting with ShardManager. */ public void postGuilds(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ this.id = jda.getSelfUser().getId(); @@ -137,10 +135,6 @@ public void postGuilds(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI) throw * When the post request couldn't be performed properly. * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. - * - * @see #postGuilds(String, int, BotBlockAPI) postGuilds(String, int, BotBlockAPI) for the full method. - * @see #postGuilds(ShardManager, BotBlockAPI) postGuilds(ShardManager, BotBlockAPI) for posting with ShardManager. - * @see #postGuilds(JDA, BotBlockAPI) postGuilds(JDA, BotBlockAPI) for posting with JDA. */ public void postGuilds(Long botId, int guilds, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ postGuilds(Long.toString(botId), guilds, botBlockAPI); @@ -160,9 +154,6 @@ public void postGuilds(Long botId, int guilds, @NotNull BotBlockAPI botBlockAPI) * When the post request couldn't be performed properly. * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. - * - * @see #postGuilds(ShardManager, BotBlockAPI) postGuilds(ShardManager, BotBlockAPI) for posting with ShardManager. - * @see #postGuilds(JDA, BotBlockAPI) postGuilds(JDA, BotBlockAPI) for posting with JDA. */ public void postGuilds(@NotNull String botId, int guilds, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ if(ObjectUtils.isEmpty(botId)) @@ -186,8 +177,6 @@ public void postGuilds(@NotNull String botId, int guilds, @NotNull BotBlockAPI b * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. - * - * @see #startAutoPosting(JDA, BotBlockAPI) startAutoPosting(JDA, BotBlockAPI) for posting with JDA. */ public void startAutoPosting(@NotNull ShardManager shardManager, @NotNull BotBlockAPI botBlockAPI){ scheduler.scheduleAtFixedRate(() -> { @@ -207,8 +196,6 @@ public void startAutoPosting(@NotNull ShardManager shardManager, @NotNull BotBlo * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. - * - * @see #startAutoPosting(ShardManager, BotBlockAPI) startAutoPosting(ShardManager, BotBlockAPI) for posting with ShardManager. */ public void startAutoPosting(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI){ scheduler.scheduleAtFixedRate(() -> { @@ -229,9 +216,6 @@ public void startAutoPosting(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI) * The guilds the bot is in. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. - * - * @see #startAutoPosting(JDA, BotBlockAPI) startAutoPosting(JDA, BotBlockAPI) for posting with JDA. - * @see #startAutoPosting(ShardManager, BotBlockAPI) startAutoPosting(ShardManager, BotBlockAPI) for posting with ShardManager. */ public void startAutoPosting(Long botId, int guilds, @NotNull BotBlockAPI botBlockAPI){ scheduler.scheduleAtFixedRate(() -> { @@ -252,9 +236,6 @@ public void startAutoPosting(Long botId, int guilds, @NotNull BotBlockAPI botBlo * The guilds the bot is in. * @param botBlockAPI * The {@link com.andre601.javabotblockapi.BotBlockAPI BotBlockAPI instance} that should be used. - * - * @see #startAutoPosting(JDA, BotBlockAPI) startAutoPosting(JDA, BotBlockAPI) for posting with JDA. - * @see #startAutoPosting(ShardManager, BotBlockAPI) startAutoPosting(ShardManager, BotBlockAPI) for posting with ShardManager. */ public void startAutoPosting(@NotNull String botId, int guilds, @NotNull BotBlockAPI botBlockAPI){ scheduler.scheduleAtFixedRate(() -> { @@ -280,9 +261,11 @@ private void postRequest() throws IOException, RatelimitedException{ if(ObjectUtils.isEmpty(id)) throw new NullPointerException("botId may not be empty!"); + String url = baseUrl + "count"; + RequestBody body = RequestBody.create(null, json.toString()); Request request = new Request.Builder() - .url("https://botblock.org/api/count") + .url(url) .addHeader("User-Agent", id) .addHeader("Content-Type", "application/json") // Some sites require this in the header. .post(body) @@ -332,4 +315,337 @@ private void postRequest() throws IOException, RatelimitedException{ } } } + + /** + * Gets the owners of a bot as a list. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. + * + * @param shardManager + * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. + * + * @return The owners as a list. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getOwners(String) getOwners(String) + */ + public List getOwners(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ + return getOwners(shardManager.getShardById(0).getSelfUser().getId()); + } + + + /** + * Gets the owners of a bot as a list. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. + * + * @param jda + * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. + * + * @return The owners as a list. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getOwners(String) getOwners(String) + */ + public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedException{ + return getOwners(jda.getSelfUser().getId()); + } + + /** + * Gets the owners of a bot as a List. + * + * @param id + * The ID of the bot to get information from. + * + * @return The owners as a list. + * + * @throws IOException + * When the post request couldn't be performed properly. + * @throws RatelimitedException + * When the Bot (IP or ID) got ratelimited. + */ + public List getOwners(@NotNull String id) throws IOException, RatelimitedException{ + JSONObject json = getAll(id); + + JSONArray array = json.getJSONArray("owners"); + + List owners = new ArrayList<>(); + for(int i = 0; i < array.length(); i++) + owners.add(array.getString(0)); + + return owners; + } + + /** + * Gets all the available Botlists as JSONObject. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + * + *

The JSONObject will look something like this: + *

{@code
+     * {
+     *   "somebotlist.com": [
+     *     ,
+     *     200
+     *   ],
+     *   "otherlist.org": [
+     *     ,
+     *     404
+     *   ]
+     * }
+     * }
+ * + * @param shardManager + * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. + * + * @return The Botlists as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getBotlists(String) getBotlists(String) + */ + public JSONObject getBotlists(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ + return getBotlists(shardManager.getShardById(0).getSelfUser().getId()); + } + + + /** + * Gets all the available Botlists as JSONObject. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + * + *

The JSONObject will look something like this: + *

{@code
+     * {
+     *   "somebotlist.com": [
+     *     ,
+     *     200
+     *   ],
+     *   "otherlist.org": [
+     *     ,
+     *     404
+     *   ]
+     * }
+     * }
+ * + * @param jda + * The {@link net.dv8tion.jda.api.JDA jda instance} that should be used. + * + * @return The Botlists as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getBotlists(String) getBotlists(String) + */ + public JSONObject getBotlists(@NotNull JDA jda) throws IOException, RatelimitedException{ + return getBotlists(jda.getSelfUser().getId()); + } + + + /** + * Gets all the available Botlists as JSONObject. + * + *

The JSONObject will look something like this: + *

{@code
+     * {
+     *   "somebotlist.com": [
+     *     ,
+     *     200
+     *   ],
+     *   "otherlist.org": [
+     *     ,
+     *     404
+     *   ]
+     * }
+     * }
+ * + * @param id + * The id of the bot + * + * @return The Botlists as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + */ + public JSONObject getBotlists(@NotNull String id) throws IOException, RatelimitedException{ + return getAll(id).getJSONObject("list_data"); + } + + /** + * Gets a specific botlist-information as JSONArray. + * + *

The JSONObject will look something like this: + *

{@code
+     * {[
+     *   ,
+     *   200
+     * ]}
+     * }
+ * + * @param shardManager + * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. + * @param site + * The sites name to get information from. + *
A list of supported sites can be found here. + * + * @return The sites information as JSONArray. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONArray getBotlist(@NotNull ShardManager shardManager, @NotNull String site) throws IOException, RatelimitedException{ + return getBotlist(shardManager.getShardById(0).getSelfUser().getId(), site); + } + + /** + * Gets a specific botlist-information as JSONArray. + * + *

The JSONObject will look something like this: + *

{@code
+     * {[
+     *   ,
+     *   200
+     * ]}
+     * }
+ * + * @param jda + * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. + * @param site + * The sites name to get information from. + *
A list of supported sites can be found here. + * + * @return The sites information as JSONArray. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, RatelimitedException{ + return getBotlist(jda.getSelfUser().getId(), site); + } + + /** + * Gets a specific botlist-information as JSONArray. + * + *

The JSONObject will look something like this: + *

{@code
+     * {[
+     *   ,
+     *   200
+     * ]}
+     * }
+ * + * @param id + * The id of the bot. + * @param site + * The sites name to get information from. + *
A list of supported sites can be found here. + * + * @return The sites information as JSONArray. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + */ + public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOException, RatelimitedException{ + return getAll(id).getJSONObject("list_data").getJSONArray(site); + } + + /** + * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(ShardManager) owners}, + * server_count and OAuth-link but also all sites and corresponding informations of those. + *
With exception of id and the sites are the other informations based on the most common response. + * + *

A response could look like this: + *

{@code
+     * {
+     *     "id": "123456789012345678",
+     *     "usernam": "MyBot",
+     *     "discriminator": "1234",
+     *     "owners": [
+     *         "234567890123456789"
+     *     ],
+     *     "server_count": 100,
+     *     "invite": "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot",
+     *     "list_data": {
+     *         "somebotlist.com": [
+     *             ,
+     *             200
+     *         ],
+     *         "otherlist.org": [
+     *             ,
+     *             404
+     *         ]
+     *     }
+     * }
+     * }
+ * + * @param id + * The id of the bot. + * + * @return The Bot information as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @see #getOwners(ShardManager) getOwners(ShardManager) + * @see #getOwners(JDA) getOwners(JDA) + * @see #getOwners(String) getOwners(String) + * @see #getBotlists(ShardManager) getBotlists(ShardManager) + * @see #getBotlists(JDA) getBotlists(JDA) + * @see #getBotlists(String) getBotlists(String) + * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String) + * @see #getBotlist(JDA, String) getBotlist(JDA, String) + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONObject getAll(@NotNull String id) throws IOException, RatelimitedException{ + String url = baseUrl + "bots/" + id; + + Request request = new Request.Builder() + .url(url) + .addHeader("User-Agent", id) + .build(); + + try(Response response = CLIENT.newCall(request).execute()){ + Objects.requireNonNull(response.body(), "Received empty body from BotBlocks API."); + + if(response.body().string().isEmpty()) + throw new NullPointerException("Received empty body from BotBlocks API."); + + if(!response.isSuccessful()){ + if(response.code() == 429) + throw new RatelimitedException(response.body().string()); + + throw new IOException(String.format( + "Couldn't get Bot information. Site responded with %d (%s)", + response.code(), + response.message() + )); + } + + return new JSONObject(response.body().string()); + } + } } From b97ded8e3452d5bfb7fff3d9c4477e9b783f182a Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sat, 29 Jun 2019 18:05:26 +0200 Subject: [PATCH 03/11] Add missing methods and bump version to 1.1.0 --- README.md | 46 +++ build.gradle | 2 +- .../javabotblockapi/RequestHandler.java | 340 ++++++++++++++++-- 3 files changed, 360 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 314604b..6171d7f 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,52 @@ RequestHandler handler = new RequestHandler(); handler.postGuilds(jda, api); ``` +### Getting botinfo +JavaBotBlockAPI allows you to receive informations. +There aren't that many methods to use due to the nature of the sites returning different informations. + +#### Receive full JSON +You can use the `getAll(...)` method to receive the full JSON of the BotBlock API. +```java +// We need to get an instance of RequestHandler to use the methods. +RequestHandler handler = new RequestHandler(); + +// Like with all other methods can you use JDA, ShardManager or ID. +JSONObject json = handler.getAll(jda); +``` + +#### Receive Owners +You can use `getOwners(...)` to receive a List of all owners of the bot. +```java +// We need to get an instance of RequestHandler to use the methods. +RequestHandler handler = new RequestHandler(); + +// Like with all other methods can you use JDA, ShardManager or ID. +List owners = handler.getOwners(jda); +``` + +#### Receive all botlists. +If you only want the Botlists and their information, use `getBotlists(...)`. +It is returned as a JSONObject. +```java +// We need to get an instance of RequestHandler to use the methods. +RequestHandler handler = new RequestHandler(); + +// Like with all other methods can you use JDA, ShardManager or ID. +JSONObject json = handler.getBotlists(jda); +``` + +#### Receive certain Botlist info +You can use `getBotlist(..., String)` to get the information of a specific botlist. +The information you receive is given as JSONArray and depends on what the botlist returns. +```java +// We need to get an instance of RequestHandler to use the methods. +RequestHandler handler = new RequestHandler(); + +// Like with all other methods can you use JDA, ShardManager or ID. +JSONArray array = handler.getBotlist(jda, "lbots.org"); +``` + ### Exceptions When you post the guild counts you could encounter certain Exceptions. You can receive the following exceptions: diff --git a/build.gradle b/build.gradle index 8d6063e..ca4f109 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins{ } group = 'com.andre601' -version = '1.0.5' +version = '1.1.0' sourceCompatibility = 1.8 diff --git a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java index 45423a2..405194a 100644 --- a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java +++ b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java @@ -330,6 +330,8 @@ private void postRequest() throws IOException, RatelimitedException{ * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getOwners(String) getOwners(String) */ public List getOwners(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ @@ -351,12 +353,36 @@ public List getOwners(@NotNull ShardManager shardManager) throws IOExcep * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getOwners(String) getOwners(String) */ public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedException{ return getOwners(jda.getSelfUser().getId()); } + /** + * Gets the owners of a bot as a list. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. + * + * @param id + * The id of the bot. + * + * @return The owners as a list. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getOwners(String) getOwners(String) + */ + public List getOwners(Long id) throws IOException, RatelimitedException{ + return getOwners(Long.toString(id)); + } + /** * Gets the owners of a bot as a List. * @@ -369,6 +395,8 @@ public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedE * When the post request couldn't be performed properly. * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. + * + * @since v1.1.0 */ public List getOwners(@NotNull String id) throws IOException, RatelimitedException{ JSONObject json = getAll(id); @@ -387,18 +415,18 @@ public List getOwners(@NotNull String id) throws IOException, Ratelimite *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. * *

The JSONObject will look something like this: - *

{@code
+     * 

      * {
      *   "somebotlist.com": [
-     *     ,
+     *    {@literal },
      *     200
      *   ],
      *   "otherlist.org": [
-     *     ,
+     *    {@literal },
      *     404
      *   ]
      * }
-     * }
+ *
* * @param shardManager * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. @@ -410,30 +438,31 @@ public List getOwners(@NotNull String id) throws IOException, Ratelimite * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getBotlists(String) getBotlists(String) */ public JSONObject getBotlists(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ return getBotlists(shardManager.getShardById(0).getSelfUser().getId()); } - /** * Gets all the available Botlists as JSONObject. *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. * *

The JSONObject will look something like this: - *

{@code
+     * 

      * {
      *   "somebotlist.com": [
-     *     ,
+     *    {@literal },
      *     200
      *   ],
      *   "otherlist.org": [
-     *     ,
+     *    {@literal },
      *     404
      *   ]
      * }
-     * }
+ *
* * @param jda * The {@link net.dv8tion.jda.api.JDA jda instance} that should be used. @@ -445,29 +474,66 @@ public JSONObject getBotlists(@NotNull ShardManager shardManager) throws IOExcep * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getBotlists(String) getBotlists(String) */ public JSONObject getBotlists(@NotNull JDA jda) throws IOException, RatelimitedException{ return getBotlists(jda.getSelfUser().getId()); } + /** + * Gets all the available Botlists as JSONObject. + *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + * + *

The JSONObject will look something like this: + *


+     * {
+     *   "somebotlist.com": [
+     *    {@literal },
+     *     200
+     *   ],
+     *   "otherlist.org": [
+     *    {@literal },
+     *     404
+     *   ]
+     * }
+     * 
+ * + * @param id + * The id of the bot. + * + * @return The Botlists as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getBotlists(String) getBotlists(String) + */ + public JSONObject getBotlists(Long id) throws IOException, RatelimitedException{ + return getBotlists(Long.toString(id)); + } /** * Gets all the available Botlists as JSONObject. * *

The JSONObject will look something like this: - *

{@code
+     * 

      * {
      *   "somebotlist.com": [
-     *     ,
+     *    {@literal },
      *     200
      *   ],
      *   "otherlist.org": [
-     *     ,
+     *    {@literal },
      *     404
      *   ]
      * }
-     * }
+ *
* * @param id * The id of the bot @@ -478,6 +544,8 @@ public JSONObject getBotlists(@NotNull JDA jda) throws IOException, RatelimitedE * When the request couldn't be performed properly. * @throws RatelimitedException * When the API gets ratelimited. + * + * @since v1.1.0 */ public JSONObject getBotlists(@NotNull String id) throws IOException, RatelimitedException{ return getAll(id).getJSONObject("list_data"); @@ -487,12 +555,12 @@ public JSONObject getBotlists(@NotNull String id) throws IOException, Ratelimite * Gets a specific botlist-information as JSONArray. * *

The JSONObject will look something like this: - *

{@code
+     * 

      * {[
-     *   ,
+     *  {@literal },
      *   200
      * ]}
-     * }
+ *
* * @param shardManager * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. @@ -517,12 +585,44 @@ public JSONArray getBotlist(@NotNull ShardManager shardManager, @NotNull String * Gets a specific botlist-information as JSONArray. * *

The JSONObject will look something like this: - *

{@code
+     * 

+     * {[
+     *  {@literal },
+     *   200
+     * ]}
+     * 
+ * + * @param id + * The id of the bot. + * @param site + * The sites name to get information from. + *
A list of supported sites can be found here. + * + * @return The sites information as JSONArray. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONArray getBotlist(Long id, @NotNull String site) throws IOException, RatelimitedException{ + return getBotlist(Long.toString(id), site); + } + + /** + * Gets a specific botlist-information as JSONArray. + * + *

The JSONObject will look something like this: + *


      * {[
-     *   ,
+     *  {@literal },
      *   200
      * ]}
-     * }
+ *
* * @param jda * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. @@ -537,6 +637,8 @@ public JSONArray getBotlist(@NotNull ShardManager shardManager, @NotNull String * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getBotlist(String, String) getBotlist(String, String) */ public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, RatelimitedException{ @@ -547,12 +649,12 @@ public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, R * Gets a specific botlist-information as JSONArray. * *

The JSONObject will look something like this: - *

{@code
+     * 

      * {[
-     *   ,
+     *  {@literal },
      *   200
      * ]}
-     * }
+ *
* * @param id * The id of the bot. @@ -566,6 +668,8 @@ public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, R * When the request couldn't be performed properly. * @throws RatelimitedException * When the API gets ratelimited. + * + * @since v1.1.0 */ public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOException, RatelimitedException{ return getAll(id).getJSONObject("list_data").getJSONArray(site); @@ -575,9 +679,10 @@ public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOE * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(ShardManager) owners}, * server_count and OAuth-link but also all sites and corresponding informations of those. *
With exception of id and the sites are the other informations based on the most common response. + *
This method directly calls {@link #getAll(String) getAll(String)}. * *

A response could look like this: - *

{@code
+     * 

      * {
      *     "id": "123456789012345678",
      *     "usernam": "MyBot",
@@ -586,19 +691,195 @@ public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOE
      *         "234567890123456789"
      *     ],
      *     "server_count": 100,
-     *     "invite": "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot",
+     *     "invite":{@literal "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot"},
      *     "list_data": {
      *         "somebotlist.com": [
-     *             ,
+     *            {@literal },
      *             200
      *         ],
      *         "otherlist.org": [
-     *             ,
+     *            {@literal },
      *             404
      *         ]
      *     }
      * }
-     * }
+ *
+ * + * @param shardManager + * The instance of {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} to use. + * + * @return The Bot information as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getOwners(ShardManager) getOwners(ShardManager) + * @see #getOwners(JDA) getOwners(JDA) + * @see #getOwners(Long) getOwners(Long) + * @see #getOwners(String) getOwners(String) + * @see #getBotlists(ShardManager) getBotlists(ShardManager) + * @see #getBotlists(JDA) getBotlists(JDA) + * @see #getBotlists(Long) getBotlists(Long) + * @see #getBotlists(String) getBotlists(String) + * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String) + * @see #getBotlist(JDA, String) getBotlist(JDA, String) + * @see #getBotlist(Long, String) getBotlist(Long, String) + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONObject getAll(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ + return getAll(shardManager.getShardById(0).getSelfUser().getId()); + } + + /** + * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(JDA) owners}, + * server_count and OAuth-link but also all sites and corresponding informations of those. + *
With exception of id and the sites are the other informations based on the most common response. + *
This method directly calls {@link #getAll(String) getAll(String)}. + * + *

A response could look like this: + *


+     * {
+     *     "id": "123456789012345678",
+     *     "usernam": "MyBot",
+     *     "discriminator": "1234",
+     *     "owners": [
+     *         "234567890123456789"
+     *     ],
+     *     "server_count": 100,
+     *     "invite":{@literal "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot"},
+     *     "list_data": {
+     *         "somebotlist.com": [
+     *            {@literal },
+     *             200
+     *         ],
+     *         "otherlist.org": [
+     *            {@literal },
+     *             404
+     *         ]
+     *     }
+     * }
+     * 
+ * + * @param jda + * The instance of {@link net.dv8tion.jda.api.JDA JDA} to use. + * + * @return The Bot information as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getOwners(ShardManager) getOwners(ShardManager) + * @see #getOwners(JDA) getOwners(JDA) + * @see #getOwners(Long) getOwners(Long) + * @see #getOwners(String) getOwners(String) + * @see #getBotlists(ShardManager) getBotlists(ShardManager) + * @see #getBotlists(JDA) getBotlists(JDA) + * @see #getBotlists(Long) getBotlists(Long) + * @see #getBotlists(String) getBotlists(String) + * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String) + * @see #getBotlist(JDA, String) getBotlist(JDA, String) + * @see #getBotlist(Long, String) getBotlist(Long, String) + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONObject getAll(@NotNull JDA jda) throws IOException, RatelimitedException{ + return getAll(jda.getSelfUser().getId()); + } + + /** + * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(Long) owners}, + * server_count and OAuth-link but also all sites and corresponding informations of those. + *
With exception of id and the sites are the other informations based on the most common response. + *
This method directly calls {@link #getAll(String) getAll(String)}. + * + *

A response could look like this: + *


+     * {
+     *     "id": "123456789012345678",
+     *     "usernam": "MyBot",
+     *     "discriminator": "1234",
+     *     "owners": [
+     *         "234567890123456789"
+     *     ],
+     *     "server_count": 100,
+     *     "invite":{@literal "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot"},
+     *     "list_data": {
+     *         "somebotlist.com": [
+     *            {@literal },
+     *             200
+     *         ],
+     *         "otherlist.org": [
+     *            {@literal },
+     *             404
+     *         ]
+     *     }
+     * }
+     * 
+ * + * @param id + * The id of the bot. + * + * @return The Bot information as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v1.1.0 + * + * @see #getOwners(ShardManager) getOwners(ShardManager) + * @see #getOwners(JDA) getOwners(JDA) + * @see #getOwners(Long) getOwners(Long) + * @see #getOwners(String) getOwners(String) + * @see #getBotlists(ShardManager) getBotlists(ShardManager) + * @see #getBotlists(JDA) getBotlists(JDA) + * @see #getBotlists(Long) getBotlists(Long) + * @see #getBotlists(String) getBotlists(String) + * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String) + * @see #getBotlist(JDA, String) getBotlist(JDA, String) + * @see #getBotlist(Long, String) getBotlist(Long, String) + * @see #getBotlist(String, String) getBotlist(String, String) + */ + public JSONObject getAll(Long id) throws IOException, RatelimitedException{ + return getAll(Long.toString(id)); + } + + /** + * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(String) owners}, + * server_count and OAuth-link but also all sites and corresponding informations of those. + *
With exception of id and the sites are the other informations based on the most common response. + * + *

A response could look like this: + *


+     * {
+     *     "id": "123456789012345678",
+     *     "usernam": "MyBot",
+     *     "discriminator": "1234",
+     *     "owners": [
+     *         "234567890123456789"
+     *     ],
+     *     "server_count": 100,
+     *     "invite":{@literal "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot"},
+     *     "list_data": {
+     *         "somebotlist.com": [
+     *            {@literal },
+     *             200
+     *         ],
+     *         "otherlist.org": [
+     *            {@literal },
+     *             404
+     *         ]
+     *     }
+     * }
+     * 
* * @param id * The id of the bot. @@ -610,14 +891,19 @@ public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOE * @throws RatelimitedException * When the API gets ratelimited. * + * @since v1.1.0 + * * @see #getOwners(ShardManager) getOwners(ShardManager) * @see #getOwners(JDA) getOwners(JDA) + * @see #getOwners(Long) getOwners(Long) * @see #getOwners(String) getOwners(String) * @see #getBotlists(ShardManager) getBotlists(ShardManager) * @see #getBotlists(JDA) getBotlists(JDA) + * @see #getBotlists(Long) getBotlists(Long) * @see #getBotlists(String) getBotlists(String) * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String) * @see #getBotlist(JDA, String) getBotlist(JDA, String) + * @see #getBotlist(Long, String) getBotlist(Long, String) * @see #getBotlist(String, String) getBotlist(String, String) */ public JSONObject getAll(@NotNull String id) throws IOException, RatelimitedException{ From 510b40ae512972d43f502fc59a012152b9979031 Mon Sep 17 00:00:00 2001 From: Andre_601 <11576465+Andre601@users.noreply.github.com> Date: Sat, 29 Jun 2019 18:09:35 +0200 Subject: [PATCH 04/11] Fix spelling and linebreaks --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6171d7f..cadd82e 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,11 @@ handler.postGuilds(jda, api); ``` ### Getting botinfo -JavaBotBlockAPI allows you to receive informations. -There aren't that many methods to use due to the nature of the sites returning different informations. +JavaBotBlockAPI allows you to receive different information of a certain bot. +What the sites returns can be completely different. There are only methods to receive general informations. #### Receive full JSON -You can use the `getAll(...)` method to receive the full JSON of the BotBlock API. +You can use the `getAll(...)` method to receive the full JSON of the BotBlock API. ```java // We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); @@ -113,7 +113,7 @@ JSONObject json = handler.getAll(jda); ``` #### Receive Owners -You can use `getOwners(...)` to receive a List of all owners of the bot. +You can use `getOwners(...)` to receive a List of all owners of the bot. ```java // We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); @@ -123,8 +123,8 @@ List owners = handler.getOwners(jda); ``` #### Receive all botlists. -If you only want the Botlists and their information, use `getBotlists(...)`. -It is returned as a JSONObject. +If you only want the Botlists and their information, use `getBotlists(...)`. +It is returned as a JSONObject. ```java // We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); @@ -134,8 +134,8 @@ JSONObject json = handler.getBotlists(jda); ``` #### Receive certain Botlist info -You can use `getBotlist(..., String)` to get the information of a specific botlist. -The information you receive is given as JSONArray and depends on what the botlist returns. +You can use `getBotlist(..., String)` to get the information of a specific botlist. +The information you receive is given as JSONArray and depends on what the botlist returns. ```java // We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); From 6f07184c6f5f48f581ee5cf6f5b35381b2b4499d Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sun, 14 Jul 2019 16:25:33 +0200 Subject: [PATCH 05/11] Bump JDA dependency to 4.BETA.0_23 --- build.gradle | 2 +- src/main/java/com/andre601/javabotblockapi/RequestHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ca4f109..78579fe 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ dependencies{ implementation group: 'org.json', name: 'json', version: '20180813' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2' - api(group: 'net.dv8tion', name: 'JDA', version: '4.BETA.0_11'){ + api(group: 'net.dv8tion', name: 'JDA', version: '4.BETA.0_23'){ exclude(module: 'opus-java') } } diff --git a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java index 405194a..34b6617 100644 --- a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java +++ b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java @@ -405,7 +405,7 @@ public List getOwners(@NotNull String id) throws IOException, Ratelimite List owners = new ArrayList<>(); for(int i = 0; i < array.length(); i++) - owners.add(array.getString(0)); + owners.add(array.getString(i)); return owners; } From 40ffdd6c0bf072cf80ac49f095b5d825108dce8e Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 16 Jul 2019 11:50:33 +0200 Subject: [PATCH 06/11] Added Check class --- .../com/andre601/javabotblockapi/Check.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/andre601/javabotblockapi/Check.java diff --git a/src/main/java/com/andre601/javabotblockapi/Check.java b/src/main/java/com/andre601/javabotblockapi/Check.java new file mode 100644 index 0000000..39c1123 --- /dev/null +++ b/src/main/java/com/andre601/javabotblockapi/Check.java @@ -0,0 +1,23 @@ +package com.andre601.javabotblockapi; + +import java.util.Map; + +public class Check { + + public static void notNull(Object target, String msg){ + if(target == null) + throw new NullPointerException(msg); + } + + public static void notEmpty(CharSequence arguments, String msg){ + notNull(arguments, msg); + if(arguments.length() == 0) + throw new NullPointerException(msg); + } + + public static void notEmpty(Map map, String msg){ + notNull(map, msg); + if(map.isEmpty()) + throw new NullPointerException(msg); + } +} From 3a6a9a9bbb0036efccbd3bc88c5e25fd13655bf9 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 16 Jul 2019 11:51:09 +0200 Subject: [PATCH 07/11] Removed Commons --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 78579fe..807b860 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,6 @@ repositories{ dependencies{ implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' implementation group: 'org.json', name: 'json', version: '20180813' - implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2' api(group: 'net.dv8tion', name: 'JDA', version: '4.BETA.0_23'){ exclude(module: 'opus-java') From 3e12f865c7a9428baeccef303be850440d5bd4a3 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 16 Jul 2019 11:53:28 +0200 Subject: [PATCH 08/11] Added more get methods --- .../andre601/javabotblockapi/BotBlockAPI.java | 17 +- .../javabotblockapi/RequestHandler.java | 484 ++++++++++-------- 2 files changed, 287 insertions(+), 214 deletions(-) diff --git a/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java b/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java index 873e7a1..b3611f6 100644 --- a/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java +++ b/src/main/java/com/andre601/javabotblockapi/BotBlockAPI.java @@ -18,14 +18,13 @@ */ package com.andre601.javabotblockapi; -import org.apache.commons.lang3.ObjectUtils; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; /** - * Class for handling the sites to post to and the delay for the auto-post option in + * Class for handling the sites to post to and the delay for the auto-post option in the * {@link com.andre601.javabotblockapi.RequestHandler RequestHandler}. */ public class BotBlockAPI{ @@ -48,7 +47,7 @@ public BotBlockAPI(@NotNull Map authTokens){ } /** - * Creates an instance of BotBlockAPI with the provided api tokens (as Map) and update interval. + * Constructor to set the Map with the sites and tokens and also the update delay.. * * @param authTokens * A Map of sites and their tokens. May not be null. @@ -57,6 +56,9 @@ public BotBlockAPI(@NotNull Map authTokens){ * The update interval to set. */ public BotBlockAPI(@NotNull Map authTokens, int updateInterval){ + if(updateInterval < 2) + throw new IllegalArgumentException("Update interval may not be less than 2."); + this.authTokens = authTokens; this.updateInterval = updateInterval; } @@ -98,8 +100,8 @@ public Builder(){} * @return The Builder after the site and token were set. Useful for chaining. */ public Builder addAuthToken(@NotNull String site, @NotNull String token){ - if(ObjectUtils.isEmpty(site) || ObjectUtils.isEmpty(token)) - throw new NullPointerException("Empty site and/or token is not allowed!"); + Check.notEmpty(site, "Site may not be empty."); + Check.notEmpty(token, "Token may not be empty."); authTokens.put(site, token); @@ -119,8 +121,7 @@ public Builder addAuthToken(@NotNull String site, @NotNull String token){ * @return The Builder after the Map was set. Useful for chaining. */ public Builder setAuthTokens(@NotNull Map authTokens){ - if(ObjectUtils.isEmpty(authTokens)) - throw new NullPointerException("Empty Map for authTokens is not allowed!"); + Check.notEmpty(authTokens, "AuthTokens may not be null."); this.authTokens = authTokens; @@ -141,7 +142,7 @@ public Builder setAuthTokens(@NotNull Map authTokens){ */ public Builder setUpdateInteval(int updateInterval){ if(updateInterval < 2) - throw new IllegalArgumentException("updateInterval can't be less than 2!"); + throw new IllegalArgumentException("Update interval may not be less than 2."); this.updateInterval = updateInterval; diff --git a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java index 34b6617..f490b85 100644 --- a/src/main/java/com/andre601/javabotblockapi/RequestHandler.java +++ b/src/main/java/com/andre601/javabotblockapi/RequestHandler.java @@ -21,11 +21,7 @@ import com.andre601.javabotblockapi.exceptions.RatelimitedException; import net.dv8tion.jda.api.sharding.ShardManager; import net.dv8tion.jda.api.JDA; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import org.apache.commons.lang3.ObjectUtils; +import okhttp3.*; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; @@ -39,12 +35,22 @@ /** * Class to handle post-requests to the BotBlock API. + * + *

The class can currently do the following things: + *

    + *
  • Posting Guild counts ({@link #postGuilds(ShardManager, BotBlockAPI) manually} and {@link #startAutoPosting(ShardManager, BotBlockAPI) automatically}).
  • + *
  • {@link #getBotlists() Getting botlists}.
  • + *
  • {@link #getBotlist(String) Getting a single Botlist}.
  • + *
  • {@link #getBotInfos(ShardManager) Getting lists a bot is on}.
  • + *
  • {@link #getBotInfo(ShardManager, String) Getting a single list a bot is on}.
  • + *
  • {@link #getOwners(ShardManager) Getting the owners of a bot.}
  • + *
*/ public class RequestHandler { private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final OkHttpClient CLIENT = new OkHttpClient(); - private String baseUrl = "https://botblock.org/api/"; + private final String BASE_URL = "https://botblock.org/api/"; private String id = null; @@ -71,7 +77,8 @@ public RequestHandler(){} * When the ShardManager gives an invalid shard (Shard id 0 is null). */ public void postGuilds(@NotNull ShardManager shardManager, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ - this.id = Objects.requireNonNull(shardManager.getShardById(0), "The provided ShardManager had an invalid Shard ID.").getSelfUser().getId(); + this.id = Objects.requireNonNull(shardManager.getShardById(0), "Received invalid shard.") + .getSelfUser().getId(); json.put("server_count", shardManager.getGuilds().size()) .put("bot_id", id) @@ -122,7 +129,6 @@ public void postGuilds(@NotNull JDA jda, @NotNull BotBlockAPI botBlockAPI) throw /** * Posts the provided guilds from the provided Bot id. - *
This is a shortcut to {@link #postGuilds(String, int, BotBlockAPI)}. * * @param botId * The ID (as long) of the bot. @@ -156,8 +162,7 @@ public void postGuilds(Long botId, int guilds, @NotNull BotBlockAPI botBlockAPI) * When the Bot (IP or ID) got ratelimited. */ public void postGuilds(@NotNull String botId, int guilds, @NotNull BotBlockAPI botBlockAPI) throws IOException, RatelimitedException{ - if(ObjectUtils.isEmpty(botId)) - throw new NullPointerException("botId may not be empty!"); + Check.notEmpty(botId, "ID may not be empty."); this.id = botId; @@ -189,8 +194,7 @@ public void startAutoPosting(@NotNull ShardManager shardManager, @NotNull BotBlo } /** - * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.api.JDA JDA} - * every X minutes. + * Starts a scheduler that posts the guilds from the provided {@link net.dv8tion.jda.api.JDA JDA} every X minutes. * * @param jda * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. @@ -254,71 +258,8 @@ public void stopAutoPosting(){ scheduler.shutdown(); } - private void postRequest() throws IOException, RatelimitedException{ - Objects.requireNonNull(json, "JSON may not be null."); - Objects.requireNonNull(id, "Id may not be null."); - - if(ObjectUtils.isEmpty(id)) - throw new NullPointerException("botId may not be empty!"); - - String url = baseUrl + "count"; - - RequestBody body = RequestBody.create(null, json.toString()); - Request request = new Request.Builder() - .url(url) - .addHeader("User-Agent", id) - .addHeader("Content-Type", "application/json") // Some sites require this in the header. - .post(body) - .build(); - - try(Response response = CLIENT.newCall(request).execute()){ - Objects.requireNonNull(response.body(), "Received empty body from BotBlocks API."); - - if(response.body().string().isEmpty()) - throw new NullPointerException("Received empty body from BotBlocks API."); - - if(!response.isSuccessful()){ - if(response.code() == 429) - throw new RatelimitedException(response.body().string()); - - throw new IOException(String.format( - "Couldn't post guild counts to BotBlockAPI! Site responded with %d (%s)", - response.code(), - response.message() - )); - } - - JSONObject json = new JSONObject(response.body()); - if(json.has("failure")){ - JSONObject failure = json.getJSONObject("failure"); - - List sites = new ArrayList<>(); - for(String key : failure.keySet()){ - try{ - JSONArray array = failure.getJSONArray(key); - sites.add(String.format( - "Name: %s, Error code: %d, Error Message: %s", - key, - array.getInt(0), - array.getString(1) - )); - }catch (JSONException ex){ - Map notFound = failure.toMap(); - sites.add("Errors: " + notFound.toString()); - } - } - - throw new IOException(String.format( - "One or multiple requests failed! Response(s): %s", - String.join(", ", sites) - )); - } - } - } - /** * Gets the owners of a bot as a list. - *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. * * @param shardManager * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} that should be used. @@ -330,18 +271,16 @@ private void postRequest() throws IOException, RatelimitedException{ * @throws RatelimitedException * When the API gets ratelimited. * - * @since v1.1.0 - * - * @see #getOwners(String) getOwners(String) + * @since v2.0.0 */ public List getOwners(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{ - return getOwners(shardManager.getShardById(0).getSelfUser().getId()); + return getOwners(Objects.requireNonNull(shardManager.getShardById(0), "Received invalid Shard") + .getSelfUser().getId()); } /** * Gets the owners of a bot as a list. - *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. * * @param jda * The {@link net.dv8tion.jda.api.JDA JDA instance} that should be used. @@ -353,9 +292,7 @@ public List getOwners(@NotNull ShardManager shardManager) throws IOExcep * @throws RatelimitedException * When the API gets ratelimited. * - * @since v1.1.0 - * - * @see #getOwners(String) getOwners(String) + * @since v2.0.0 */ public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedException{ return getOwners(jda.getSelfUser().getId()); @@ -363,7 +300,6 @@ public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedE /** * Gets the owners of a bot as a list. - *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getAll(String) getOwners(String)}. * * @param id * The id of the bot. @@ -375,9 +311,7 @@ public List getOwners(@NotNull JDA jda) throws IOException, RatelimitedE * @throws RatelimitedException * When the API gets ratelimited. * - * @since v1.1.0 - * - * @see #getOwners(String) getOwners(String) + * @since v2.0.0 */ public List getOwners(Long id) throws IOException, RatelimitedException{ return getOwners(Long.toString(id)); @@ -396,7 +330,7 @@ public List getOwners(Long id) throws IOException, RatelimitedException{ * @throws RatelimitedException * When the Bot (IP or ID) got ratelimited. * - * @since v1.1.0 + * @since v2.0.0 */ public List getOwners(@NotNull String id) throws IOException, RatelimitedException{ JSONObject json = getAll(id); @@ -412,7 +346,7 @@ public List getOwners(@NotNull String id) throws IOException, Ratelimite /** * Gets all the available Botlists as JSONObject. - *
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + *
The data of each Botlist depends on the site. * *

The JSONObject will look something like this: *


@@ -438,17 +372,16 @@ public List getOwners(@NotNull String id) throws IOException, Ratelimite
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getBotlists(String) getBotlists(String)
+     * @since v2.0.0
      */
-    public JSONObject getBotlists(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{
-        return getBotlists(shardManager.getShardById(0).getSelfUser().getId());
+    public JSONObject getBotInfos(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{
+        return getBotInfos(Objects.requireNonNull(shardManager.getShardById(0), "Received invalid shard.")
+                .getSelfUser().getId());
     }
 
     /**
      * Gets all the available Botlists as JSONObject.
-     * 
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + *
The data of each Botlist depends on the site. * *

The JSONObject will look something like this: *


@@ -474,17 +407,15 @@ public JSONObject getBotlists(@NotNull ShardManager shardManager) throws IOExcep
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getBotlists(String) getBotlists(String)
+     * @since v2.0.0
      */
-    public JSONObject getBotlists(@NotNull JDA jda) throws IOException, RatelimitedException{
-        return getBotlists(jda.getSelfUser().getId());
+    public JSONObject getBotInfos(@NotNull JDA jda) throws IOException, RatelimitedException{
+        return getBotInfos(jda.getSelfUser().getId());
     }
 
     /**
      * Gets all the available Botlists as JSONObject.
-     * 
This method calls {@link com.andre601.javabotblockapi.RequestHandler#getBotlists(String) getBotlists(String)}. + *
The data of each Botlist depends on the site. * *

The JSONObject will look something like this: *


@@ -510,16 +441,15 @@ public JSONObject getBotlists(@NotNull JDA jda) throws IOException, RatelimitedE
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getBotlists(String) getBotlists(String)
+     * @since v2.0.0
      */
-    public JSONObject getBotlists(Long id) throws IOException, RatelimitedException{
-        return getBotlists(Long.toString(id));
+    public JSONObject getBotInfos(Long id) throws IOException, RatelimitedException{
+        return getBotInfos(Long.toString(id));
     }
 
     /**
      * Gets all the available Botlists as JSONObject.
+     * 
The data of each Botlist depends on the site. * *

The JSONObject will look something like this: *


@@ -545,14 +475,15 @@ public JSONObject getBotlists(Long id) throws IOException, RatelimitedException{
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
+     * @since v2.0.0
      */
-    public JSONObject getBotlists(@NotNull String id) throws IOException, RatelimitedException{
+    public JSONObject getBotInfos(@NotNull String id) throws IOException, RatelimitedException{
         return getAll(id).getJSONObject("list_data");
     }
 
     /**
-     * Gets a specific botlist-information as JSONArray.
+     * Gets the specific information from a single Botlist.
+     * 
The returned data depends on the Botlist. * *

The JSONObject will look something like this: *


@@ -575,14 +506,16 @@ public JSONObject getBotlists(@NotNull String id) throws IOException, Ratelimite
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
-    public JSONArray getBotlist(@NotNull ShardManager shardManager, @NotNull String site) throws IOException, RatelimitedException{
-        return getBotlist(shardManager.getShardById(0).getSelfUser().getId(), site);
+    public JSONArray getBotInfo(@NotNull ShardManager shardManager, @NotNull String site) throws IOException, RatelimitedException{
+        return getBotInfo(Objects.requireNonNull(shardManager.getShardById(0), "Received invalid shard.")
+                .getSelfUser().getId(), site);
     }
 
     /**
-     * Gets a specific botlist-information as JSONArray.
+     * Gets the specific information from a single Botlist.
+     * 
The returned data depends on the Botlist. * *

The JSONObject will look something like this: *


@@ -605,16 +538,15 @@ public JSONArray getBotlist(@NotNull ShardManager shardManager, @NotNull String
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
-    public JSONArray getBotlist(Long id, @NotNull String site) throws IOException, RatelimitedException{
-        return getBotlist(Long.toString(id), site);
+    public JSONArray getBotInfo(Long id, @NotNull String site) throws IOException, RatelimitedException{
+        return getBotInfo(Long.toString(id), site);
     }
 
     /**
-     * Gets a specific botlist-information as JSONArray.
+     * Gets the specific information from a single Botlist.
+     * 
The returned data depends on the Botlist. * *

The JSONObject will look something like this: *


@@ -637,16 +569,15 @@ public JSONArray getBotlist(Long id, @NotNull String site) throws IOException, R
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
-    public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, RatelimitedException{
-        return getBotlist(jda.getSelfUser().getId(), site);
+    public JSONArray getBotInfo(@NotNull JDA jda, String site) throws IOException, RatelimitedException{
+        return getBotInfo(jda.getSelfUser().getId(), site);
     }
 
     /**
-     * Gets a specific botlist-information as JSONArray.
+     * Gets the specific information from a single Botlist.
+     * 
The returned data depends on the Botlist. * *

The JSONObject will look something like this: *


@@ -669,17 +600,26 @@ public JSONArray getBotlist(@NotNull JDA jda, String site) throws IOException, R
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
+     * @since v2.0.0
      */
-    public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOException, RatelimitedException{
+    public JSONArray getBotInfo(@NotNull String id, @NotNull String site) throws IOException, RatelimitedException{
         return getAll(id).getJSONObject("list_data").getJSONArray(site);
     }
 
     /**
-     * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(ShardManager) owners},
-     * server_count and OAuth-link but also all sites and corresponding informations of those.
-     * 
With exception of id and the sites are the other informations based on the most common response. - *
This method directly calls {@link #getAll(String) getAll(String)}. + * Gets information from BotBlock about the provided Bot. + *
The information can contain: + *
    + *
  • Bot id
  • + *
  • Username
  • + *
  • Discriminator
  • + *
  • Botowners*
  • + *
  • Server count*
  • + *
  • OAuth invite*
  • + *
  • Data of the botlists**
  • + *
+ * *Based on most appearances on the botlists. + *
**The provided data depends on the Botlist and can be different. * *

A response could look like this: *


@@ -715,30 +655,27 @@ public JSONArray getBotlist(@NotNull String id, @NotNull String site) throws IOE
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getOwners(ShardManager) getOwners(ShardManager)
-     * @see #getOwners(JDA) getOwners(JDA)
-     * @see #getOwners(Long) getOwners(Long)
-     * @see #getOwners(String) getOwners(String)
-     * @see #getBotlists(ShardManager) getBotlists(ShardManager)
-     * @see #getBotlists(JDA) getBotlists(JDA)
-     * @see #getBotlists(Long) getBotlists(Long)
-     * @see #getBotlists(String) getBotlists(String)
-     * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String)
-     * @see #getBotlist(JDA, String) getBotlist(JDA, String)
-     * @see #getBotlist(Long, String) getBotlist(Long, String)
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
     public JSONObject getAll(@NotNull ShardManager shardManager) throws IOException, RatelimitedException{
-        return getAll(shardManager.getShardById(0).getSelfUser().getId());
+        return getAll(Objects.requireNonNull(shardManager.getShardById(0), "Received invalid shard.")
+                .getSelfUser().getId());
     }
 
     /**
-     * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(JDA) owners},
-     * server_count and OAuth-link but also all sites and corresponding informations of those.
-     * 
With exception of id and the sites are the other informations based on the most common response. - *
This method directly calls {@link #getAll(String) getAll(String)}. + * Gets information from BotBlock about the provided Bot. + *
The information can contain: + *
    + *
  • Bot id
  • + *
  • Username
  • + *
  • Discriminator
  • + *
  • Botowners*
  • + *
  • Server count*
  • + *
  • OAuth invite*
  • + *
  • Data of the botlists**
  • + *
+ * *Based on most appearances on the botlists. + *
**The provided data depends on the Botlist and can be different. * *

A response could look like this: *


@@ -774,30 +711,26 @@ public JSONObject getAll(@NotNull ShardManager shardManager) throws IOException,
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getOwners(ShardManager) getOwners(ShardManager)
-     * @see #getOwners(JDA) getOwners(JDA)
-     * @see #getOwners(Long) getOwners(Long)
-     * @see #getOwners(String) getOwners(String)
-     * @see #getBotlists(ShardManager) getBotlists(ShardManager)
-     * @see #getBotlists(JDA) getBotlists(JDA)
-     * @see #getBotlists(Long) getBotlists(Long)
-     * @see #getBotlists(String) getBotlists(String)
-     * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String)
-     * @see #getBotlist(JDA, String) getBotlist(JDA, String)
-     * @see #getBotlist(Long, String) getBotlist(Long, String)
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
     public JSONObject getAll(@NotNull JDA jda) throws IOException, RatelimitedException{
         return getAll(jda.getSelfUser().getId());
     }
 
     /**
-     * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(Long) owners},
-     * server_count and OAuth-link but also all sites and corresponding informations of those.
-     * 
With exception of id and the sites are the other informations based on the most common response. - *
This method directly calls {@link #getAll(String) getAll(String)}. + * Gets information from BotBlock about the provided Bot. + *
The information can contain: + *
    + *
  • Bot id
  • + *
  • Username
  • + *
  • Discriminator
  • + *
  • Botowners*
  • + *
  • Server count*
  • + *
  • OAuth invite*
  • + *
  • Data of the botlists**
  • + *
+ * *Based on most appearances on the botlists. + *
**The provided data depends on the Botlist and can be different. * *

A response could look like this: *


@@ -833,29 +766,26 @@ public JSONObject getAll(@NotNull JDA jda) throws IOException, RatelimitedExcept
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getOwners(ShardManager) getOwners(ShardManager)
-     * @see #getOwners(JDA) getOwners(JDA)
-     * @see #getOwners(Long) getOwners(Long)
-     * @see #getOwners(String) getOwners(String)
-     * @see #getBotlists(ShardManager) getBotlists(ShardManager)
-     * @see #getBotlists(JDA) getBotlists(JDA)
-     * @see #getBotlists(Long) getBotlists(Long)
-     * @see #getBotlists(String) getBotlists(String)
-     * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String)
-     * @see #getBotlist(JDA, String) getBotlist(JDA, String)
-     * @see #getBotlist(Long, String) getBotlist(Long, String)
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
     public JSONObject getAll(Long id) throws IOException, RatelimitedException{
         return getAll(Long.toString(id));
     }
 
     /**
-     * Gets the basic information of a bot including id, name, discriminator, {@link #getOwners(String) owners},
-     * server_count and OAuth-link but also all sites and corresponding informations of those.
-     * 
With exception of id and the sites are the other informations based on the most common response. + * Gets information from BotBlock about the provided Bot. + *
The information can contain: + *
    + *
  • Bot id
  • + *
  • Username
  • + *
  • Discriminator
  • + *
  • Botowners*
  • + *
  • Server count*
  • + *
  • OAuth invite*
  • + *
  • Data of the botlists**
  • + *
+ * *Based on most appearances on the botlists. + *
**The provided data depends on the Botlist and can be different. * *

A response could look like this: *


@@ -891,23 +821,10 @@ public JSONObject getAll(Long id) throws IOException, RatelimitedException{
      * @throws RatelimitedException
      *         When the API gets ratelimited.
      *
-     * @since v1.1.0
-     *
-     * @see #getOwners(ShardManager) getOwners(ShardManager)
-     * @see #getOwners(JDA) getOwners(JDA)
-     * @see #getOwners(Long) getOwners(Long)
-     * @see #getOwners(String) getOwners(String)
-     * @see #getBotlists(ShardManager) getBotlists(ShardManager)
-     * @see #getBotlists(JDA) getBotlists(JDA)
-     * @see #getBotlists(Long) getBotlists(Long)
-     * @see #getBotlists(String) getBotlists(String)
-     * @see #getBotlist(ShardManager, String) getBotlist(ShardManager, String)
-     * @see #getBotlist(JDA, String) getBotlist(JDA, String)
-     * @see #getBotlist(Long, String) getBotlist(Long, String)
-     * @see #getBotlist(String, String) getBotlist(String, String)
+     * @since v2.0.0
      */
     public JSONObject getAll(@NotNull String id) throws IOException, RatelimitedException{
-        String url = baseUrl + "bots/" + id;
+        String url = BASE_URL + "bots/" + id;
 
         Request request = new Request.Builder()
                 .url(url)
@@ -915,23 +832,178 @@ public JSONObject getAll(@NotNull String id) throws IOException, RatelimitedExce
                 .build();
 
         try(Response response = CLIENT.newCall(request).execute()){
-            Objects.requireNonNull(response.body(), "Received empty body from BotBlocks API.");
+            Check.notNull(response.body(), "Received empty response body from BotBlcok API.");
+            ResponseBody responseBody = response.body();
 
-            if(response.body().string().isEmpty())
-                throw new NullPointerException("Received empty body from BotBlocks API.");
+            Check.notEmpty(responseBody.string(), "Received empty response body from BotBlock API.");
 
             if(!response.isSuccessful()){
                 if(response.code() == 429)
-                    throw new RatelimitedException(response.body().string());
+                    throw new RatelimitedException(responseBody.string());
 
                 throw new IOException(String.format(
-                        "Couldn't get Bot information. Site responded with %d (%s)",
+                        "Couldn't get Bot information. Site responded with error code %d (%s)",
                         response.code(),
                         response.message()
                 ));
             }
 
-            return new JSONObject(response.body().string());
+            return new JSONObject(responseBody.string());
+        }
+    }
+
+    /**
+     * Returns the provided botlist info that is saved in BotBlock.
+     *
+     * 

A response could look like this: + *


+     * {
+     *     "api_docs": "https://somebotlist.com/docs",
+     *     "api_post": "https://somebotlist.com/api/v1/bots/:id/post",
+     *     "api_field": "server_count",
+     *     "api_shard_id": "shard_id",
+     *     "api_shard_count": "shard_count",
+     *     "api_shards": "shards",
+     *     "api_get": "https://somebotlist.com/api/v1/bots/:id"
+     * }
+     * 
+ * + * @param name + * The name of the botlist. + * + * @return The botlist as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v2.0.0 + */ + public JSONObject getBotlist(@NotNull String name) throws IOException, RatelimitedException{ + return getBotlists().getJSONObject(name); + } + + /** + * Returns the current botlists that BotBlock supports. + * + *

A response could look like this: + *


+     * {
+     *     "somebotlist.com": {
+     *         "api_docs": "https://somebotlist.com/docs",
+     *         "api_post": "https://somebotlist.com/api/v1/bots/:id/post",
+     *         "api_field": "server_count",
+     *         "api_shard_id": "shard_id",
+     *         "api_shard_count": "shard_count",
+     *         "api_shards": "shards",
+     *         "api_get": "https://somebotlist.com/api/v1/bots/:id"
+     *     },
+     *     "otherlist.org": {
+     *         "api_docs": "https://docs.otherlist.org",
+     *         "api_post": null,
+     *         "api_field": null,
+     *         "api_shard_id": null,
+     *         "api_shard_count": null,
+     *         "api_shards": null,
+     *         "api_get": "https://api.otherlist.org/v2/bot/:id"
+     *     }
+     * }
+     * 
+ * + * @return The botlists as JSONObject. + * + * @throws IOException + * When the request couldn't be performed properly. + * @throws RatelimitedException + * When the API gets ratelimited. + * + * @since v2.0.0 + */ + public JSONObject getBotlists() throws IOException, RatelimitedException{ + String url = BASE_URL + "lists"; + + Request request = new Request.Builder() + .url(url) + .build(); + + try(Response response = CLIENT.newCall(request).execute()){ + Check.notNull(response.body(), "Received empty response body from BotBlcok API."); + ResponseBody responseBody = response.body(); + + Check.notEmpty(responseBody.string(), "Received empty response body from BotBlock API."); + + if(!response.isSuccessful()){ + if(response.code() == 429) + throw new RatelimitedException(responseBody.string()); + + throw new IOException(String.format( + "Couldn't get Botlists. Site responded with error code %d (%s)", + response.code(), + response.message() + )); + } + + return new JSONObject(responseBody.string()); + } + } + + private void postRequest() throws IOException, RatelimitedException{ + Check.notNull(json, "JSON may not be null."); + Check.notEmpty(id, "ID may not be empty."); + + String url = BASE_URL + "count"; + + RequestBody body = RequestBody.create(null, json.toString()); + Request request = new Request.Builder() + .url(url) + .addHeader("User-Agent", id) + .addHeader("Content-Type", "application/json") // Some sites require this in the header. + .post(body) + .build(); + + try(Response response = CLIENT.newCall(request).execute()){ + Check.notNull(response.body(), "Received empty response body from BotBlcok API."); + ResponseBody responseBody = response.body(); + + Check.notEmpty(responseBody.string(), "Received empty response body from BotBlock API."); + + if(!response.isSuccessful()){ + if(response.code() == 429) + throw new RatelimitedException(responseBody.string()); + + throw new IOException(String.format( + "Couldn't post guild counts to BotBlockAPI! Site responded with error code %d (%s)", + response.code(), + response.message() + )); + } + + JSONObject json = new JSONObject(responseBody); + if(json.has("failure")){ + JSONObject failure = json.getJSONObject("failure"); + + List sites = new ArrayList<>(); + for(String key : failure.keySet()){ + try{ + JSONArray array = failure.getJSONArray(key); + sites.add(String.format( + "Name: %s, Error code: %d, Error Message: %s", + key, + array.getInt(0), + array.getString(1) + )); + }catch (JSONException ex){ + Map notFound = failure.toMap(); + sites.add("Errors: " + notFound.toString()); + } + } + + throw new IOException(String.format( + "One or multiple requests failed! Response(s): %s", + String.join(", ", sites) + )); + } } } } From 44da1e058d853e3e2cf2897401b2ec7ab38c8426 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 18 Jul 2019 15:14:25 +0200 Subject: [PATCH 09/11] Updating readme --- README.md | 195 +++++++++++------- build.gradle | 10 +- .../com/andre601/javabotblockapi/Check.java | 8 +- 3 files changed, 131 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index cadd82e..e109b01 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,16 @@ [BadgeDownload]: https://api.bintray.com/packages/andre601/maven/JavaBotBlockAPI/images/download.svg [Download]: https://bintray.com/andre601/maven/JavaBotBlockAPI/_latestVersion -# JavaBotBlockAPI JavaBotBlockAPI is a continued and updated Java Wrapper for [BotBlock], a website that makes it possible to update guild counts on multiple lists with one API. This wrapper is a fork of [BotBlock4J] and was updated and improved to make it as userfriendly as possible. -## Installation +# Installation [![BadgeDownload]][Download] You can install JavaBotBlockAPI through the following methods. Make sure to replace `{version}` with the above shown version. -### Gradle +## Gradle Put this code into your `build.gradle`: ```gradle repositories{ @@ -31,7 +30,7 @@ dependencies{ } ``` -### Maven +## Maven For maven use this code snipped: ```xml @@ -43,108 +42,158 @@ For maven use this code snipped: ``` -## Usage +# Usage To use the Wrapper you have to follow these steps. -### Notes +## Notes In the below examples do I use a JDA instance called `jda`. This will also work with ShardManager. -### Creating a BotBlockAPI instance -You first need to create an instance of the BotBlockAPI class. -This class is the center of everything, including on what sites you want to post your guild counts. +## POST methods +You can post you guild counts to the different Botlists using the BotBlock API. -You can use the internal Builder class of BotBlockAPI to create an instance. It would look something like this: +### Creating an instance of BotBlockAPI +For posting your guild counts towards the BotBlock API you first need to create an instance of the BotBlockAPI class. +To do this it's recommended to use `BotBlockAPI.Builder()`. + +Here is an example of how it could look like. ```java -// Creating an instance of BotBlockAPI using BotBlockAPI.Builder BotBlockAPI api = new BotBlockAPI.Builder() - .addAuthToken("lbots.org", "MySecretToken123") // Adds a site with the corresponding API token. - .addAuthToken("botlist.space", "MySecretToken456") // The builder allows chaining of the methods. + .addAuthToken("lbots.org", "MySecretToken123") + .addAuthToken("botlist.space", "MySecretToken456") .build(); ``` +Remember to use `.build();` at the end to create the class. -#### Notes -There are a lot of other methods that you can use. Head over to the [Wiki] for more information. - -### Posting -You can post the guilds either automatically or manually depending on your own preferences. - -#### Auto-posting -JavaBotBlockAPI comes with an inbuilt scheduler to post your guilds automatically. -To use it simply use the `startAutoPosting` method and provide either a JDA instance, ShardManager instance or the bot id and guild count. +### Auto Posting +JavaBotBlockAPI allows you to post the guild counts automatically every X minutes. +To do this, you first need to get an instance of the RequestHandler and then call `.startAutoPosting(...)`. -**Example**: +Here is an example: ```java -// We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); -// jda is a JDA instance and api a BotBlockAPI instance. +// api is the instance of the BotBlockAPI handler.startAutoPosting(jda, api); ``` +The delay in which you post the guild counts is set through the `.setUpdateInterval(int)` method in the BotBlockAPI.Builder(). -But what if you want to stop it? -For that just call the `stopAutoPosting` method: -``` -handler.stopAutoPosting(); -``` +### Cancel auto posting +To cancel the auto posting just call `.stopAutoPosting();` in the RequestHandler and it should cancel the scheduler. + +### Manually posting +There are methods that allow you to post the guild counts manually. +To Post your guild counts, just call the `.postGuilds(..., ...)` method in the RequestHandler. -#### Manual posting -If you want to post the guild counts manually you can use the `postGuilds` method. ```java -// We need to get an instance of RequestHandler to use the methods. RequestHandler handler = new RequestHandler(); -// jda is a JDA instance and api a BotBlockAPI instance. +// api is the instance of the BotBlockAPI handler.postGuilds(jda, api); ``` -### Getting botinfo -JavaBotBlockAPI allows you to receive different information of a certain bot. -What the sites returns can be completely different. There are only methods to receive general informations. - -#### Receive full JSON -You can use the `getAll(...)` method to receive the full JSON of the BotBlock API. -```java -// We need to get an instance of RequestHandler to use the methods. -RequestHandler handler = new RequestHandler(); - -// Like with all other methods can you use JDA, ShardManager or ID. -JSONObject json = handler.getAll(jda); +## GET methods +Since version 2.0.0 of JavaBotBlockAPI can you get certain informations of a bot or the available Botlists on the BotBlock API. + +### All available Botlists +You can call `.getBotlists()` to receive a JSONObject with all available Botlists in the BotBlockAPI. + +The returned JSONObject could look like this: +```json +{ + "botlist.space": { + "api_docs": "https://docs.botlist.space", + "api_post": "https://api.botlist.space/v1/bots/:id", + "api_field": "server_count", + "api_shard_id": null, + "api_shard_count": null, + "api_shards": "shards", + "api_get": "https://api.botlist.space/v1/bots/:id" + }, + "lbots.org": { + "api_docs": "https://lbots.org/api/docs", + "api_post": "https://lbots.org/api/v1/bots/:id/stats", + "api_field": "guild_count", + "api_shard_id": "shard_id", + "api_shard_count": "shard_count", + "api_shards": null, + "api_get": null + } +} ``` -#### Receive Owners -You can use `getOwners(...)` to receive a List of all owners of the bot. -```java -// We need to get an instance of RequestHandler to use the methods. -RequestHandler handler = new RequestHandler(); - -// Like with all other methods can you use JDA, ShardManager or ID. -List owners = handler.getOwners(jda); +### Single Botlist +Calling `.getBotlist(String)` returns a specific Botlist as JSONObject. +For example does `.getBotlist("lbots.org")` return the following JSONObject: +```json +{ + "api_docs": "https://lbots.org/api/docs", + "api_post": "https://lbots.org/api/v1/bots/:id/stats", + "api_field": "guild_count", + "api_shard_id": "shard_id", + "api_shard_count": "shard_count", + "api_shards": null, + "api_get": null +} ``` -#### Receive all botlists. -If you only want the Botlists and their information, use `getBotlists(...)`. -It is returned as a JSONObject. -```java -// We need to get an instance of RequestHandler to use the methods. -RequestHandler handler = new RequestHandler(); +### Complete Botinfo +Calling `.getAll(...)` returns a JSONObject from all the botlists and with some general information. + +The JSONObject can look like this: +```json +{ + "id": "123456789012345678", + "name": "MyBot", + "discriminator": "1234", + "owners": [ + "234567890123456789" + ], + "server_count": 100, + "invite": "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot", + "list_data": { + "botlist.space": [ + , + 200 + ], + "lbots.org": [ + , + 404 + ] + } +} +``` -// Like with all other methods can you use JDA, ShardManager or ID. -JSONObject json = handler.getBotlists(jda); +`` is the JSON that is returned by the provided Botlist meaning it's different for each site. +`name`, `owners`, `server_count` and `invite` is based on the most common appearances of the data. + +### Botinfo from all Botlists +You can call `.getBotInfos(...)` to only receive the bot info from all the Botlists. + +The returned JSONObject can look like this: +```json +{ + "botlist.space": [ + , + 200 + ], + "lbots.org": [ + , + 404 + ] +} ``` +`` is the JSON that is returned by the provided Botlist meaning it's different for each site. -#### Receive certain Botlist info -You can use `getBotlist(..., String)` to get the information of a specific botlist. -The information you receive is given as JSONArray and depends on what the botlist returns. -```java -// We need to get an instance of RequestHandler to use the methods. -RequestHandler handler = new RequestHandler(); +### Botinfo of a single site +With `.getBotInfo(..., String)` can you receive the info of a specific site. +The returned data depends on the selected site and can be different for each one. -// Like with all other methods can you use JDA, ShardManager or ID. -JSONArray array = handler.getBotlist(jda, "lbots.org"); -``` +### Owners +You can call `.getOwners(...)` to get the owners of a Bot from all the Botlists. +The info is returned as JSONArray and is based on how often the info is provided by the botlists. -### Exceptions +## Exceptions When you post the guild counts you could encounter certain Exceptions. You can receive the following exceptions: - `IOException` @@ -155,7 +204,7 @@ This shouldn't be the case with auto-posting since it has a minimum delay of 1 m - `NullPointerException` Thrown when BotBlock.org sends an empty response, meaning something got messed up on their side. -## Links +# Links Here are some useful links: - [BotBlock.org][BotBlock] Site for which this wrapper was made. - [API] API documentation. diff --git a/build.gradle b/build.gradle index 807b860..786403e 100644 --- a/build.gradle +++ b/build.gradle @@ -21,20 +21,20 @@ repositories{ } dependencies{ - implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' - implementation group: 'org.json', name: 'json', version: '20180813' - implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2' + api group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0' + api group: 'org.json', name: 'json', version: '20180813' + api group: 'org.jetbrains', name: 'annotations', version: '16.0.2' api(group: 'net.dv8tion', name: 'JDA', version: '4.BETA.0_23'){ exclude(module: 'opus-java') } } -task sourcesJar(type: Jar, dependsOn: classes) { +task sourcesJar(type: Jar, dependsOn: classes){ classifier = 'sources' from sourceSets.main.allSource } -task javadocJar(type: Jar, dependsOn: javadoc) { +task javadocJar(type: Jar, dependsOn: javadoc){ classifier = 'javadoc' from javadoc.destinationDir } diff --git a/src/main/java/com/andre601/javabotblockapi/Check.java b/src/main/java/com/andre601/javabotblockapi/Check.java index 39c1123..94dbab6 100644 --- a/src/main/java/com/andre601/javabotblockapi/Check.java +++ b/src/main/java/com/andre601/javabotblockapi/Check.java @@ -2,20 +2,20 @@ import java.util.Map; -public class Check { +class Check { - public static void notNull(Object target, String msg){ + static void notNull(Object target, String msg){ if(target == null) throw new NullPointerException(msg); } - public static void notEmpty(CharSequence arguments, String msg){ + static void notEmpty(CharSequence arguments, String msg){ notNull(arguments, msg); if(arguments.length() == 0) throw new NullPointerException(msg); } - public static void notEmpty(Map map, String msg){ + static void notEmpty(Map map, String msg){ notNull(map, msg); if(map.isEmpty()) throw new NullPointerException(msg); From 61b68b1b69fef68549dc403002f64aa0b932e723 Mon Sep 17 00:00:00 2001 From: Andre_601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 18 Jul 2019 15:16:58 +0200 Subject: [PATCH 10/11] linebreak fixes --- README.md | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e109b01..cda8c2f 100644 --- a/README.md +++ b/README.md @@ -53,36 +53,36 @@ This will also work with ShardManager. You can post you guild counts to the different Botlists using the BotBlock API. ### Creating an instance of BotBlockAPI -For posting your guild counts towards the BotBlock API you first need to create an instance of the BotBlockAPI class. +For posting your guild counts towards the BotBlock API you first need to create an instance of the BotBlockAPI class. To do this it's recommended to use `BotBlockAPI.Builder()`. -Here is an example of how it could look like. +Here is an example of how it could look like. ```java BotBlockAPI api = new BotBlockAPI.Builder() .addAuthToken("lbots.org", "MySecretToken123") .addAuthToken("botlist.space", "MySecretToken456") .build(); -``` +``` Remember to use `.build();` at the end to create the class. ### Auto Posting -JavaBotBlockAPI allows you to post the guild counts automatically every X minutes. +JavaBotBlockAPI allows you to post the guild counts automatically every X minutes. To do this, you first need to get an instance of the RequestHandler and then call `.startAutoPosting(...)`. -Here is an example: +Here is an example: ```java RequestHandler handler = new RequestHandler(); // api is the instance of the BotBlockAPI handler.startAutoPosting(jda, api); -``` +``` The delay in which you post the guild counts is set through the `.setUpdateInterval(int)` method in the BotBlockAPI.Builder(). ### Cancel auto posting To cancel the auto posting just call `.stopAutoPosting();` in the RequestHandler and it should cancel the scheduler. ### Manually posting -There are methods that allow you to post the guild counts manually. +There are methods that allow you to post the guild counts manually. To Post your guild counts, just call the `.postGuilds(..., ...)` method in the RequestHandler. ```java @@ -98,7 +98,7 @@ Since version 2.0.0 of JavaBotBlockAPI can you get certain informations of a bot ### All available Botlists You can call `.getBotlists()` to receive a JSONObject with all available Botlists in the BotBlockAPI. -The returned JSONObject could look like this: +The returned JSONObject could look like this: ```json { "botlist.space": { @@ -123,8 +123,8 @@ The returned JSONObject could look like this: ``` ### Single Botlist -Calling `.getBotlist(String)` returns a specific Botlist as JSONObject. -For example does `.getBotlist("lbots.org")` return the following JSONObject: +Calling `.getBotlist(String)` returns a specific Botlist as JSONObject. +For example does `.getBotlist("lbots.org")` return the following JSONObject: ```json { "api_docs": "https://lbots.org/api/docs", @@ -140,7 +140,7 @@ For example does `.getBotlist("lbots.org")` return the following JSONObject: ### Complete Botinfo Calling `.getAll(...)` returns a JSONObject from all the botlists and with some general information. -The JSONObject can look like this: +The JSONObject can look like this: ```json { "id": "123456789012345678", @@ -162,15 +162,14 @@ The JSONObject can look like this: ] } } -``` - -`` is the JSON that is returned by the provided Botlist meaning it's different for each site. +``` +`` is the JSON that is returned by the provided Botlist meaning it's different for each site. `name`, `owners`, `server_count` and `invite` is based on the most common appearances of the data. ### Botinfo from all Botlists You can call `.getBotInfos(...)` to only receive the bot info from all the Botlists. -The returned JSONObject can look like this: +The returned JSONObject can look like this: ```json { "botlist.space": [ @@ -182,15 +181,15 @@ The returned JSONObject can look like this: 404 ] } -``` +``` `` is the JSON that is returned by the provided Botlist meaning it's different for each site. ### Botinfo of a single site -With `.getBotInfo(..., String)` can you receive the info of a specific site. +With `.getBotInfo(..., String)` can you receive the info of a specific site. The returned data depends on the selected site and can be different for each one. ### Owners -You can call `.getOwners(...)` to get the owners of a Bot from all the Botlists. +You can call `.getOwners(...)` to get the owners of a Bot from all the Botlists. The info is returned as JSONArray and is based on how often the info is provided by the botlists. ## Exceptions From 3911714e0121d0ddb9be28616c1b3cc6ac4643cd Mon Sep 17 00:00:00 2001 From: Andre_601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 18 Jul 2019 15:20:46 +0200 Subject: [PATCH 11/11] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cda8c2f..ee4418c 100644 --- a/README.md +++ b/README.md @@ -153,17 +153,17 @@ The JSONObject can look like this: "invite": "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot", "list_data": { "botlist.space": [ - , + {"data"}, 200 ], "lbots.org": [ - , + {"data"}, 404 ] } } ``` -`` is the JSON that is returned by the provided Botlist meaning it's different for each site. +`{"data"}` is the JSON that is returned by the provided Botlist meaning it's different for each site. `name`, `owners`, `server_count` and `invite` is based on the most common appearances of the data. ### Botinfo from all Botlists @@ -173,16 +173,16 @@ The returned JSONObject can look like this: ```json { "botlist.space": [ - , + {"data"}, 200 ], "lbots.org": [ - , + {"data"}, 404 ] } ``` -`` is the JSON that is returned by the provided Botlist meaning it's different for each site. +`{"data"}` is the JSON that is returned by the provided Botlist meaning it's different for each site. ### Botinfo of a single site With `.getBotInfo(..., String)` can you receive the info of a specific site.