19
19
package org .botblock .javabotblockapi .javacord ;
20
20
21
21
import org .botblock .javabotblockapi .core .BotBlockAPI ;
22
+ import org .botblock .javabotblockapi .core .CheckUtil ;
22
23
import org .botblock .javabotblockapi .core .exceptions .RatelimitedException ;
23
24
import org .botblock .javabotblockapi .requests .handler .RequestHandler ;
24
25
import org .javacord .api .DiscordApi ;
@@ -112,6 +113,11 @@ public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
112
113
* finish, or to time out after a specified time frame.
113
114
*
114
115
* <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>
115
121
*
116
122
* @param time
117
123
* 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){
121
127
* @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
122
128
*/
123
129
public void disableAutoPost (long time , @ Nonnull TimeUnit timeUnit ){
130
+ CheckUtil .condition (time <= 0 , "time may not be less or equal to 0!" );
131
+
124
132
try {
125
133
scheduler .shutdown ();
126
134
scheduler .awaitTermination (time , timeUnit );
@@ -139,16 +147,23 @@ public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
139
147
* <p>The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
140
148
* time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
141
149
* (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>
142
155
*
143
- * @param apis
156
+ * @param discordApis
144
157
* The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
145
158
* @param botBlockAPI
146
159
* The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
147
160
*/
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
+
149
164
scheduler .scheduleAtFixedRate (() -> {
150
165
try {
151
- postGuilds (botBlockAPI , apis );
166
+ postGuilds (botBlockAPI , discordApis );
152
167
}catch (IOException | RatelimitedException ex ){
153
168
ex .printStackTrace ();
154
169
}
@@ -161,8 +176,13 @@ public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi
161
176
*
162
177
* <p>If the provided DiscordApi instance is a sharded Bot (Amount of shards is larger than 1) will the request
163
178
* 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>
164
184
*
165
- * @param apis
185
+ * @param discordApis
166
186
* The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
167
187
* @param botBlockAPI
168
188
* The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
@@ -172,22 +192,24 @@ public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi
172
192
* @throws org.botblock.javabotblockapi.core.exceptions.RatelimitedException
173
193
* When we get rate limited by the BotBlock API (returns error code 429).
174
194
*/
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
+
176
198
JSONObject json = new JSONObject ()
177
- .put ("bot_id" , apis [0 ].getYourself ().getId ());
199
+ .put ("bot_id" , discordApis [0 ].getYourself ().getId ());
178
200
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 ();
181
203
json .put ("server_count" , guilds )
182
- .put ("shard_count" , apis .length );
204
+ .put ("shard_count" , discordApis .length );
183
205
184
206
List <Integer > shards = new ArrayList <>();
185
- for (DiscordApi api : apis )
207
+ for (DiscordApi api : discordApis )
186
208
shards .add (api .getServers ().size ());
187
209
188
210
json .put ("shards" , new JSONArray (Arrays .deepToString (shards .toArray ())));
189
211
}else {
190
- json .put ("server_count" , apis [0 ].getServers ().size ());
212
+ json .put ("server_count" , discordApis [0 ].getServers ().size ());
191
213
}
192
214
193
215
botBlockAPI .getTokens ().forEach (json ::put );
0 commit comments