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

io.github.freya022.botcommands.internal.conditions.RequiredIntentsChecker.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.conditions

import io.github.freya022.botcommands.api.core.BContext
import io.github.freya022.botcommands.api.core.JDAService
import io.github.freya022.botcommands.api.core.conditions.RequiredIntents
import io.github.freya022.botcommands.api.core.service.CustomConditionChecker
import io.github.freya022.botcommands.api.core.service.getServiceOrNull
import io.github.freya022.botcommands.api.core.utils.simpleNestedName
import io.github.freya022.botcommands.internal.utils.annotationRef

internal object RequiredIntentsChecker : CustomConditionChecker {
    override val annotationType: Class = RequiredIntents::class.java

    override fun checkServiceAvailability(
        context: BContext,
        checkedClass: Class<*>,
        annotation: RequiredIntents
    ): String? {
        val jdaService = context.getServiceOrNull()
        checkNotNull(jdaService) {
            "A JDAService instance must be present in order to use ${annotationRef()}"
        }

        val missingIntents = annotation.intents.asList() - jdaService.intents
        if (missingIntents.isNotEmpty()) {
            return "${checkedClass.simpleNestedName} requires missing intents: $missingIntents"
        }

        return null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy