Skip to content

Commit

Permalink
Fix ratelimit exception
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 25, 2024
1 parent 37437fe commit 1308185
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.schlaubi.mikbot.plugin.api.owner

import com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.Permission
import dev.schlaubi.mikbot.plugin.api.*
import dev.schlaubi.mikbot.plugin.api.config.Config
Expand Down Expand Up @@ -31,4 +33,6 @@ public interface OwnerExtensionPoint : ModuleExtensionPoint<OwnerModule> {
public fun SlashCommand<*, *, *>.ownerOnly() {
guildId = Config.OWNER_GUILD ?: error("Cannot register owner command without OWNER_GUILD value")
requirePermission(Permission.Administrator)
allowedContexts.add(InteractionContextType.Guild)
allowedInstallTypes.add(ApplicationIntegrationType.GuildInstall)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.datetime.toJavaInstant
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executors
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.toJavaDuration

Expand Down Expand Up @@ -85,7 +86,7 @@ class DistributedRateLimiter(proxyManager: ProxyManager<String>) : RequestRateLi
.capacity(limit.remaining.value)
.refillIntervallyAligned(
limit.total.value,
(reset.value - Clock.System.now()).coerceAtMost(Duration.ZERO).toJavaDuration(),
(reset.value - Clock.System.now()).coerceAtLeast(1.milliseconds).toJavaDuration(),
start.toJavaInstant()
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coroutines = "1.9.0"
serialization = "1.7.3"
ktor = "3.0.0"
kord = "feature-user-apps-20241022.210712-8"
api = "3.37.13"
api = "3.37.14"
ksp = "2.0.21-1.0.25"
lavakord = "7.1.0"

Expand Down

0 comments on commit 1308185

Please sign in to comment.