Class PostAction
- java.lang.Object
-
- org.botblock.javabotblockapi.jda.PostAction
-
public class PostAction extends Object
Class used to perform POST requests towards the /api/count endpoint of BotBlock using the JDA Library.The class offers options to post either
manuallyorautomatically.
It also allows you to choose, if you want to use aJDA instanceor aShardManager instance.If you want to post without using either instance, use the
normal PostAction.
-
-
Constructor Summary
Constructors Constructor Description PostAction(JDA jda)Creates a new instance of this class.PostAction(ShardManager shardManager)Creates a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableAutoPost()Disables the automatic posting of Stats.voiddisableAutoPost(long time, TimeUnit timeUnit)Disables the automatic posting of Stats.voiddisableAutoPost(BotBlockAPI botBlockAPI)Disables the automatic posting of Stats.voidenableAutoPost(JDA jda, BotBlockAPI botBlockAPI)Starts ascheduleAtFixedRatetask, which will post the statistics of the providedJDA instanceevery n minutes.voidenableAutoPost(ShardManager shardManager, BotBlockAPI botBlockAPI)Starts ascheduleAtFixedRatetask, which will post the statistics of the providedShardManager instanceevery n minutes.voidpostGuilds(JDA jda, BotBlockAPI botBlockAPI)Performs a POST request towards the BotBlock API using the information from the providedJDAandBotBlockAPIinstances.voidpostGuilds(ShardManager shardManager, BotBlockAPI botBlockAPI)Performs a POST request towards the BotBlock API using the information from the providedShardManagerandBotBlockAPIinstances.
-
-
-
Constructor Detail
-
PostAction
public PostAction(@Nonnull ShardManager shardManager)
Creates a new instance of this class.
This will set the UserAgent used for POST requests to<botname>-<discriminator>/<api-version> (JDA) DBots/<id>using the providedShardManager instance.- Parameters:
shardManager- TheShardManager instanceused to set the UserAgent.
-
PostAction
public PostAction(@Nonnull JDA jda)
Creates a new instance of this class.
This will set the UserAgent used for POST requests to<botname>-<discriminator>/<api-version> (JDA) DBots/<id>using the providedJDA instance.- Parameters:
jda- TheJDA instanceused to set the UserAgent.
-
-
Method Detail
-
disableAutoPost
public void disableAutoPost()
Disables the automatic posting of Stats.
This essentially just performs aScheduledExecutorService.shutdown()by calling thedisableAutoPost(null)method.Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
If you want to wait for the tasks to complete usedisableAutoPost(BotBlockAPI)ordisableAutoPost(long, TimeUnit)instead.- See Also:
ExecutorService.shutdown()
-
disableAutoPost
public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI)
Disables the automatic posting of Stats.
UnlikedisableAutoPost()can you make the scheduler wait for all scheduled tasks to finish, or to time out after n minutes by providing theBotBlock instance.Passing null as argument will just perform a
ScheduledExecutorService.shutdown()similar to what the disableAutoPost() method does.If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
disableAutoPost(long, TimeUnit)instead.This method may throw a
InterruptedExceptionin the terminal.- Parameters:
botBlockAPI- TheBotBlockAPI instanceor null to just perform a shutdown.- Since:
- 6.0.0
- See Also:
ExecutorService.shutdown(),ExecutorService.awaitTermination(long, TimeUnit)
-
disableAutoPost
public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit)Disables the automatic posting of Stats.
UnlikedisableAutoPost()can you make the scheduler wait for all scheduled tasks to finish, or to time out after a specified time frame.This method may throw a
InterruptedExceptionin the terminal.Following Exceptions can be thrown from the CheckUtil:
IllegalStateException- When the provided time param is 0 or lower.
- Parameters:
time- The amount of time to wait for scheduled executions to finish before the Scheduler would time out.timeUnit- TheTimeUnitto use.- Since:
- 6.0.0
- See Also:
ExecutorService.awaitTermination(long, TimeUnit)
-
enableAutoPost
public void enableAutoPost(@Nonnull JDA jda, @Nonnull BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRatetask, which will post the statistics of the providedJDA instanceevery n minutes.If the post can't be performed - either by getting a
RatelimitedExceptionor by getting anIOException- will the exception be catched and the stacktrace printed.The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the time set in
BotBlockAPI.Builder.setUpdateDelay(Integer)(default is 30 minutes).If you have a sharded bot is it recommendet to use
enableAutoPost(ShardManager, BotBlockAPI)instead.- Parameters:
jda- TheJDA instanceto post stats from.botBlockAPI- TheBotBlockAPI instanceto use.
-
enableAutoPost
public void enableAutoPost(@Nonnull ShardManager shardManager, @Nonnull BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRatetask, which will post the statistics of the providedShardManager instanceevery n minutes.If the post can't be performed - either by getting a
RatelimitedExceptionor by getting anIOException- will the exception be caught and a Stacktrace printed.The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the time set in
BotBlockAPI.Builder.setUpdateDelay(Integer)(default is 30 minutes).- Parameters:
shardManager- TheShardManager instanceto post stats from.botBlockAPI- TheBotBlockAPI instanceto use.
-
postGuilds
public void postGuilds(@Nonnull JDA jda, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException
Performs a POST request towards the BotBlock API using the information from the providedJDAandBotBlockAPIinstances.If the provided JDA instance also is part of a sharded Bot (Amount of shards is larger than 1) will the request also include
shard_idandshard_count- Parameters:
jda- TheJDA instanceto post stats from.botBlockAPI- TheBotBlockAPI instanceto use.- Throws:
IOException- When the POST request wasn't successful.RateLimitedException- When we get rate limited by the BotBlock API (returns error code 429).
-
postGuilds
public void postGuilds(@Nonnull ShardManager shardManager, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException
Performs a POST request towards the BotBlock API using the information from the providedShardManagerandBotBlockAPIinstances.The following Exceptions may be thrown by the CheckUtil:
IllegalStateException- if the first shard of the provided ShardManager is null.
- Parameters:
shardManager- TheShardManager instanceto post stats from.botBlockAPI- TheBotBlockAPI instanceto use.- Throws:
IOException- When the POST request wasn't successful.RateLimitedException- When we get rate limited by the BotBlock API (returns error code 429).
-
-