add POST /user endpoints.

- POST /user {"chzzkUrl": String} to add chzzk account to bots.
- and it post event UserRegisterEvent
This commit is contained in:
dalbodeule
2024-08-08 19:36:58 +09:00
parent d0840ad6a7
commit 80fa2d5029
4 changed files with 97 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import org.koin.java.KoinJavaComponent.inject
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import space.mori.chzzk_bot.chatbot.chzzk.Connector.chzzk
import space.mori.chzzk_bot.chatbot.chzzk.Connector.getChannel
import space.mori.chzzk_bot.chatbot.discord.Discord
import space.mori.chzzk_bot.common.events.*
import space.mori.chzzk_bot.common.models.User
@@ -28,6 +29,7 @@ object ChzzkHandler {
private val logger = LoggerFactory.getLogger(this::class.java)
lateinit var botUid: String
@Volatile private var running: Boolean = false
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
fun addUser(chzzkChannel: ChzzkChannel, user: User) {
handlers.add(UserHandler(chzzkChannel, logger, user, streamStartTime = null))
@@ -43,6 +45,14 @@ object ChzzkHandler {
val streamInfo = getStreamInfo(handler.listener.channelId)
if (streamInfo.content?.status == "OPEN") handler.isActive(true, streamInfo)
}
dispatcher.subscribe(UserRegisterEvent::class) {
val channel = getChannel(it.chzzkId)
val user = UserService.getUser(it.chzzkId)
if(channel != null && user != null) {
addUser(channel, user)
}
}
}
fun disable() {