diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt index 0e830cb..63f25c0 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt @@ -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 diff --git a/common/src/main/kotlin/space/mori/chzzk_bot/common/events/EventBase.kt b/common/src/main/kotlin/space/mori/chzzk_bot/common/events/EventBase.kt index 6b602da..f847082 100644 --- a/common/src/main/kotlin/space/mori/chzzk_bot/common/events/EventBase.kt +++ b/common/src/main/kotlin/space/mori/chzzk_bot/common/events/EventBase.kt @@ -3,7 +3,7 @@ package space.mori.chzzk_bot.common.events interface Event interface EventHandler { - 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 dispatch(event: E) { + fun dispatch(event: E) { handlers[event::class.java]?.forEach { (it as EventHandler).handle(event) } } } \ No newline at end of file diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSTimerRoutes.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSTimerRoutes.kt index 3d5c1e1..832a1db 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSTimerRoutes.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSTimerRoutes.kt @@ -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 { - 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 ?: "")) + } } }) }