fix some bugs 3(streamInfo add errorhandler)

This commit is contained in:
dalbodeule 2024-06-17 17:35:48 +09:00
parent eae675eaf6
commit e31efc0212
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65

View File

@ -13,6 +13,7 @@ import xyz.r2turntrue.chzzk4j.chat.ChatMessage
import xyz.r2turntrue.chzzk4j.chat.ChzzkChat import xyz.r2turntrue.chzzk4j.chat.ChzzkChat
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
import java.lang.Exception import java.lang.Exception
import java.net.SocketTimeoutException
import java.time.Instant import java.time.Instant
object ChzzkHandler { object ChzzkHandler {
@ -58,11 +59,18 @@ object ChzzkHandler {
while(running) { while(running) {
handlers.forEach { handlers.forEach {
if (!running) return@forEach if (!running) return@forEach
try {
val streamInfo = getStreamInfo(it.channel.channelId) val streamInfo = getStreamInfo(it.channel.channelId)
if(streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, streamInfo) if (streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, streamInfo)
if(streamInfo.content.status == "CLOSED" && it.isActive) it.isActive(false, streamInfo) if (streamInfo.content.status == "CLOSED" && it.isActive) it.isActive(false, streamInfo)
} catch(e: SocketTimeoutException) {
logger.info("timeout: ${it.channel.channelName}")
} catch (e: Exception) {
logger.info("Exception: ${it.channel.channelName}")
} finally {
Thread.sleep(5000) Thread.sleep(5000)
} }
}
Thread.sleep(60000) Thread.sleep(60000)
} }
}.start() }.start()