mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-13 06:30:13 +08:00
[Review] Improve Message.isContentEmpty, add Message.isContentBlank
This commit is contained in:
parent
3cda506c46
commit
ca6dbd2740
@ -288,20 +288,24 @@ public suspend inline fun <C : Contact> Message.sendTo(contact: C): MessageRecei
|
||||
|
||||
|
||||
/**
|
||||
* 判断消息内容是否为空.
|
||||
*
|
||||
* 以下情况视为 "空消息":
|
||||
*
|
||||
* - 是 [MessageMetadata] (因为 [MessageMetadata.contentToString] 都必须返回空字符串)
|
||||
* - [PlainText] 长度为 0
|
||||
* - [MessageChain] 所有元素都满足 [isContentEmpty]
|
||||
* 当消息内容为空时返回 `true`.
|
||||
* @see String.isEmpty
|
||||
*/
|
||||
public fun Message.isContentEmpty(): Boolean {
|
||||
return when (this) {
|
||||
is MessageMetadata -> true
|
||||
is PlainText -> this.content.isEmpty()
|
||||
is MessageChain -> this.all { it.isContentEmpty() }
|
||||
else -> false
|
||||
else -> this.content.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当消息内容为空白时返回 `true`.
|
||||
* @see String.isBlank
|
||||
*/
|
||||
public fun Message.isContentBlank(): Boolean {
|
||||
return when (this) {
|
||||
is MessageChain -> this.all { it.isContentBlank() }
|
||||
else -> this.content.isBlank()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user