소스 검색

Fix Bot init

Him188 5 년 전
부모
커밋
20b912bee7
1개의 변경된 파일8개의 추가작업 그리고 7개의 파일을 삭제
  1. 8 7
      mirai-core/src/commonMain/kotlin/AbstractBot.kt

+ 8 - 7
mirai-core/src/commonMain/kotlin/AbstractBot.kt

@@ -41,15 +41,9 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
     final override val id: Long,
 ) : Bot, CoroutineScope {
     // FASTEST INIT
-    init {
-        Bot._instances[this.id] = this
-        supervisorJob.invokeOnCompletion {
-            Bot._instances.remove(id)
-        }
-    }
 
-    final override val logger: MiraiLogger by lazy { configuration.botLoggerSupplier(this) }
 
+    final override val logger: MiraiLogger by lazy { configuration.botLoggerSupplier(this) }
 
     final override val coroutineContext: CoroutineContext = // for id
         configuration.parentCoroutineContext
@@ -61,6 +55,13 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
             )
             .plus(CoroutineName("Mirai Bot"))
 
+    init {
+        @Suppress("LeakingThis")
+        Bot._instances[this.id] = this
+        supervisorJob.invokeOnCompletion {
+            Bot._instances.remove(id)
+        }
+    }
 
     // region network