1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-17 09:09:23 +08:00

Bot.getFriend now returns Bot.asFriend if id == bot.id

This commit is contained in:
Him188 2020-12-30 19:34:57 +08:00
parent d33948ac14
commit 8732cc1fc4

View File

@ -100,9 +100,10 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
/**
* [对方 QQ 号码][id] 获取一个好友对象, 在获取失败时返回 `null`.
* [id] [Bot.id] 相同时返回 [Bot.asFriend]
*/
public fun getFriend(id: Long): Friend? =
friends.firstOrNull { it.id == id }
friends.firstOrNull { it.id == id } ?: asFriend
/**
* [对方 QQ 号码][id] 获取一个好友对象, 在获取失败时抛出 [NoSuchElementException].