Skip to content

Commit

Permalink
Fix ratelimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 25, 2024
1 parent 3a4baa6 commit a0e3354
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "2.0.21"
mikbot = "3.37.10"
mikbot = "3.37.12"
ktor = "3.0.0"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/space/votebot/core/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class VoteBotModule : Extension() {

event<ReadyEvent> {
action {
//rescheduleAllPollExpires(kord)
rescheduleAllPollExpires(kord)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import dev.kord.common.annotation.KordUnsafe
import dev.kord.common.entity.Snowflake
import dev.kord.core.Kord
import dev.schlaubi.mikbot.core.health.Config
import dev.schlaubi.mikbot.plugin.api.config.Environment
import dev.schlaubi.mikbot.plugin.api.pluginSystem
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.datetime.Clock
Expand All @@ -18,15 +18,17 @@ import org.litote.kmongo.eq
import org.litote.kmongo.not
import space.votebot.common.models.FinalPollSettings
import space.votebot.common.models.Poll
import dev.schlaubi.mikbot.plugin.api.config.Config as BotConfig

internal val ExpirationScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val expirationCache = mutableMapOf<String, Job>()

suspend fun rescheduleAllPollExpires(kord: Kord) = coroutineScope {
if (Config.POD_ID != 0 || !Config.ENABLE_SCALING || BotConfig.ENVIRONMENT != Environment.PRODUCTION)
VoteBotDatabase.polls.find(and(not(Poll::settings / FinalPollSettings::deleteAfter eq null), Poll::excludedFromScheduling eq false))
.toFlow()
.filter {
if (it.guildId == null) kord.gateway.gateways.containsKey(0)
else ((it.guildId!! shr 22) % kord.resources.shards.totalShards.toUInt()).toInt() in kord.gateway.gateways.keys
}
.onEach { poll ->
poll.addExpirationListener(kord)
}.launchIn(this)
Expand Down

0 comments on commit a0e3354

Please sign in to comment.