mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-08 05:11:12 +00:00
some fix on Manager functions.
This commit is contained in:
@@ -28,7 +28,7 @@ fun Routing.apiCommandRoutes() {
|
||||
return@get
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null ) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
@@ -49,7 +49,12 @@ fun Routing.apiCommandRoutes() {
|
||||
return@put
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@put
|
||||
}
|
||||
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@put
|
||||
}
|
||||
@@ -74,7 +79,12 @@ fun Routing.apiCommandRoutes() {
|
||||
return@post
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@post
|
||||
}
|
||||
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@post
|
||||
}
|
||||
@@ -104,7 +114,12 @@ fun Routing.apiCommandRoutes() {
|
||||
return@delete
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@delete
|
||||
}
|
||||
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@delete
|
||||
}
|
||||
|
@@ -25,7 +25,11 @@ fun Route.apiDiscordRoutes() {
|
||||
return@get
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id || user.token == null) {
|
||||
if(user?.token == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
@@ -50,10 +54,15 @@ fun Route.apiDiscordRoutes() {
|
||||
return@post
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id || user.token == null) {
|
||||
if(user?.token == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@post
|
||||
}
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@post
|
||||
}
|
||||
|
||||
UserService.updateLiveAlert(user, body.guildId?.toLong() ?: 0L, body.channelId?.toLong() ?: 0L, body.message)
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
@@ -82,21 +91,6 @@ fun Route.apiDiscordRoutes() {
|
||||
call.respond(HttpStatusCode.OK, guild)
|
||||
return@get
|
||||
}
|
||||
get {
|
||||
val session = call.sessions.get<UserSession>()
|
||||
if(session == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "Session is required")
|
||||
return@get
|
||||
}
|
||||
val user = UserService.getUserWithNaverId(session.id)
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
|
||||
call.respond(HttpStatusCode.OK, DiscordGuildCache.getCachedGuilds(session.discordGuildList))
|
||||
return@get
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -89,13 +89,13 @@ fun Routing.apiRoutes() {
|
||||
call.respondText("No session found", status = HttpStatusCode.Unauthorized)
|
||||
return@get
|
||||
}
|
||||
println(session)
|
||||
var user = UserService.getUserWithNaverId(session.id)
|
||||
if(user == null) {
|
||||
user = UserService.saveUser("임시닉네임", session.id)
|
||||
}
|
||||
val songConfig = SongConfigService.getConfig(user)
|
||||
val status = user.token?.let { it1 -> getStreamInfo(it1) }
|
||||
val returnUsers = mutableListOf<GetSessionDTO>()
|
||||
|
||||
if (user.username == "임시닉네임") {
|
||||
status?.content?.channel?.let { it1 -> UserService.updateUser(user, it1.channelId, it1.channelName) }
|
||||
@@ -106,7 +106,7 @@ fun Routing.apiRoutes() {
|
||||
return@get
|
||||
}
|
||||
|
||||
call.respond(HttpStatusCode.OK, GetSessionDTO(
|
||||
returnUsers.add(GetSessionDTO(
|
||||
status.content!!.channel.channelId,
|
||||
status.content!!.channel.channelName,
|
||||
status.content!!.status == "OPEN",
|
||||
@@ -116,6 +116,24 @@ fun Routing.apiRoutes() {
|
||||
songConfig.streamerOnly,
|
||||
songConfig.disabled
|
||||
))
|
||||
|
||||
user.suborinates.forEach {
|
||||
val subStatus = user.token?.let { it1 -> getStreamInfo(it1) }
|
||||
if(it.token == null) return@forEach
|
||||
if(subStatus?.content == null) return@forEach
|
||||
returnUsers.add(GetSessionDTO(
|
||||
subStatus.content!!.channel.channelId,
|
||||
subStatus.content!!.channel.channelName,
|
||||
subStatus.content!!.status == "OPEN",
|
||||
subStatus.content!!.channel.channelImageUrl,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
false
|
||||
))
|
||||
}
|
||||
|
||||
call.respond(HttpStatusCode.OK, returnUsers)
|
||||
}
|
||||
post {
|
||||
val session = call.sessions.get<UserSession>()
|
||||
|
@@ -22,7 +22,12 @@ fun Routing.apiTimerRoutes() {
|
||||
return@get
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@get
|
||||
}
|
||||
@@ -41,7 +46,12 @@ fun Routing.apiTimerRoutes() {
|
||||
return@put
|
||||
}
|
||||
val user = UserService.getUser(uid)
|
||||
if(user == null || user.naverId != session?.id) {
|
||||
if(user == null) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@put
|
||||
}
|
||||
|
||||
if(!user.managers.any { it.naverId == session?.id } && user.naverId != session?.id) {
|
||||
call.respond(HttpStatusCode.BadRequest, "User does not exist")
|
||||
return@put
|
||||
}
|
||||
|
Reference in New Issue
Block a user