mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
some debugs on Chisu playlist
This commit is contained in:
@@ -9,9 +9,7 @@ import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import space.mori.chzzk_bot.chatbot.chzzk.Connector.chzzk
|
||||
import space.mori.chzzk_bot.chatbot.discord.Discord
|
||||
import space.mori.chzzk_bot.common.events.CoroutinesEventBus
|
||||
import space.mori.chzzk_bot.common.events.TimerEvent
|
||||
import space.mori.chzzk_bot.common.events.TimerType
|
||||
import space.mori.chzzk_bot.common.events.*
|
||||
import space.mori.chzzk_bot.common.models.User
|
||||
import space.mori.chzzk_bot.common.services.LiveStatusService
|
||||
import space.mori.chzzk_bot.common.services.TimerConfigService
|
||||
@@ -39,6 +37,11 @@ object ChzzkHandler {
|
||||
UserService.getAllUsers().map {
|
||||
chzzk.getChannel(it.token)?.let { token -> addUser(token, it) }
|
||||
}
|
||||
|
||||
handlers.forEach { handler ->
|
||||
val streamInfo = getStreamInfo(handler.listener.channelId)
|
||||
if (streamInfo.content.status == "OPEN") handler.isActive(true, streamInfo)
|
||||
}
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
@@ -148,7 +151,6 @@ class UserHandler(
|
||||
get() = _isActive
|
||||
|
||||
internal fun isActive(value: Boolean, status: IData<IStreamInfo>) {
|
||||
_isActive = value
|
||||
if(value) {
|
||||
logger.info("${user.username} is live.")
|
||||
|
||||
@@ -170,10 +172,11 @@ class UserHandler(
|
||||
""
|
||||
))
|
||||
}
|
||||
|
||||
delay(5000L)
|
||||
listener.sendChat("${user.username} 님! 오늘도 열심히 방송하세요!")
|
||||
Discord.sendDiscord(user, status)
|
||||
if(!_isActive) {
|
||||
delay(5000L)
|
||||
listener.sendChat("${user.username} 님! 오늘도 열심히 방송하세요!")
|
||||
Discord.sendDiscord(user, status)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.info("${user.username} is offline.")
|
||||
@@ -181,12 +184,25 @@ class UserHandler(
|
||||
listener.closeAsync()
|
||||
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
dispatcher.post(TimerEvent(
|
||||
channel.channelId,
|
||||
TimerType.STREAM_OFF,
|
||||
""
|
||||
))
|
||||
val events = listOf(
|
||||
TimerEvent(
|
||||
channel.channelId,
|
||||
TimerType.STREAM_OFF,
|
||||
null
|
||||
),
|
||||
SongEvent(
|
||||
channel.channelId,
|
||||
SongType.STREAM_OFF,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
)
|
||||
events.forEach { dispatcher.post(it) }
|
||||
}
|
||||
}
|
||||
_isActive = value
|
||||
}
|
||||
}
|
@@ -36,6 +36,14 @@ class MessageHandler(
|
||||
|
||||
init {
|
||||
reloadCommand()
|
||||
dispatcher.subscribe(SongEvent::class) {
|
||||
if(it.type == SongType.STREAM_OFF) {
|
||||
val user = UserService.getUser(channel.channelId)
|
||||
if(! user?.let { usr -> SongListService.getSong(usr) }.isNullOrEmpty()) {
|
||||
SongListService.deleteUser(user!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun reloadCommand() {
|
||||
@@ -199,33 +207,35 @@ class MessageHandler(
|
||||
val url = parts[1]
|
||||
val songs = SongListService.getSong(user)
|
||||
|
||||
if (songs.any { it.url == url }) {
|
||||
listener.sendChat("같은 노래가 이미 신청되어 있습니다.")
|
||||
return
|
||||
}
|
||||
|
||||
val video = getYoutubeVideo(url)
|
||||
if (video == null) {
|
||||
listener.sendChat("유튜브에서 찾을 수 없어요!")
|
||||
return
|
||||
}
|
||||
|
||||
if (songs.any { it.url == video.url }) {
|
||||
listener.sendChat("같은 노래가 이미 신청되어 있습니다.")
|
||||
return
|
||||
}
|
||||
|
||||
SongListService.saveSong(
|
||||
user,
|
||||
msg.userId,
|
||||
video.url,
|
||||
video.name,
|
||||
video.author,
|
||||
video.length
|
||||
video.length,
|
||||
msg.profile?.nickname ?: ""
|
||||
)
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
dispatcher.post(SongEvent(
|
||||
user.token,
|
||||
SongType.ADD,
|
||||
msg.userId,
|
||||
msg.profile?.nickname ?: "",
|
||||
video.name,
|
||||
video.author,
|
||||
video.length
|
||||
video.length,
|
||||
))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user