From 5ca07d37490fed8b14420622aa2195d6c389c801 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 21 Nov 2019 21:30:36 +0800 Subject: [PATCH] Add instance getters --- mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt index fe62c0665..029e8498a 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -169,8 +169,11 @@ class Bot(val account: BotAccount, val logger: MiraiLogger) : CoroutineScope { private val _instances: MutableList = mutableListOf() private val instanceLock: Mutex = Mutex() - val instances: List get() = _instances + private val instances: List get() = _instances + suspend fun instanceWhose(qq: UInt) = instanceLock.withLock { + instances.first { it.qqAccount == qq } + } internal suspend fun addInstance(bot: Bot) = instanceLock.withLock { _instances += bot