Add Message.isContentEmpty

This commit is contained in:
Him188 2020-04-25 12:40:40 +08:00
parent 48362a241c
commit 86aacc5d47

View File

@ -57,6 +57,11 @@ import kotlin.jvm.JvmSynthetic
* #### 实现规范
* [MessageChain] , 所有 [Message] 的实现类都有伴生对象实现 [Key] 接口.
*
* #### [CharSequence] 继承
* 所有 [CharSequence] 的行为均由 [toString] 委托.
*
* , `appendable.append(message)` 相当于 `appendable.append(message.toString())`
*
* @see PlainText 纯文本
* @see Image 图片
* @see Face 原生表情
@ -261,6 +266,13 @@ interface Message { // must be interface. Don't consider any changes.
this.followedByInternalForBinaryCompatibility(another.toString().toMessage())
}
@SinceMirai("0.39.3")
fun Message.isContentEmpty(): Boolean = when (this) {
is PlainText -> this.isEmpty()
is MessageChain -> this.any { it.isContentEmpty() }
else -> false
}
inline fun Message.isPlain(): Boolean = this is PlainText
inline fun Message.isNotPlain(): Boolean = this !is PlainText