debug some codes.

This commit is contained in:
dalbodeule 2024-08-10 00:39:23 +09:00
parent 9a91537e59
commit b12e29674a
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
4 changed files with 28 additions and 1 deletions

View File

@ -54,6 +54,9 @@ object ChzzkHandler {
addUser(channel, user)
}
}
dispatcher.subscribe(CommandReloadEvent::class) {
handlers.firstOrNull { handlers -> handlers.channel.channelId == it.uid }?.reloadCommand()
}
}
fun disable() {

View File

@ -0,0 +1,7 @@
package space.mori.chzzk_bot.common.events
data class CommandReloadEvent(
val uid: String
): Event {
val TAG = javaClass.simpleName
}

View File

@ -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") {

View File

@ -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)