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.
You can install JavaBotBlockAPI through the following methods.
Make sure to replace {version} with the above shown version.
Put this code into your build.gradle:
repositories{
maven { url = 'https://dl.bintray.com/andre601/maven' }
}
dependencies{
compile group: 'com.andre601', name: 'JavaBotBlockAPI', version: '{version}'
}For maven use this code snipped:
<repositories>
<repository>
<id>jcenter</id>
<url>https://dl.bintray.com/andre601/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.andre601</groupId>
<artifactId>JavaBotBlockAPI</artifactId>
<version>{version}</version>
</dependency>
</dependencies>To use the Wrapper you have to follow these steps.
In the below examples do I use a JDA instance called jda.
This will also work with ShardManager.
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.
You can use the internal Builder class of BotBlockAPI to create an instance. It would look something like this:
// 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.
.build();There are a lot of other methods that you can use. Head over to the Wiki for more information.
You can post the guilds eithe automatically or manually depending on your own preferences.
JavaBotBlockAPI comes with an inbuild scheduler to post yout 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.
Example:
// 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.
handler.startAutoPosting(jda, api);But what if you want to stop it?
For that just call the stopAutoPosting method:
handler.stopAutoPosting();
If you want to post the guild counts manually you can use the postGuilds method.
// 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.
handler.postGuilds(jda, api);When you post the guild counts you could encounter certain Exceptions.
You can receive the following exceptions:
IOException
The Request couldn't be performed properly. This can be f.e. the case when BotBlock.org denies access (403).RatelimitedException
When we exceed the ratelimit of BotBlock.org
This shouldn't be the case with auto-posting since it has a minimum delay of 1 minute.NullPointerException
Thrown when BotBlock.org sends an empty response, meaning something got messed up on their side.
Here are some useful links:
- BotBlock.org Site for which this wrapper was made.
- API API documentation.
- Wiki Contains additional information on how you can use JavaBotBlockAPI.
- BotBlock4J Original Wrapper from which this one originates.