1919package org .botblock .javabotblockapi .javacord ;
2020
2121import org .botblock .javabotblockapi .core .BotBlockAPI ;
22+ import org .botblock .javabotblockapi .core .CheckUtil ;
2223import org .botblock .javabotblockapi .core .exceptions .RatelimitedException ;
2324import org .botblock .javabotblockapi .requests .handler .RequestHandler ;
2425import org .javacord .api .DiscordApi ;
@@ -112,6 +113,11 @@ public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
112113 * finish, or to time out after a specified time frame.
113114 *
114115 * <p>This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
116+ *
117+ * <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
118+ * <ul>
119+ * <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided time param is 0 or lower.</li>
120+ * </ul>
115121 *
116122 * @param time
117123 * The amount of time to wait for scheduled executions to finish before the Scheduler would time out.
@@ -121,6 +127,8 @@ public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
121127 * @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
122128 */
123129 public void disableAutoPost (long time , @ Nonnull TimeUnit timeUnit ){
130+ CheckUtil .condition (time <= 0 , "time may not be less or equal to 0!" );
131+
124132 try {
125133 scheduler .shutdown ();
126134 scheduler .awaitTermination (time , timeUnit );
@@ -139,16 +147,23 @@ public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
139147 * <p>The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
140148 * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
141149 * (default is 30 minutes).
150+ *
151+ * <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
152+ * <ul>
153+ * <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided DiscordApis are 0 or less.</li>
154+ * </ul>
142155 *
143- * @param apis
156+ * @param discordApis
144157 * The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
145158 * @param botBlockAPI
146159 * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
147160 */
148- public void enableAutoPost (@ Nonnull BotBlockAPI botBlockAPI , @ Nonnull DiscordApi ... apis ){
161+ public void enableAutoPost (@ Nonnull BotBlockAPI botBlockAPI , @ Nonnull DiscordApi ... discordApis ){
162+ CheckUtil .condition (discordApis .length <= 0 , "At least one DiscordApi instance needs to be provided!" );
163+
149164 scheduler .scheduleAtFixedRate (() -> {
150165 try {
151- postGuilds (botBlockAPI , apis );
166+ postGuilds (botBlockAPI , discordApis );
152167 }catch (IOException | RatelimitedException ex ){
153168 ex .printStackTrace ();
154169 }
@@ -161,8 +176,13 @@ public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi
161176 *
162177 * <p>If the provided DiscordApi instance is a sharded Bot (Amount of shards is larger than 1) will the request
163178 * contain the {@code shards} array alongside a {@code shard_count} field.
179+ *
180+ * <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
181+ * <ul>
182+ * <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided DiscordApis are 0 or less.</li>
183+ * </ul>
164184 *
165- * @param apis
185+ * @param discordApis
166186 * The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
167187 * @param botBlockAPI
168188 * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
@@ -172,22 +192,24 @@ public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi
172192 * @throws org.botblock.javabotblockapi.core.exceptions.RatelimitedException
173193 * When we get rate limited by the BotBlock API (returns error code 429).
174194 */
175- public void postGuilds (@ Nonnull BotBlockAPI botBlockAPI , @ Nonnull DiscordApi ... apis ) throws IOException , RatelimitedException {
195+ public void postGuilds (@ Nonnull BotBlockAPI botBlockAPI , @ Nonnull DiscordApi ... discordApis ) throws IOException , RatelimitedException {
196+ CheckUtil .condition (discordApis .length <= 0 , "At least one DiscordApi instance needs to be provided!" );
197+
176198 JSONObject json = new JSONObject ()
177- .put ("bot_id" , apis [0 ].getYourself ().getId ());
199+ .put ("bot_id" , discordApis [0 ].getYourself ().getId ());
178200
179- if (apis .length > 1 ){
180- int guilds = Arrays .stream (apis ).map (DiscordApi ::getServers ).mapToInt (Collection ::size ).sum ();
201+ if (discordApis .length > 1 ){
202+ int guilds = Arrays .stream (discordApis ).map (DiscordApi ::getServers ).mapToInt (Collection ::size ).sum ();
181203 json .put ("server_count" , guilds )
182- .put ("shard_count" , apis .length );
204+ .put ("shard_count" , discordApis .length );
183205
184206 List <Integer > shards = new ArrayList <>();
185- for (DiscordApi api : apis )
207+ for (DiscordApi api : discordApis )
186208 shards .add (api .getServers ().size ());
187209
188210 json .put ("shards" , new JSONArray (Arrays .deepToString (shards .toArray ())));
189211 }else {
190- json .put ("server_count" , apis [0 ].getServers ().size ());
212+ json .put ("server_count" , discordApis [0 ].getServers ().size ());
191213 }
192214
193215 botBlockAPI .getTokens ().forEach (json ::put );
0 commit comments