CustomMessageMetadata

abstract class CustomMessageMetadata : CustomMessage, MessageMetadata

自定义消息元数据.

实现方法:

  1. 实现一个类继承 CustomMessageMetadata, 添加 @Serializable (来自 kotlinx.serialization)

  2. 添加伴生对象, 继承 CustomMessage.ProtoBufSerializerFactoryCustomMessage.JsonSerializerFactory, 或 CustomMessage.Factory

  3. 在需要解析消息前调用一次伴生对象以注册

注意: 这是实验性 API. 可能会在未来发生变动.

See also

可实现此接口以保证消息链中只存在一个元素

Constructors

CustomMessageMetadata
Link copied to clipboard
fun CustomMessageMetadata()

Types

Companion
Link copied to clipboard
object Companion

Functions

contentEquals
Link copied to clipboard
open fun contentEquals(another: String, ignoreCase: Boolean = false): Boolean

判断内容是否与 another 相等.

open fun contentEquals(another: Message, ignoreCase: Boolean = false): Boolean

判断内容是否与 another 相等即 thisanothercontentToString 相等.

open fun contentEquals(another: Message, ignoreCase: Boolean = false, strict: Boolean = false): Boolean

判断内容是否与 another 相等即 thisanothercontentToString 相等. stricttrue 时, 还会额外判断每个消息元素的类型, 顺序和属性. 如 Image 会判断 Image.imageId

contentToString
Link copied to clipboard
abstract fun contentToString(): String

转为最接近官方格式的字符串. 如 At(member) + "test" 将转为 "@群名片 test".

customToString
Link copied to clipboard
open fun customToString(): ByteArray
followedBy
Link copied to clipboard
open fun followedBy(tail: Message): MessageChain

thistail 连接.

getFactory
Link copied to clipboard
abstract fun getFactory(): CustomMessage.Factory<out CustomMessage>

获取这个消息的工厂

plus
Link copied to clipboard
open operator fun plus(another: Array<out Message>): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: CharSequence): MessageChain

another 作为 PlainText 连接到这个消息的尾部.

open operator fun plus(another: String): MessageChain

another 作为 PlainText 连接到这个消息的尾部.

open operator fun plus(another: Iterable<String>): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: Iterable<Message>): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: Sequence<Message>): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: Message): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: MessageChain): MessageChain

another 按顺序连接到这个消息的尾部.

open operator fun plus(another: SingleMessage): MessageChain

another 连接到这个消息的尾部.

toString
Link copied to clipboard
override fun toString(): String

得到包含 mirai 消息元素代码的, 易读的字符串. 如 At(member) + "test" 将转为 "[mirai:at:qqId]test".