@@ -234,6 +234,44 @@ open class DiscordBot(
234
234
return alunaProperties.nodeNumber
235
235
}
236
236
237
+ /* *
238
+ * Get the lower bound of Snowflakes.
239
+ *
240
+ * This method calculates the lower bound of Snowflakes based on the sharding configuration.
241
+ *
242
+ * @return The lower bound of Snowflakes as a [Long] value.
243
+ */
244
+ fun getLowerBoundOfSnowflake (): Long {
245
+ return if (alunaProperties.discord.sharding.type == AlunaDiscordProperties .Sharding .Type .SUBSET ) {
246
+ alunaProperties.discord.sharding.fromShard * (Long .MAX_VALUE / alunaProperties.discord.sharding.totalShards)
247
+ } else {
248
+ 0L
249
+ }
250
+ }
251
+
252
+ /* *
253
+ * Get the upper bound of Snowflakes.
254
+ *
255
+ * This method calculates the upper bound ofSnowflakes based on the sharding configuration.
256
+ *
257
+ * @return The upper bound of Snowflakes as a [Long] value.
258
+ */
259
+ fun getUpperBoundOfSnowflake (): Long {
260
+ return if (alunaProperties.discord.sharding.type == AlunaDiscordProperties .Sharding .Type .SUBSET ) {
261
+ (alunaProperties.discord.sharding.fromShard + alunaProperties.discord.sharding.shardAmount) * (Long .MAX_VALUE / alunaProperties.discord.sharding.totalShards) - 1
262
+ } else {
263
+ Long .MAX_VALUE
264
+ }
265
+ }
266
+
267
+ fun getShardBySnowflake (snowflake : Long ): Long {
268
+ return (snowflake shr 22 ) % alunaProperties.discord.sharding.totalShards
269
+ }
270
+
271
+ fun getShardOfBotDM (): Long {
272
+ return alunaProperties.discord.applicationId?.let { getShardBySnowflake(it.toLong()) } ? : throw IllegalArgumentException (" alunaProperties.discord.applicationId is not set" )
273
+ }
274
+
237
275
/* *
238
276
* Register a message for button events. If such an event happens, Aluna will trigger the onButtonInteraction method of the interaction handler.
239
277
*
@@ -293,9 +331,7 @@ open class DiscordBot(
293
331
authorIds : ArrayList <String >? = null,
294
332
interactionUserOnly : Boolean = false
295
333
) {
296
- hook.retrieveOriginal()
297
- .queue { registerMessageForButtonEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
298
-
334
+ hook.retrieveOriginal().queue { registerMessageForButtonEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
299
335
}
300
336
301
337
/* *
@@ -357,8 +393,7 @@ open class DiscordBot(
357
393
authorIds : ArrayList <String >? = null,
358
394
interactionUserOnly : Boolean = false
359
395
) {
360
- hook.retrieveOriginal()
361
- .queue { registerMessageForStringSelectEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
396
+ hook.retrieveOriginal().queue { registerMessageForStringSelectEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
362
397
}
363
398
364
399
/* *
@@ -420,8 +455,7 @@ open class DiscordBot(
420
455
authorIds : ArrayList <String >? = null,
421
456
interactionUserOnly : Boolean = false
422
457
) {
423
- hook.retrieveOriginal()
424
- .queue { registerMessageForEntitySelectEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
458
+ hook.retrieveOriginal().queue { registerMessageForEntitySelectEvents(it.id, interaction, multiUse, duration, authorIds, interactionUserOnly) }
425
459
}
426
460
427
461
/* *
0 commit comments