mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 14:58:21 +00:00
add botIsDisabled, welcomeMessageDisabled.
This commit is contained in:
parent
4fca9df9c2
commit
eccf1a29bc
4
.idea/sqldialects.xml
generated
4
.idea/sqldialects.xml
generated
@ -3,4 +3,8 @@
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="PROJECT" dialect="MariaDB" />
|
||||
</component>
|
||||
<component name="SqlResolveMappings">
|
||||
<file url="file://$PROJECT_DIR$/common/src/main/kotlin/space/mori/chzzk_bot/common/models/User.kt" scope="{"node":{ "@negative":"1", "group":{ "@kind":"root", "node":{ "name":{ "@qname":"90f8ee11-600e-4155-a316-e8062c7c828b" }, "group":{ "@kind":"schema", "node":{ "name":{ "@qname":"chzzk" } } } } } }}" />
|
||||
<file url="PROJECT" scope="{"node":{ "@negative":"1", "group":{ "@kind":"root", "node":{ "name":{ "@qname":"90f8ee11-600e-4155-a316-e8062c7c828b" }, "group":{ "@kind":"schema", "node":{ "name":{ "@qname":"chzzk" } } } } } }}" />
|
||||
</component>
|
||||
</project>
|
@ -39,7 +39,7 @@ object ChzzkHandler {
|
||||
fun enable() {
|
||||
botUid = chzzk.loggedUser.userId
|
||||
UserService.getAllUsers().map {
|
||||
if(it.token != null)
|
||||
if(it.token != null && !it.isDisabled)
|
||||
chzzk.getChannel(it.token)?.let { token -> addUser(token, it) }
|
||||
}
|
||||
|
||||
@ -55,9 +55,22 @@ object ChzzkHandler {
|
||||
addUser(channel, user)
|
||||
}
|
||||
}
|
||||
|
||||
dispatcher.subscribe(CommandReloadEvent::class) {
|
||||
handlers.firstOrNull { handlers -> handlers.channel.channelId == it.uid }?.reloadCommand()
|
||||
}
|
||||
|
||||
dispatcher.subscribe(BotEnabledEvent::class) {
|
||||
if(it.isDisabled) {
|
||||
handlers.removeIf { handlers -> handlers.channel.channelId == it.chzzkId }
|
||||
} else {
|
||||
val channel = getChannel(it.chzzkId)
|
||||
val user = UserService.getUser(it.chzzkId)
|
||||
if(channel != null && user != null) {
|
||||
addUser(channel, user)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
|
@ -0,0 +1,8 @@
|
||||
package space.mori.chzzk_bot.common.events
|
||||
|
||||
data class BotEnabledEvent(
|
||||
val chzzkId: String,
|
||||
val isDisabled: Boolean,
|
||||
): Event {
|
||||
val TAG = javaClass.simpleName
|
||||
}
|
@ -15,6 +15,7 @@ object Users: IntIdTable("users") {
|
||||
val liveAlertChannel = long("live_alert_channel").nullable()
|
||||
val liveAlertMessage = text("live_alert_message").nullable()
|
||||
val isDisableStartupMsg = bool("is_disable_startup_msg").default(false)
|
||||
val isDisabled = bool("is_disabled").default(false)
|
||||
}
|
||||
|
||||
class User(id: EntityID<Int>) : IntEntity(id) {
|
||||
@ -28,6 +29,7 @@ class User(id: EntityID<Int>) : IntEntity(id) {
|
||||
var liveAlertChannel by Users.liveAlertChannel
|
||||
var liveAlertMessage by Users.liveAlertMessage
|
||||
var isDisableStartupMsg by Users.isDisableStartupMsg
|
||||
var isDisabled by Users.isDisabled
|
||||
|
||||
// 유저가 가진 매니저들
|
||||
var managers by User.via(UserManagers.user, UserManagers.manager)
|
||||
|
@ -89,4 +89,20 @@ object UserService {
|
||||
user
|
||||
}
|
||||
}
|
||||
|
||||
fun setIsDisabled(user: User, disabled: Boolean): User {
|
||||
return transaction {
|
||||
user.isDisabled = disabled
|
||||
|
||||
user
|
||||
}
|
||||
}
|
||||
|
||||
fun setIsStartupDisabled(user: User, disabled: Boolean): User {
|
||||
return transaction {
|
||||
user.isDisableStartupMsg = disabled
|
||||
|
||||
user
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user