Skip to content

Commit

Permalink
fix some bugs 3(streamInfo add errorhandler)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalbodeule committed Jun 17, 2024
1 parent eae675e commit e31efc0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import xyz.r2turntrue.chzzk4j.chat.ChatMessage
import xyz.r2turntrue.chzzk4j.chat.ChzzkChat
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel
import java.lang.Exception
import java.net.SocketTimeoutException
import java.time.Instant

object ChzzkHandler {
Expand Down Expand Up @@ -58,10 +59,17 @@ object ChzzkHandler {
while(running) {
handlers.forEach {
if (!running) return@forEach
val streamInfo = getStreamInfo(it.channel.channelId)
if(streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, streamInfo)
if(streamInfo.content.status == "CLOSED" && it.isActive) it.isActive(false, streamInfo)
Thread.sleep(5000)
try {
val streamInfo = getStreamInfo(it.channel.channelId)
if (streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, 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(60000)
}
Expand Down

0 comments on commit e31efc0

Please sign in to comment.