Him188 5 vuotta sitten
vanhempi
sitoutus
20b912bee7
1 muutettua tiedostoa jossa 8 lisäystä ja 7 poistoa
  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