@@ -96,14 +96,16 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
96
96
priority = MONITOR ,
97
97
concurrency = ConcurrencyKind .LOCKED
98
98
) { 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 还在登入
107
109
return @subscribeAlways
108
110
}
109
111
/*
@@ -165,20 +167,13 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
165
167
if (tryCount != 0 ) {
166
168
delay(configuration.reconnectPeriodMillis)
167
169
}
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
+ }
182
177
launch {
183
178
BotReloginEvent (bot, (event as ? BotOfflineEvent .CauseAware )?.cause).broadcast()
184
179
}
0 commit comments