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

io.github.freya022.botcommands.internal.commands.text.TextCommandsBuilder.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.22
Show newest version
package io.github.freya022.botcommands.internal.commands.text

import io.github.freya022.botcommands.api.commands.text.provider.TextCommandManager
import io.github.freya022.botcommands.api.commands.text.provider.TextCommandProvider
import io.github.freya022.botcommands.api.core.annotations.BEventListener
import io.github.freya022.botcommands.api.core.events.FirstGuildReadyEvent
import io.github.freya022.botcommands.api.core.service.annotations.BService
import io.github.freya022.botcommands.api.core.service.getInterfacedServices
import io.github.freya022.botcommands.internal.core.BContextImpl
import io.github.oshai.kotlinlogging.KotlinLogging

@BService
internal class TextCommandsBuilder {
    @BEventListener
    internal fun onFirstReady(event: FirstGuildReadyEvent, context: BContextImpl) {
        try {
            val manager = TextCommandManager(context)
            context.serviceContainer
                .getInterfacedServices()
                .forEach { textCommandProvider ->
                    textCommandProvider.declareTextCommands(manager)
                }

            manager.textCommands.map.values.forEach { context.textCommandsContext.addTextCommand(it) }
        } catch (e: Throwable) {
            KotlinLogging.logger { }.error(e) { "An error occurred while updating text commands" }
        } finally {
            context.eventDispatcher.removeEventListener(this)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy