All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.internal.commands.ratelimit.declaration.RateLimitDeclarationRunner.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
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" }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy