From a18b83fcc8bc74c500d826768da40a5ca6baeedc Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Sun, 18 May 2025 08:14:46 +0900 Subject: [PATCH] [feature] thumbnail, etc. fixed --- .../mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt | 6 +++--- .../mori/chzzk_bot/chatbot/chzzk/Connector.kt | 4 ++-- .../mori/chzzk_bot/chatbot/discord/Discord.kt | 14 +++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt index d61ac1a..a8cc596 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/ChzzkHandler.kt @@ -23,7 +23,7 @@ import xyz.r2turntrue.chzzk4j.session.ChzzkSessionSubscriptionType import xyz.r2turntrue.chzzk4j.session.ChzzkUserSession import xyz.r2turntrue.chzzk4j.session.event.SessionChatMessageEvent import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel -import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveStatus +import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveDetail import java.lang.Exception import java.net.SocketTimeoutException import java.time.LocalDateTime @@ -259,7 +259,7 @@ class UserHandler( internal val isActive: Boolean get() = _isActive - internal fun isActive(value: Boolean, status: ChzzkLiveStatus) { + internal fun isActive(value: Boolean, status: ChzzkLiveDetail) { if(value) { CoroutineScope(Dispatchers.Default).launch { logger.info("${user.username} is live.") @@ -267,7 +267,7 @@ class UserHandler( reloadUser(UserService.getUser(user.id.value)!!) logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}") - listener.subscribeAsync(ChzzkSessionSubscriptionType.CHAT) + listener.subscribeAsync(ChzzkSessionSubscriptionType.CHAT).join() streamStartTime = LocalDateTime.now() diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt index e36a687..ae69302 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt @@ -14,7 +14,7 @@ import xyz.r2turntrue.chzzk4j.ChzzkClientBuilder import xyz.r2turntrue.chzzk4j.auth.ChzzkLegacyLoginAdapter import xyz.r2turntrue.chzzk4j.auth.ChzzkSimpleUserLoginAdapter import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel -import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveStatus +import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveDetail import kotlin.getValue val dotenv = dotenv { @@ -31,7 +31,7 @@ object Connector { private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) fun getChannel(channelId: String): ChzzkChannel? = client.fetchChannel(channelId) - fun getLive(channelId: String): ChzzkLiveStatus? = client.fetchLiveStatus(channelId) + fun getLive(channelId: String): ChzzkLiveDetail? = client.fetchLiveDetail(channelId) init { logger.info("chzzk logged: ${client.isLoggedIn}") diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/discord/Discord.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/discord/Discord.kt index af54e80..4d44c0d 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/discord/Discord.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/discord/Discord.kt @@ -14,7 +14,8 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder import org.slf4j.LoggerFactory import space.mori.chzzk_bot.chatbot.discord.commands.* import space.mori.chzzk_bot.common.models.User -import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveStatus +import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveDetail +import xyz.r2turntrue.chzzk4j.types.channel.live.Resolution import java.time.Instant import kotlin.jvm.optionals.getOrNull @@ -33,7 +34,7 @@ class Discord: ListenerAdapter() { return bot.getGuildById(guildId)?.getTextChannelById(channelId) } - fun sendDiscord(user: User, status: ChzzkLiveStatus) { + fun sendDiscord(user: User, status: ChzzkLiveDetail) { if(user.liveAlertMessage != null && user.liveAlertGuild != null && user.liveAlertChannel != null) { val channel = getChannel(user.liveAlertGuild ?: 0, user.liveAlertChannel ?: 0) ?: throw RuntimeException("${user.liveAlertChannel} is not valid.") @@ -45,7 +46,14 @@ class Discord: ListenerAdapter() { embed.setAuthor(user.username, "https://chzzk.naver.com/live/${user.token}") embed.addField("카테고리", status.liveCategoryValue, true) embed.addField("태그", status.tags.joinToString(", ") { it.trim() }, true) - // embed.setImage(status.) + status.defaultThumbnailImageUrl.getOrNull()?.let { embed.setImage(it) } + ?: Resolution.entries.reversed().forEach { + val thumbnail = status.getLiveImageUrl(it) + if (thumbnail != null) { + embed.setImage(thumbnail) + return@forEach + } + } channel.sendMessage( MessageCreateBuilder()