Commit 418fb439 authored by Him188's avatar Him188

Returns botAsMember when `Group.get(bot.id)`

parent 2c31a2ac
......@@ -242,15 +242,21 @@ internal class GroupImpl(
override operator fun get(id: Long): Member {
if (id == bot.id) {
return botAsMember
}
return members.firstOrNull { it.id == id }
?: throw NoSuchElementException("member $id not found in group $uin")
}
override fun contains(id: Long): Boolean {
return members.firstOrNull { it.id == id } != null
return bot.id == id || members.firstOrNull { it.id == id } != null
}
override fun getOrNull(id: Long): Member? {
if (id == bot.id) {
return botAsMember
}
return members.firstOrNull { it.id == id }
}
......
......@@ -97,16 +97,19 @@ expect abstract class Group() : Contact, CoroutineScope {
/**
* 获取群成员实例. 不存在时抛出 [kotlin.NoSuchElementException]
* 当 [id] 为 [Bot.id] 时返回 [botAsMember]
*/
abstract operator fun get(id: Long): Member
/**
* 获取群成员实例, 不存在则 null
* 当 [id] 为 [Bot.id] 时返回 [botAsMember]
*/
abstract fun getOrNull(id: Long): Member?
/**
* 检查此 id 的群成员是否存在
* 当 [id] 为 [Bot.id] 时返回 `true`
*/
abstract operator fun contains(id: Long): Boolean
......
......@@ -96,17 +96,20 @@ actual abstract class Group : Contact(), CoroutineScope {
/**
* 获取群成员实例. 不存在时抛出 [kotlin.NoSuchElementException]
* 当 [id] 为 [Bot.id] 时返回 [botAsMember]
*/
actual abstract operator fun get(id: Long): Member
/**
* 获取群成员实例, 不存在则 null
* 当 [id] 为 [Bot.id] 时返回 [botAsMember]
*/
actual abstract fun getOrNull(id: Long): Member?
/**
* 检查此 id 的群成员是否存在
* 当 [id] 为 [Bot.id] 时返回 `true`
*/
actual abstract operator fun contains(id: Long): Boolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment