Skip to content

Commit

Permalink
修复因握手阶段的错误导致bot无法接受后续连接的问题 (#110)
Browse files Browse the repository at this point in the history
* feat: ✨ 使Overflow在非MiraiConsole模式下的工作协程下的子协程相互隔离

* feat: ✨ 将OneBotProducer协程也纳入parent的管理范围内
  • Loading branch information
kagg886 authored Nov 24, 2024
1 parent 54e53f3 commit 4fedbde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions onebot/src/main/kotlin/client/connection/ConnectFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package cn.evolvefield.onebot.client.connection
import cn.evolvefield.onebot.client.config.BotConfig
import cn.evolvefield.onebot.client.core.Bot
import cn.evolvefield.onebot.client.handler.ActionHandler
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
import kotlinx.coroutines.*
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.InetSocketAddress
Expand All @@ -24,7 +21,7 @@ import java.net.URI
*/
class ConnectFactory private constructor(
private val config: BotConfig,
parent: Job?,
private val parent: Job?,
private val logger: Logger,
) {
private val actionHandler: ActionHandler = ActionHandler(parent, logger)
Expand Down Expand Up @@ -96,8 +93,9 @@ class ConnectFactory private constructor(

@JvmOverloads
fun createProducer(
scope: CoroutineScope = CoroutineScope(CoroutineName("ConnectFactory"))
scope0: CoroutineScope = CoroutineScope(CoroutineName("ConnectFactory"))
): OneBotProducer {
val scope = if (parent == null) scope0 else scope0 + parent
if (config.isInReverseMode) {
val address = InetSocketAddress(config.reversedPort)
return ReversedOneBotProducer(WSServer.create(scope, config, address, logger, actionHandler, config.token))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI {
File(System.getProperty("overflow.config", "overflow.json"))
}
val defaultJob: Job? by lazy {
if (!miraiConsole) return@lazy null
if (!miraiConsole) return@lazy SupervisorJob()
return@lazy MiraiConsole.job
}
val config: Config by lazy {
Expand Down

0 comments on commit 4fedbde

Please sign in to comment.