mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-08 05:11:12 +00:00
add botIsDisabled, welcomeMessageDisabled.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package space.mori.chzzk_bot.webserver.routes
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
@@ -41,13 +40,19 @@ data class GetSessionDTO(
|
||||
val isDisabled: Boolean
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GetSettingDTO(
|
||||
val isBotDisabled: Boolean,
|
||||
val isBotMsgDisabled: Boolean,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class RegisterChzzkUserDTO(
|
||||
val chzzkUrl: String
|
||||
)
|
||||
|
||||
fun Routing.apiRoutes() {
|
||||
val chzzkIDRegex = """(?:.+chzzk\.naver\.com\/)?([a-f0-9]{32})(?:.+)?""".toRegex()
|
||||
val chzzkIDRegex = """(?:.+chzzk\.naver\.com/)?([a-f0-9]{32})(?:.+)?""".toRegex()
|
||||
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||
|
||||
route("/") {
|
||||
@@ -183,4 +188,46 @@ fun Routing.apiRoutes() {
|
||||
return@post
|
||||
}
|
||||
}
|
||||
|
||||
route("/settings") {
|
||||
get {
|
||||
val session = call.sessions.get<UserSession>()
|
||||
if(session == null) {
|
||||
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
|
||||
return@get
|
||||
}
|
||||
|
||||
val user = UserService.getUserWithNaverId(session.id)
|
||||
if(user == null) {
|
||||
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
|
||||
return@get
|
||||
}
|
||||
|
||||
call.respond(GetSettingDTO(
|
||||
user.isDisabled, user.isDisableStartupMsg
|
||||
))
|
||||
}
|
||||
post {
|
||||
val session = call.sessions.get<UserSession>()
|
||||
if(session == null) {
|
||||
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
|
||||
return@post
|
||||
}
|
||||
|
||||
val body: GetSettingDTO = call.receive()
|
||||
|
||||
val user = UserService.getUserWithNaverId(session.id)
|
||||
if(user == null) {
|
||||
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
|
||||
return@post
|
||||
}
|
||||
|
||||
UserService.setIsDisabled(user, body.isBotDisabled)
|
||||
UserService.setIsStartupDisabled(user, body.isBotMsgDisabled)
|
||||
|
||||
call.respond(GetSettingDTO(
|
||||
user.isDisabled, user.isDisableStartupMsg
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user