|
| 1 | +# JavaBotBlockAPI |
| 2 | +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. |
| 3 | +This wrapper is a fork of [BotBlock4J] and was updated and improved to make it as userfriendly as possible. |
| 4 | + |
| 5 | +## Installation |
| 6 | +You can install JavaBotBlockAPI through the following methods. |
| 7 | +Make sure to replace `{version}` with the above shown version. |
| 8 | + |
| 9 | +### Gradle |
| 10 | +Put this code into your `build.gradle`: |
| 11 | +```gradle |
| 12 | +repositories{ |
| 13 | + jcenter() |
| 14 | +} |
| 15 | +
|
| 16 | +dependencies{ |
| 17 | + compile group: 'com.andre601', name: 'JavaBotBlockAPI', version: '{version}' |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +### Maven |
| 22 | +For maven use this code snipped: |
| 23 | +```xml |
| 24 | +<repositories> |
| 25 | + <repository> |
| 26 | + <id>jcenter</id> |
| 27 | + <url>https://jcenter.bintray.com</url> |
| 28 | + </repository> |
| 29 | +</repositories> |
| 30 | + |
| 31 | +<dependencies> |
| 32 | + <dependency> |
| 33 | + <groupId>com.andre601</groupId> |
| 34 | + <artifactId>JavaBotBlockAPI</artifactId> |
| 35 | + <version>{version}</version> |
| 36 | + </dependency> |
| 37 | +</dependencies> |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | +To use the Wrapper you have to follow these steps. |
| 42 | + |
| 43 | +### Notes |
| 44 | +In the below examples do I use a JDA instance called `jda`. |
| 45 | +This will also work with ShardManager. |
| 46 | + |
| 47 | +### Creating a BotBlockAPI instance |
| 48 | +You first need to create an instance of the BotBlockAPI class. |
| 49 | +This class is the center of everything, including on what sites you want to post your guild counts. |
| 50 | + |
| 51 | +You can use the internal Builder class of BotBlockAPI to create an instance. It would look something like this: |
| 52 | +```java |
| 53 | +// Creating an instance of BotBlockAPI using BotBlockAPI.Builder |
| 54 | +BotBlockAPI api = new BotBlockAPI.Builder(jda) // We can provide either a instance of JDA or ShardManager |
| 55 | + .addAuthToken("lbots.org", "MySecretToken123") // Adds a site with the corresponding API token. |
| 56 | + .addAuthToken("botlist.space", "MySecretToken456") // The builder allows chaining of the methods. |
| 57 | + .build(); |
| 58 | +``` |
| 59 | + |
| 60 | +#### Notes |
| 61 | +`new BotBlockAPI.Builder()` allows you to provide either a JDA instance, a ShardManager instance or none at all. |
| 62 | +You can define a JDA or ShardManager instance at a later point with `.setJDA(JDA)` or `.setShardManager(ShardManager)` respectively. |
| 63 | + |
| 64 | +Also note that when you don't provide any instance, that you have to use `disableJDA(true)` or else you'll receive an NullPointerException. |
| 65 | +There are also a lot of other methods that you can use. Head over to the [wiki] for more information. |
| 66 | + |
| 67 | +### Creating a RequestHandler instance |
| 68 | +The next step after creating an instance of the BotBlockAPI is to create an instance of the Request Handler. |
| 69 | + |
| 70 | +This example shows the easiest one to use, but there are much more ways you can set it. Check the [Wiki] for examples. |
| 71 | +```java |
| 72 | +// We previously created a BotBlockAPI instance called api which we now use here. |
| 73 | +RequestHandler handler = new RequestHandler(api); |
| 74 | +``` |
| 75 | + |
| 76 | +### Posting the guild counts |
| 77 | +This step depends on what You previously set for the BotBlockAPI and the RequestHandler since some methods are only available for certain cases. |
| 78 | + |
| 79 | +**All methods require BotBlockAPI to be setup, meaning you have AT LEAST added one site and token!** |
| 80 | + |
| 81 | +#### Auto-posting |
| 82 | +The Wrapper comes with an inbuilt auto-post that allows you to easily post the guild counts without worrying too much. |
| 83 | +However, this method is limited to JDA and ShardManager only so you have to define them for using this. |
| 84 | + |
| 85 | +To auto-post guild counts you just need to call `RequestHandler#startAutoPosting();` |
| 86 | +This would look like this: |
| 87 | +```java |
| 88 | +// We previously defined a RequestHandler called handler |
| 89 | +handler.startAutoPosting(); |
| 90 | +``` |
| 91 | + |
| 92 | +Easy right? But what if you want to stop the auto-posting? |
| 93 | +For that simply use `Request#stopAutoPosting();`. Here is another example: |
| 94 | +```java |
| 95 | +// We previously defined a RequestHandler called handler |
| 96 | +handler.stopAutoPosting(); |
| 97 | +``` |
| 98 | + |
| 99 | +Note thet the delay in which you post to the API is defined through the BotBlockAPI. |
| 100 | +Use `BotBlockAPI.Builder#setUpdateInterval(Integer)` to define a delay. It is counted in minutes and default is 30. |
| 101 | + |
| 102 | +#### Manual posting |
| 103 | +If you want to post the guild counts manually you can use the following method: |
| 104 | +```java |
| 105 | +// We previously defined a RequestHandler called handler |
| 106 | +handler.postGuilds(); |
| 107 | +``` |
| 108 | + |
| 109 | +### Exceptions |
| 110 | +When you post the guild counts you could encounter certain Exceptions. |
| 111 | +You can receive the following exceptions: |
| 112 | +- `IOException` |
| 113 | +The Request couldn't be performed properly. This can be f.e. the case when BotBlock.org denies access (403). |
| 114 | +- `RatelimitedException` |
| 115 | +When we exceed the ratelimit of BotBlock.org |
| 116 | +This shouldn't be the case with auto-posting since it has a minimum delay of 1 minute. |
| 117 | +- `NullPointerException` |
| 118 | +Thrown when BotBlock.org sends an empty response, meaning something got messed up on their side. |
| 119 | + |
| 120 | +## Links |
| 121 | +Here are some useful links: |
| 122 | +- [BotBlock.org] Site for which this wrapper was made. |
| 123 | + - [API] API documentation. |
| 124 | +- [Wiki] Contains additional information on how you can use JavaBotBlockAPI. |
| 125 | +- [BotBlock4J] Original Wrapper from which this one originates. |
0 commit comments