diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt index 59c1622..d890fcd 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt @@ -54,6 +54,9 @@ object ChzzkHandler { addUser(channel, user) } } + dispatcher.subscribe(CommandReloadEvent::class) { + handlers.firstOrNull { handlers -> handlers.channel.channelId == it.uid }?.reloadCommand() + } } fun disable() { diff --git a/common/src/main/kotlin/space/mori/chzzk_bot/common/events/CommandReloadEvent.kt b/common/src/main/kotlin/space/mori/chzzk_bot/common/events/CommandReloadEvent.kt new file mode 100644 index 0000000..5f5740c --- /dev/null +++ b/common/src/main/kotlin/space/mori/chzzk_bot/common/events/CommandReloadEvent.kt @@ -0,0 +1,7 @@ +package space.mori.chzzk_bot.common.events + +data class CommandReloadEvent( + val uid: String +): Event { + val TAG = javaClass.simpleName +} \ No newline at end of file diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt index 9c5f5b2..e6a614c 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/Main.kt @@ -97,7 +97,7 @@ val server = embeddedServer(Netty, port = 8080, ) { } } } - call.respondRedirect(dotenv["FRONTEND"]) + call.respondRedirect("${ if(dotenv["FRONTEND_HTTPS"].toBoolean()) "https://" else "http://" }${dotenv["FRONTEND"]}") } } get("/logout") { diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiCommandRoutes.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiCommandRoutes.kt index df815ab..8bd61c9 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiCommandRoutes.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiCommandRoutes.kt @@ -6,12 +6,20 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.server.sessions.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kotlinx.serialization.Serializable +import org.koin.java.KoinJavaComponent.inject +import space.mori.chzzk_bot.common.events.CommandReloadEvent +import space.mori.chzzk_bot.common.events.CoroutinesEventBus import space.mori.chzzk_bot.common.services.CommandService import space.mori.chzzk_bot.common.services.UserService import space.mori.chzzk_bot.webserver.UserSession fun Routing.apiCommandRoutes() { + val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) + route("/commands") { get("/{uid}") { val uid = call.parameters["uid"] @@ -52,6 +60,9 @@ fun Routing.apiCommandRoutes() { commandRequest.content, commandRequest.failContent ?: "" ) + CoroutineScope(Dispatchers.Default).launch { + dispatcher.post(CommandReloadEvent(user.token ?: "")) + } call.respond(HttpStatusCode.OK) } @@ -76,6 +87,9 @@ fun Routing.apiCommandRoutes() { commandRequest.content, commandRequest.failContent ?: "" ) + CoroutineScope(Dispatchers.Default).launch { + dispatcher.post(CommandReloadEvent(user.token ?: "")) + } call.respond(HttpStatusCode.OK) } catch(e: Exception) { call.respond(HttpStatusCode.BadRequest) @@ -98,6 +112,9 @@ fun Routing.apiCommandRoutes() { try { CommandService.removeCommand(user, commandRequest.label) + CoroutineScope(Dispatchers.Default).launch { + dispatcher.post(CommandReloadEvent(user.token ?: "")) + } call.respond(HttpStatusCode.OK) } catch(e: Exception) { call.respond(HttpStatusCode.BadRequest)