mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-14 07:10:09 +08:00
Fix Bot init
This commit is contained in:
parent
bf88731086
commit
20b912bee7
@ -41,16 +41,10 @@ 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 coroutineContext: CoroutineContext = // for id
|
||||
configuration.parentCoroutineContext
|
||||
.plus(SupervisorJob(configuration.parentCoroutineContext[Job]))
|
||||
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user