|
| 1 | +[BotBlock]: https://botblock.org |
| 2 | +[API]: https://botblock.org/api/docs |
| 3 | + |
| 4 | +[BotBlock4J]: https://github.com/Nathan-webb/BotBlock4J |
| 5 | + |
| 6 | +[Wiki]: https://github.com/Andre601/JavaBotBlockAPI/wiki |
| 7 | +[Javadocs]: https://Andre601.github.io/jbba-doc |
| 8 | + |
| 9 | +[BadgeDownload]: https://api.bintray.com/packages/andre601/maven/JavaBotBlockAPI/images/download.svg |
| 10 | +[Download]: https://bintray.com/andre601/maven/JavaBotBlockAPI/_latestVersion |
| 11 | + |
| 12 | +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. |
| 13 | +This wrapper is a fork of [BotBlock4J] and was updated and improved to make it as userfriendly as possible. |
| 14 | + |
| 15 | +# Installation |
| 16 | +[![BadgeDownload]][Download] |
| 17 | + |
| 18 | +You can install JavaBotBlockAPI through the following methods. |
| 19 | +Make sure to replace `{version}` with the above shown version. |
| 20 | + |
| 21 | +## Gradle |
| 22 | +Put this code into your `build.gradle`: |
| 23 | +```gradle |
| 24 | +repositories{ |
| 25 | + jcenter() |
| 26 | +} |
| 27 | +
|
| 28 | +dependencies{ |
| 29 | + compile group: 'com.andre601', name: 'JavaBotBlockAPI', version: '{version}' |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +## Maven |
| 34 | +For maven use this code snipped: |
| 35 | +```xml |
| 36 | +<dependencies> |
| 37 | + <dependency> |
| 38 | + <groupId>com.andre601</groupId> |
| 39 | + <artifactId>JavaBotBlockAPI</artifactId> |
| 40 | + <version>{version}</version> |
| 41 | + </dependency> |
| 42 | +</dependencies> |
| 43 | +``` |
| 44 | + |
| 45 | +# Usage |
| 46 | +To use the Wrapper you have to follow these steps. |
| 47 | + |
| 48 | +## Notes |
| 49 | +In the below examples do I use a JDA instance called `jda`. |
| 50 | +This will also work with ShardManager. |
| 51 | + |
| 52 | +## POST methods |
| 53 | +You can post you guild counts to the different Botlists using the BotBlock API. |
| 54 | + |
| 55 | +### Creating an instance of BotBlockAPI |
| 56 | +For posting your guild counts towards the BotBlock API you first need to create an instance of the BotBlockAPI class. |
| 57 | +To do this it's recommended to use `BotBlockAPI.Builder()`. |
| 58 | + |
| 59 | +Here is an example of how it could look like. |
| 60 | +```java |
| 61 | +BotBlockAPI api = new BotBlockAPI.Builder() |
| 62 | + .addAuthToken("lbots.org", "MySecretToken123") |
| 63 | + .addAuthToken("botlist.space", "MySecretToken456") |
| 64 | + .build(); |
| 65 | +``` |
| 66 | +Remember to use `.build();` at the end to create the class. |
| 67 | + |
| 68 | +### Auto Posting |
| 69 | +JavaBotBlockAPI allows you to post the guild counts automatically every X minutes. |
| 70 | +To do this, you first need to get an instance of the RequestHandler and then call `.startAutoPosting(...)`. |
| 71 | + |
| 72 | +Here is an example: |
| 73 | +```java |
| 74 | +RequestHandler handler = new RequestHandler(); |
| 75 | + |
| 76 | +// api is the instance of the BotBlockAPI |
| 77 | +handler.startAutoPosting(jda, api); |
| 78 | +``` |
| 79 | +The delay in which you post the guild counts is set through the `.setUpdateInterval(int)` method in the BotBlockAPI.Builder(). |
| 80 | + |
| 81 | +### Cancel auto posting |
| 82 | +To cancel the auto posting just call `.stopAutoPosting();` in the RequestHandler and it should cancel the scheduler. |
| 83 | + |
| 84 | +### Manually posting |
| 85 | +There are methods that allow you to post the guild counts manually. |
| 86 | +To Post your guild counts, just call the `.postGuilds(..., ...)` method in the RequestHandler. |
| 87 | + |
| 88 | +```java |
| 89 | +RequestHandler handler = new RequestHandler(); |
| 90 | + |
| 91 | +// api is the instance of the BotBlockAPI |
| 92 | +handler.postGuilds(jda, api); |
| 93 | +``` |
| 94 | + |
| 95 | +## GET methods |
| 96 | +Since version 2.0.0 of JavaBotBlockAPI can you get certain informations of a bot or the available Botlists on the BotBlock API. |
| 97 | + |
| 98 | +### All available Botlists |
| 99 | +You can call `.getBotlists()` to receive a JSONObject with all available Botlists in the BotBlockAPI. |
| 100 | + |
| 101 | +The returned JSONObject could look like this: |
| 102 | +```json |
| 103 | +{ |
| 104 | + "botlist.space": { |
| 105 | + "api_docs": "https://docs.botlist.space", |
| 106 | + "api_post": "https://api.botlist.space/v1/bots/:id", |
| 107 | + "api_field": "server_count", |
| 108 | + "api_shard_id": null, |
| 109 | + "api_shard_count": null, |
| 110 | + "api_shards": "shards", |
| 111 | + "api_get": "https://api.botlist.space/v1/bots/:id" |
| 112 | + }, |
| 113 | + "lbots.org": { |
| 114 | + "api_docs": "https://lbots.org/api/docs", |
| 115 | + "api_post": "https://lbots.org/api/v1/bots/:id/stats", |
| 116 | + "api_field": "guild_count", |
| 117 | + "api_shard_id": "shard_id", |
| 118 | + "api_shard_count": "shard_count", |
| 119 | + "api_shards": null, |
| 120 | + "api_get": null |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +### Single Botlist |
| 126 | +Calling `.getBotlist(String)` returns a specific Botlist as JSONObject. |
| 127 | +For example does `.getBotlist("lbots.org")` return the following JSONObject: |
| 128 | +```json |
| 129 | +{ |
| 130 | + "api_docs": "https://lbots.org/api/docs", |
| 131 | + "api_post": "https://lbots.org/api/v1/bots/:id/stats", |
| 132 | + "api_field": "guild_count", |
| 133 | + "api_shard_id": "shard_id", |
| 134 | + "api_shard_count": "shard_count", |
| 135 | + "api_shards": null, |
| 136 | + "api_get": null |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +### Complete Botinfo |
| 141 | +Calling `.getAll(...)` returns a JSONObject from all the botlists and with some general information. |
| 142 | + |
| 143 | +The JSONObject can look like this: |
| 144 | +```json |
| 145 | +{ |
| 146 | + "id": "123456789012345678", |
| 147 | + "name": "MyBot", |
| 148 | + "discriminator": "1234", |
| 149 | + "owners": [ |
| 150 | + "234567890123456789" |
| 151 | + ], |
| 152 | + "server_count": 100, |
| 153 | + "invite": "https://discordapp.com/oauth2/authorize?client_id=123456789012345678&scope=bot", |
| 154 | + "list_data": { |
| 155 | + "botlist.space": [ |
| 156 | + <data>, |
| 157 | + 200 |
| 158 | + ], |
| 159 | + "lbots.org": [ |
| 160 | + <data>, |
| 161 | + 404 |
| 162 | + ] |
| 163 | + } |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +`<data>` is the JSON that is returned by the provided Botlist meaning it's different for each site. |
| 168 | +`name`, `owners`, `server_count` and `invite` is based on the most common appearances of the data. |
| 169 | + |
| 170 | +### Botinfo from all Botlists |
| 171 | +You can call `.getBotInfos(...)` to only receive the bot info from all the Botlists. |
| 172 | + |
| 173 | +The returned JSONObject can look like this: |
| 174 | +```json |
| 175 | +{ |
| 176 | + "botlist.space": [ |
| 177 | + <data>, |
| 178 | + 200 |
| 179 | + ], |
| 180 | + "lbots.org": [ |
| 181 | + <data>, |
| 182 | + 404 |
| 183 | + ] |
| 184 | +} |
| 185 | +``` |
| 186 | +`<data>` is the JSON that is returned by the provided Botlist meaning it's different for each site. |
| 187 | + |
| 188 | +### Botinfo of a single site |
| 189 | +With `.getBotInfo(..., String)` can you receive the info of a specific site. |
| 190 | +The returned data depends on the selected site and can be different for each one. |
| 191 | + |
| 192 | +### Owners |
| 193 | +You can call `.getOwners(...)` to get the owners of a Bot from all the Botlists. |
| 194 | +The info is returned as JSONArray and is based on how often the info is provided by the botlists. |
| 195 | + |
| 196 | +## Exceptions |
| 197 | +When you post the guild counts you could encounter certain Exceptions. |
| 198 | +You can receive the following exceptions: |
| 199 | +- `IOException` |
| 200 | +The Request couldn't be performed properly. This can be f.e. the case when BotBlock.org denies access (403). |
| 201 | +- `RatelimitedException` |
| 202 | +When we exceed the ratelimit of BotBlock.org |
| 203 | +This shouldn't be the case with auto-posting since it has a minimum delay of 1 minute. |
| 204 | +- `NullPointerException` |
| 205 | +Thrown when BotBlock.org sends an empty response, meaning something got messed up on their side. |
| 206 | + |
| 207 | +# Links |
| 208 | +Here are some useful links: |
| 209 | +- [BotBlock.org][BotBlock] Site for which this wrapper was made. |
| 210 | + - [API] API documentation. |
| 211 | +- [Wiki] Contains additional information on how you can use JavaBotBlockAPI. |
| 212 | +- [Javadocs] Java documentation of the Wrapper. |
| 213 | +- [BotBlock4J] Original Wrapper from which this one originates. |
0 commit comments