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