mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
Merge pull request #15 from dalbodeule/develop
some change on TimerEvents.
This commit is contained in:
commit
53cefe5813
@ -38,7 +38,7 @@ class MessageHandler(
|
||||
val user = UserService.getUser(channel.channelId)
|
||||
?: throw RuntimeException("User not found. it's bug? ${channel.channelName} - ${channel.channelId}")
|
||||
val commands = CommandService.getCommands(user)
|
||||
val manageCommands = mapOf("!명령어추가" to this::manageAddCommand, "!명령어삭제" to this::manageRemoveCommand, "!명령어수정" to this::manageUpdateCommand)
|
||||
val manageCommands = mapOf("!명령어추가" to this::manageAddCommand, "!명령어삭제" to this::manageRemoveCommand, "!명령어수정" to this::manageUpdateCommand, "!시간" to this::timerCommand)
|
||||
|
||||
manageCommands.forEach { (commandName, command) ->
|
||||
this.commands[commandName] = command
|
||||
@ -112,7 +112,7 @@ class MessageHandler(
|
||||
listener.sendChat("명령어 '$command' 삭제되었습니다.")
|
||||
}
|
||||
|
||||
private suspend fun timerCommand(msg: ChatMessage, user: User) {
|
||||
private fun timerCommand(msg: ChatMessage, user: User) {
|
||||
if (msg.profile?.userRoleCode == "common_user") {
|
||||
listener.sendChat("매니저만 이 명령어를 사용할 수 있습니다.")
|
||||
return
|
||||
|
@ -3,7 +3,7 @@ package space.mori.chzzk_bot.common.events
|
||||
interface Event
|
||||
|
||||
interface EventHandler<E: Event> {
|
||||
suspend fun handle(event: E)
|
||||
fun handle(event: E)
|
||||
}
|
||||
|
||||
object EventDispatcher {
|
||||
@ -13,7 +13,7 @@ object EventDispatcher {
|
||||
handlers.computeIfAbsent(eventClass) { mutableListOf() }.add(handler)
|
||||
}
|
||||
|
||||
suspend fun <E : Event> dispatch(event: E) {
|
||||
fun <E : Event> dispatch(event: E) {
|
||||
handlers[event::class.java]?.forEach { (it as EventHandler<E>).handle(event) }
|
||||
}
|
||||
}
|
@ -3,7 +3,10 @@ package space.mori.chzzk_bot.webserver.routes
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.websocket.*
|
||||
import io.ktor.websocket.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.channels.ClosedReceiveChannelException
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.mori.chzzk_bot.common.events.Event
|
||||
import space.mori.chzzk_bot.common.events.TimerType
|
||||
@ -52,8 +55,10 @@ fun Routing.wsTimerRoutes() {
|
||||
val dispatcher = EventDispatcher
|
||||
|
||||
dispatcher.register(TimerEvent::class.java, object : EventHandler<TimerEvent> {
|
||||
override suspend fun handle(event: TimerEvent) {
|
||||
sessions[event.uid]?.sendSerialized(TimerResponse(event.type, event.time ?: ""))
|
||||
override fun handle(event: TimerEvent) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
sessions[event.uid]?.sendSerialized(TimerResponse(event.type, event.time ?: ""))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user