io.github.freya022.botcommands.internal.commands.ratelimit.declaration.RateLimitDeclarationRunner.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of BotCommands Show documentation
Show all versions of BotCommands Show documentation
A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.
package io.github.freya022.botcommands.internal.commands.ratelimit.declaration
import io.github.freya022.botcommands.api.commands.ratelimit.declaration.RateLimitProvider
import io.github.freya022.botcommands.api.core.BContext
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.utils.joinAsList
import io.github.freya022.botcommands.internal.commands.ratelimit.RateLimitContainer
import io.github.oshai.kotlinlogging.KotlinLogging
private val logger = KotlinLogging.logger { }
@BService(priority = 1) //Higher than all command declarations
internal class RateLimitDeclarationRunner internal constructor(
context: BContext,
rateLimitProviders: List,
rateLimitContainer: RateLimitContainer
) {
init {
val manager = RateLimitManagerImpl(context)
rateLimitProviders.forEach { it.declareRateLimit(manager) }
if (logger.isTraceEnabled()) {
logger.trace {
val declarations = rateLimitContainer.allInfos.joinAsList { it.declarationSite.toString() }
"Registered ${rateLimitContainer.size} rate limiters:\n$declarations"
}
} else {
logger.debug { "Registered ${rateLimitContainer.size} rate limiters" }
}
}
}