This commit is contained in:
Him188 2020-04-23 19:29:19 +08:00
parent 4a217d83a6
commit 2d96314d72
2 changed files with 5 additions and 1 deletions

View File

@ -162,22 +162,26 @@ abstract class Member : MemberJavaFriendlyAPI() {
*
* @throws IllegalStateException 当此成员不是好友时抛出
*/
@SinceMirai("0.39.0")
fun Member.asFriend(): Friend = this.bot.getFriendOrNull(this.id) ?: error("$this is not a friend")
/**
* 得到此成员作为好友的对象.
*/
@SinceMirai("0.39.0")
fun Member.asFriendOrNull(): Friend? = this.bot.getFriendOrNull(this.id)
/**
* 判断此成员是否为好友
*/
@SinceMirai("0.39.0")
inline val Member.isFriend: Boolean
get() = this.bot.friends.contains(this.id)
/**
* 如果此成员是好友, 则执行 [block] 并返回其返回值. 否则返回 `null`
*/
@SinceMirai("0.39.0")
inline fun <R> Member.takeIfIsFriend(block: (Friend) -> R): R? {
return this.asFriendOrNull()?.let(block)
}

View File

@ -263,7 +263,7 @@ annotation class ForwardMessageDsl
* 123456789 named "鸽子 A" says "" // 意为 名为 "鸽子 A" 的用户 123456789 发送了一条内容为 "咕" 的消息
* 100200300 named "鸽子 C" at 1582315452 says "咕咕咕" // at 设置时间 (在 PC 端显示, 在手机端不影响顺序)
* 987654321 named "鸽子 B" says "" // 未指定时间, 则自动顺序安排时间
* 5555555 says "" // 未指定发送人
* myFriend says "" // User.says
* bot says { // 构造消息链, 同 `buildMessageChain`
* +"发个图片试试"
* +Image("{90CCED1C-2D64-313B-5D66-46625CAB31D7}.jpg")