Class PostAction
- java.lang.Object
-
- org.botblock.javabotblockapi.javacord.PostAction
-
public class PostAction extends Object
Class used to perform POST requests towards the /api/count endpoint of BotBlock using the Javacord Library.The class offers options to post either
manually
orautomatically
.If you want to post without using Javacord, use the
normal PostAction
.
-
-
Constructor Summary
Constructors Constructor Description PostAction(org.javacord.api.DiscordApi api)
Creates a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disableAutoPost()
Disables the automatic posting of Stats.void
disableAutoPost(long time, TimeUnit timeUnit)
Disables the automatic posting of Stats.void
disableAutoPost(BotBlockAPI botBlockAPI)
Disables the automatic posting of Stats.void
enableAutoPost(BotBlockAPI botBlockAPI, org.javacord.api.DiscordApi... discordApis)
Starts ascheduleAtFixedRate
task, which will post the statistics of the providedDiscordApi instance
every n minutes.void
postGuilds(BotBlockAPI botBlockAPI, org.javacord.api.DiscordApi... discordApis)
Performs a POST request towards the BotBlock API using the information from the providedDiscordApi
andBotBlock
instances.
-
-
-
Constructor Detail
-
PostAction
public PostAction(org.javacord.api.DiscordApi api)
Creates a new instance of this class.
This will set the UserAgent used for POST request to<botname>-<discriminator>/<api-version> (Javacord) DBots/<id>
using the providedDiscordApi instance
.- Parameters:
api
- TheDiscordApi instance
used 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
InterruptedException
in the terminal.- Parameters:
botBlockAPI
- TheBotBlockAPI instance
or null to just perform a shutdown.- 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
InterruptedException
in 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
- TheTimeUnit
to use.- See Also:
ExecutorService.awaitTermination(long, TimeUnit)
-
enableAutoPost
public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull org.javacord.api.DiscordApi... discordApis)
Starts ascheduleAtFixedRate
task, which will post the statistics of the providedDiscordApi instance
every n minutes.If the post can't be performed - either by getting a
RatelimitedException
or 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).Following Exceptions can be thrown from the CheckUtil:
IllegalStateException
- When the provided DiscordApis are 0 or less.
- Parameters:
discordApis
- TheDiscordApi instances
to post stats from.botBlockAPI
- TheBotBlockAPI instance
to use.
-
postGuilds
public void postGuilds(@Nonnull BotBlockAPI botBlockAPI, @Nonnull org.javacord.api.DiscordApi... discordApis) throws IOException, RateLimitedException
Performs a POST request towards the BotBlock API using the information from the providedDiscordApi
andBotBlock
instances.If the provided DiscordApi instance is a sharded Bot (Amount of shards is larger than 1) will the request contain the
shards
array alongside ashard_count
field.Following Exceptions can be thrown from the CheckUtil:
IllegalStateException
- When the provided DiscordApis are 0 or less.
- Parameters:
discordApis
- TheDiscordApi instances
to post stats from.botBlockAPI
- TheBotBlockAPI instance
to use.- Throws:
IOException
- When the POST request wasn't successful.RateLimitedException
- When we get rate limited by the BotBlock API (returns error code 429).
-
-