From dd628738f7ad594983894418c347864725b96db4 Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Sat, 10 Aug 2024 21:50:58 +0900 Subject: [PATCH] =?UTF-8?q?fix=20somes.=20-=20command=20renamed=20"!?= =?UTF-8?q?=EB=85=B8=EB=9E=98=EC=B6=94=EA=B0=80"=20to=20"!=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=EA=B3=A1",=20and=20its=20debugged.=20-=20command=20"!?= =?UTF-8?q?=EB=85=B8=EB=9E=98=EC=8B=9C=EC=9E=91"=20to=20user.discordId=20i?= =?UTF-8?q?s=20null,=20send=20announce=20to=20chzzk=20chat.=20-=20songlist?= =?UTF-8?q?=20function=20isDisabled=20value=20added.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chzzk_bot/chatbot/chzzk/MessageHandler.kt | 20 +++++++++++++------ .../chzzk_bot/common/models/SongConfig.kt | 2 ++ .../common/services/SongConfigService.kt | 12 +++++++++++ .../chzzk_bot/webserver/routes/ApiRoutes.kt | 4 +++- .../webserver/routes/WSSongListRoutes.kt | 8 ++++---- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt index 26b04ad..fddc64d 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/MessageHandler.kt @@ -58,7 +58,7 @@ class MessageHandler( "!명령어삭제" to this::manageRemoveCommand, "!명령어수정" to this::manageUpdateCommand, "!시간" to this::timerCommand, - "!노래추가" to this::songAddCommand, + "!신청곡" to this::songAddCommand, "!노래목록" to this::songListCommand, "!노래시작" to this::songStartCommand ) @@ -205,7 +205,11 @@ class MessageHandler( // songs private fun songAddCommand(msg: ChatMessage, user: User) { - val parts = msg.content.split(" ", limit = 3) + if(SongConfigService.getConfig(user).disabled) { + return + } + + val parts = msg.content.split(" ", limit = 2) if (parts.size < 2) { listener.sendChat("유튜브 URL을 입력해주세요!") return @@ -274,6 +278,10 @@ class MessageHandler( } private fun songListCommand(msg: ChatMessage, user: User) { + if(SongConfigService.getConfig(user).disabled) { + return + } + listener.sendChat("리스트는 여기입니다. https://nabot.mori.space/songs/${user.token}") } @@ -283,16 +291,16 @@ class MessageHandler( return } - val session = "${UUID.randomUUID()}${UUID.randomUUID()}".replace("-", "") - - user.discord?.let { - bot.retrieveUserById(it).queue { discordUser -> + if(user.discord != null) { + bot.retrieveUserById(user.discord!!).queue { discordUser -> discordUser?.openPrivateChannel()?.queue { channel -> channel.sendMessage("여기로 접속해주세요! ||https://nabot.mori.space/songlist||.") .queue() } } + } else { + listener.sendChat("나봇 홈페이지의 노래목록 페이지를 이용해주세요! 디스코드 연동을 하시면 DM으로 바로 전송됩니다.") } } diff --git a/common/src/main/kotlin/space/mori/chzzk_bot/common/models/SongConfig.kt b/common/src/main/kotlin/space/mori/chzzk_bot/common/models/SongConfig.kt index e9c769a..526aee3 100644 --- a/common/src/main/kotlin/space/mori/chzzk_bot/common/models/SongConfig.kt +++ b/common/src/main/kotlin/space/mori/chzzk_bot/common/models/SongConfig.kt @@ -12,6 +12,7 @@ object SongConfigs: IntIdTable("song_config") { val streamerOnly = bool("streamer_only").default(false) val queueLimit = integer("queue_limit").default(50) val personalLimit = integer("personal_limit").default(5) + val disabled = bool("disabled").default(false) } class SongConfig(id: EntityID) : IntEntity(id) { companion object : IntEntityClass(SongConfigs) @@ -21,4 +22,5 @@ class SongConfig(id: EntityID) : IntEntity(id) { var streamerOnly by SongConfigs.streamerOnly var queueLimit by SongConfigs.queueLimit var personalLimit by SongConfigs.personalLimit + var disabled by SongConfigs.disabled } \ No newline at end of file diff --git a/common/src/main/kotlin/space/mori/chzzk_bot/common/services/SongConfigService.kt b/common/src/main/kotlin/space/mori/chzzk_bot/common/services/SongConfigService.kt index c2e6b54..3bfbe46 100644 --- a/common/src/main/kotlin/space/mori/chzzk_bot/common/services/SongConfigService.kt +++ b/common/src/main/kotlin/space/mori/chzzk_bot/common/services/SongConfigService.kt @@ -58,4 +58,16 @@ object SongConfigService { songConfig } } + + fun updateDisabled(user: User, config: Boolean): SongConfig { + return transaction { + var songConfig = SongConfig.find(SongConfigs.user eq user.id).firstOrNull() + if (songConfig == null) { + songConfig = initConfig(user) + } + songConfig.disabled = config + + songConfig + } + } } \ No newline at end of file diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiRoutes.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiRoutes.kt index db2f2b9..29c94eb 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiRoutes.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/ApiRoutes.kt @@ -36,6 +36,7 @@ data class GetSessionDTO( val maxQueueSize: Int, val maxUserSize: Int, val isStreamerOnly: Boolean, + val isDisabled: Boolean ) @Serializable @@ -112,7 +113,8 @@ fun Routing.apiRoutes() { status.content!!.channel.channelImageUrl, songConfig.queueLimit, songConfig.personalLimit, - songConfig.streamerOnly + songConfig.streamerOnly, + songConfig.disabled )) } post { diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSSongListRoutes.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSSongListRoutes.kt index 6187976..94354df 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSSongListRoutes.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/routes/WSSongListRoutes.kt @@ -60,7 +60,7 @@ fun Routing.wsSongListRoutes() { null, null, null, - null + null, )) } removeSession(uid, this) @@ -75,6 +75,7 @@ fun Routing.wsSongListRoutes() { if(data.maxQueue != null && data.maxQueue > 0) SongConfigService.updateQueueLimit(user, data.maxQueue) if(data.maxUserLimit != null && data.maxUserLimit > 0) SongConfigService.updatePersonalLimit(user, data.maxUserLimit) if(data.isStreamerOnly != null) SongConfigService.updateStreamerOnly(user, data.isStreamerOnly) + if(data.isDisabled != null) SongConfigService.updateDisabled(user, data.isDisabled) if(data.type == SongType.ADD.value && data.url != null) { try { @@ -173,8 +174,6 @@ fun Routing.wsSongListRoutes() { CoroutineScope(Dispatchers.Default).launch { val user = UserService.getUser(it.uid) if(user != null) { - val session = SongConfigService.getConfig(user) - sessions[user.token]?.forEach { ws -> ws.sendSerialized( SongResponse( @@ -203,5 +202,6 @@ data class SongRequest( val maxQueue: Int?, val maxUserLimit: Int?, val isStreamerOnly: Boolean?, - val remove: Int? + val remove: Int?, + val isDisabled: Boolean?, ) \ No newline at end of file