Skip to content

Commit e605c29

Browse files
committed
Revert "Fix reconnect. Fix #894"
This reverts commit 65eff19
1 parent 65eff19 commit e605c29

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

mirai-core/src/commonMain/kotlin/AbstractBot.kt

+17-22
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
9696
priority = MONITOR,
9797
concurrency = ConcurrencyKind.LOCKED
9898
) { event ->
99-
if (
100-
!event.bot.isActive // bot closed
101-
|| !::_network.isInitialized // bot 还未登录就被 close
102-
|| _isConnecting // bot 还在登入
103-
) {
104-
// Close network to avoid endless reconnection while network is ok
105-
// https://github.com/mamoe/mirai/issues/894
106-
kotlin.runCatching { network.close(event.castOrNull<BotOfflineEvent.CauseAware>()?.cause) }
99+
if (!event.bot.isActive) {
100+
// bot closed
101+
return@subscribeAlways
102+
}
103+
if (!::_network.isInitialized) {
104+
// bot 还未登录就被 close
105+
return@subscribeAlways
106+
}
107+
if (_isConnecting) {
108+
// bot 还在登入
107109
return@subscribeAlways
108110
}
109111
/*
@@ -165,20 +167,13 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
165167
if (tryCount != 0) {
166168
delay(configuration.reconnectPeriodMillis)
167169
}
168-
169-
170-
// Close network to avoid endless reconnection while network is ok
171-
// https://github.com/mamoe/mirai/issues/894
172-
kotlin.runCatching { network.close(event.castOrNull<BotOfflineEvent.CauseAware>()?.cause) }
173-
174-
login()
175-
// network.withConnectionLock {
176-
// /**
177-
// * [AbstractBot.relogin] only, no [BotNetworkHandler.init]
178-
// */
179-
// @OptIn(ThisApiMustBeUsedInWithConnectionLockBlock::class)
180-
// relogin((event as? BotOfflineEvent.Dropped)?.cause)
181-
// }
170+
network.withConnectionLock {
171+
/**
172+
* [AbstractBot.relogin] only, no [BotNetworkHandler.init]
173+
*/
174+
@OptIn(ThisApiMustBeUsedInWithConnectionLockBlock::class)
175+
relogin((event as? BotOfflineEvent.Dropped)?.cause)
176+
}
182177
launch {
183178
BotReloginEvent(bot, (event as? BotOfflineEvent.CauseAware)?.cause).broadcast()
184179
}

0 commit comments

Comments
 (0)