Skip to content
This repository was archived by the owner on Jul 26, 2019. It is now read-only.

RequestHandler

Andre_601 edited this page Jun 24, 2019 · 1 revision

The RequestHandler is for handling the post requests to the BotBlock API.
When you want to post your guild counts to the sites, you have to use this class.

Creating an instance

We first need to get an instance of the class.
This is fairly simple to do. Just do the following:

RequestHandler handler = new RequestHandler();

Posting guild counts

The RequestHandler offers many options for posting the guild counts of your bot.
You can either post them completely automatic or manual, depending on what you prefer.

Auto-Posting

You can let JavaBotBlockAPI post the guild counts automatically.
To do that just call startAutoPosting(...)

This method comes in many different flavours of how you use it and what to provide.
The delay in which the Wrapper posts the guild counts depends on what you've set in the BotBlockAPI through its setUpdateInterval(int updateInterval) method.

Here's a list of all startAutoPosting methods:

// Post guild counts from the ShardManager
handler.startAutoPost(ShardManager shardManager, BotBlockAPI botBlockAPI);

// Post guild counts from the JDA
handler.startAutoPost(JDA jda, BotBlockAPI botBlockAPI);

// Post the guild count with the Bot ID
handler.startAutoPost(Long botId, int guilds, BotBlockAPI botBlockAPI);

// Post the guild count with the Bot ID
handler.startAutoPost(String botId, int guilds, BotBlockAPI botBlockAPI);

Manual posting

If you want to use your own update method and want to manually post your guild counts, you can do that by simply calling the postGuilds(...) method.
Like with the startAutoPosting(...) method does this one here come in different flavours depending on how you want to provide the information:

// Post guild counts from the ShardManager
handler.postGuilds(ShardManager shardManager, BotBlockAPI botBlockAPI);

// Post guild counts from the JDA
handler.postGuilds(JDA jda, BotBlockAPI botBlockAPI);

// Post the guild count with the Bot ID
handler.postGuilds(Long botId, int guilds, BotBlockAPI botBlockAPI);

// Post the guild count with the Bot ID
handler.postGuilds(String botId, int guilds, BotBlockAPI botBlockAPI);

Additional notes

There are a few thing here that are worth mentioning:

  • When you use a method with JDA and the JDA-instance is sharded, then shard_id and shard_count are posted too.
  • The minimum delay for posting guild counts with startAutoPosting(...) is 2 minutes. This was made to not exceed the ratelimit of BotBlock.org which as of now is 1 request every 120 seconds (2 minutes).

Exceptions (Errors)

It can happen that the post requests encounter an exception.
This are exceptions that can occur when a post request is performed.

  • IOException
    The request couldn't be performed properly. There can be many reasons for that.
  • RatelimitedException
    Is thrown when the BotBlock API ratelimits us (Returns error code 429). The error message will tell you which route caused it, what IP and ID are affected and when you can post again.
    This should never happen with auto-posting since minimum delay is 2 minutes.
  • NullPointerException
    Thrown when BotBlock returns an empty response (body). This is rare but could happen.
Clone this wiki locally