mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 14:58:21 +00:00
[hotfix] coroutine related fixed.
This commit is contained in:
parent
49541f7289
commit
a88f994ccd
@ -6,6 +6,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.koin.java.KoinJavaComponent.inject
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@ -223,13 +224,13 @@ class UserHandler(
|
|||||||
throw RuntimeException("AccessToken or RefreshToken is not valid.")
|
throw RuntimeException("AccessToken or RefreshToken is not valid.")
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
connect()
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
connect()
|
||||||
|
|
||||||
listener.on(SessionChatMessageEvent::class.java) {
|
listener.on(SessionChatMessageEvent::class.java) {
|
||||||
messageHandler.handle(it.message, user)
|
messageHandler.handle(it.message, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalScope.launch {
|
|
||||||
val timer = TimerConfigService.getConfig(user)
|
val timer = TimerConfigService.getConfig(user)
|
||||||
if (timer?.option == TimerType.UPTIME.value)
|
if (timer?.option == TimerType.UPTIME.value)
|
||||||
dispatcher.post(
|
dispatcher.post(
|
||||||
@ -247,14 +248,13 @@ class UserHandler(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
logger.error("Exception(${user.username}): ${e.stackTraceToString()}")
|
logger.error("Exception(${user.username}): ${e.stackTraceToString()}")
|
||||||
throw RuntimeException("Exception: ${e.stackTraceToString()}")
|
throw RuntimeException("Exception: ${e.stackTraceToString()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun connect() {
|
private suspend fun connect() = runBlocking {
|
||||||
val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token)}
|
val tokens = user.refreshToken?.let { token -> Connector.client.refreshAccessToken(token)}
|
||||||
if(tokens == null) {
|
if(tokens == null) {
|
||||||
throw RuntimeException("AccessToken is not valid.")
|
throw RuntimeException("AccessToken is not valid.")
|
||||||
@ -287,9 +287,9 @@ class UserHandler(
|
|||||||
|
|
||||||
internal fun isActive(value: Boolean, status: ChzzkLiveDetail) {
|
internal fun isActive(value: Boolean, status: ChzzkLiveDetail) {
|
||||||
if(value) {
|
if(value) {
|
||||||
connect()
|
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
connect()
|
||||||
|
|
||||||
logger.info("${user.username} is live.")
|
logger.info("${user.username} is live.")
|
||||||
|
|
||||||
reloadUser(UserService.getUser(user.id.value)!!)
|
reloadUser(UserService.getUser(user.id.value)!!)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user