Bot.otherClients now does not include self, close #770

This commit is contained in:
Him188 2020-12-26 22:22:06 +08:00
parent d4a8573772
commit 5196cc410a
2 changed files with 6 additions and 2 deletions

View File

@ -187,10 +187,12 @@ public interface IMirai : LowLevelApiAccessor {
/** /**
* 获取在线的 [OtherClient] 列表 * 获取在线的 [OtherClient] 列表
* @param mayIncludeSelf 服务器返回的列表可能包含 [Bot] 自己. [mayIncludeSelf] `false` 会排除自己
*/ */
@JvmBlockingBridge @JvmBlockingBridge
public suspend fun getOnlineOtherClientsList( public suspend fun getOnlineOtherClientsList(
bot: Bot, bot: Bot,
mayIncludeSelf: Boolean = false
): List<OtherClientInfo> ): List<OtherClientInfo>
/** /**

View File

@ -159,7 +159,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
group.checkBotPermission(MemberPermission.ADMINISTRATOR) group.checkBotPermission(MemberPermission.ADMINISTRATOR)
} }
override suspend fun getOnlineOtherClientsList(bot: Bot): List<OtherClientInfo> { override suspend fun getOnlineOtherClientsList(bot: Bot, mayIncludeSelf: Boolean): List<OtherClientInfo> {
bot.asQQAndroidBot() bot.asQQAndroidBot()
val response = bot.network.run { val response = bot.network.run {
StatSvc.GetDevLoginInfo(bot.client).sendAndExpect<StatSvc.GetDevLoginInfo.Response>() StatSvc.GetDevLoginInfo(bot.client).sendAndExpect<StatSvc.GetDevLoginInfo.Response>()
@ -172,7 +172,9 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
deviceTypeInfo.orEmpty() deviceTypeInfo.orEmpty()
) )
return response.deviceList.map { it.toOtherClientInfo() } return response.deviceList.map { it.toOtherClientInfo() }.let { result ->
if (mayIncludeSelf) result else result.filterNot { it.appId == bot.client.protocol.id.toInt() }
}
} }
override suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean) { override suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean) {