main.gateway.handler.GatewayEventHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-voice Show documentation
Show all versions of kord-voice Show documentation
Idiomatic Kotlin Wrapper for The Discord API
package dev.kord.voice.gateway.handler
import dev.kord.voice.gateway.VoiceEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import mu.KotlinLogging
private val logger = KotlinLogging.logger("[Handler]")
internal abstract class GatewayEventHandler(
val flow: Flow,
val name: String
) {
open suspend fun start() {}
suspend inline fun CoroutineScope.on(crossinline block: suspend (T) -> Unit) {
flow.filterIsInstance().onEach {
try {
block(it)
} catch (exception: Exception) {
logger.error(exception) { "[$name]" }
}
}.launchIn(this)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy