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

io.github.freya022.botcommands.internal.commands.ratelimit.RateLimitContainer.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

import io.github.freya022.botcommands.api.commands.ratelimit.RateLimitInfo
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.internal.utils.putIfAbsentOrThrow

@BService
internal class RateLimitContainer internal constructor() {
    private val infoByName: MutableMap = hashMapOf()

    internal val allInfos get() = infoByName.values
    internal val size get() = infoByName.size

    internal operator fun get(group: String): RateLimitInfo? = infoByName[group]

    internal operator fun contains(rateLimitGroup: String): Boolean = rateLimitGroup in infoByName

    internal operator fun set(group: String, rateLimitInfo: RateLimitInfo) {
        infoByName.putIfAbsentOrThrow(group, rateLimitInfo) {
            "A rate limiter already exists with a group of '$group'"
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy