mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 14:58:21 +00:00
Merge pull request #128 from dalbodeule/develop
[feature] thumbnail, etc. fixed
This commit is contained in:
commit
11f9895198
@ -23,7 +23,7 @@ import xyz.r2turntrue.chzzk4j.session.ChzzkSessionSubscriptionType
|
|||||||
import xyz.r2turntrue.chzzk4j.session.ChzzkUserSession
|
import xyz.r2turntrue.chzzk4j.session.ChzzkUserSession
|
||||||
import xyz.r2turntrue.chzzk4j.session.event.SessionChatMessageEvent
|
import xyz.r2turntrue.chzzk4j.session.event.SessionChatMessageEvent
|
||||||
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
|
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.lang.Exception
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@ -259,7 +259,7 @@ class UserHandler(
|
|||||||
internal val isActive: Boolean
|
internal val isActive: Boolean
|
||||||
get() = _isActive
|
get() = _isActive
|
||||||
|
|
||||||
internal fun isActive(value: Boolean, status: ChzzkLiveStatus) {
|
internal fun isActive(value: Boolean, status: ChzzkLiveDetail) {
|
||||||
if(value) {
|
if(value) {
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
logger.info("${user.username} is live.")
|
logger.info("${user.username} is live.")
|
||||||
@ -267,7 +267,7 @@ class UserHandler(
|
|||||||
reloadUser(UserService.getUser(user.id.value)!!)
|
reloadUser(UserService.getUser(user.id.value)!!)
|
||||||
|
|
||||||
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
|
logger.info("ChzzkChat connecting... ${channel.channelName} - ${channel.channelId}")
|
||||||
listener.subscribeAsync(ChzzkSessionSubscriptionType.CHAT)
|
listener.subscribeAsync(ChzzkSessionSubscriptionType.CHAT).join()
|
||||||
|
|
||||||
streamStartTime = LocalDateTime.now()
|
streamStartTime = LocalDateTime.now()
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import xyz.r2turntrue.chzzk4j.ChzzkClientBuilder
|
|||||||
import xyz.r2turntrue.chzzk4j.auth.ChzzkLegacyLoginAdapter
|
import xyz.r2turntrue.chzzk4j.auth.ChzzkLegacyLoginAdapter
|
||||||
import xyz.r2turntrue.chzzk4j.auth.ChzzkSimpleUserLoginAdapter
|
import xyz.r2turntrue.chzzk4j.auth.ChzzkSimpleUserLoginAdapter
|
||||||
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
|
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
|
import kotlin.getValue
|
||||||
|
|
||||||
val dotenv = dotenv {
|
val dotenv = dotenv {
|
||||||
@ -31,7 +31,7 @@ object Connector {
|
|||||||
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
|
||||||
|
|
||||||
fun getChannel(channelId: String): ChzzkChannel? = client.fetchChannel(channelId)
|
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 {
|
init {
|
||||||
logger.info("chzzk logged: ${client.isLoggedIn}")
|
logger.info("chzzk logged: ${client.isLoggedIn}")
|
||||||
|
@ -14,7 +14,8 @@ import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import space.mori.chzzk_bot.chatbot.discord.commands.*
|
import space.mori.chzzk_bot.chatbot.discord.commands.*
|
||||||
import space.mori.chzzk_bot.common.models.User
|
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 java.time.Instant
|
||||||
import kotlin.jvm.optionals.getOrNull
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ class Discord: ListenerAdapter() {
|
|||||||
return bot.getGuildById(guildId)?.getTextChannelById(channelId)
|
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) {
|
if(user.liveAlertMessage != null && user.liveAlertGuild != null && user.liveAlertChannel != null) {
|
||||||
val channel = getChannel(user.liveAlertGuild ?: 0, user.liveAlertChannel ?: 0)
|
val channel = getChannel(user.liveAlertGuild ?: 0, user.liveAlertChannel ?: 0)
|
||||||
?: throw RuntimeException("${user.liveAlertChannel} is not valid.")
|
?: 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.setAuthor(user.username, "https://chzzk.naver.com/live/${user.token}")
|
||||||
embed.addField("카테고리", status.liveCategoryValue, true)
|
embed.addField("카테고리", status.liveCategoryValue, true)
|
||||||
embed.addField("태그", status.tags.joinToString(", ") { it.trim() }, 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(
|
channel.sendMessage(
|
||||||
MessageCreateBuilder()
|
MessageCreateBuilder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user