CustomMessage

sealed class CustomMessage : SingleMessage

自定义消息

它不会显示在消息文本中, 也不会被其他客户端识别. 只有 mirai 才能识别这些消息.

目前在回复时无法通过 MessageSource.originalMessage 获取自定义类型消息

序列化

若要支持序列化, 需 MessageSerializers.registerSerializer

Samples

samples.CustomMessageIdentifier

See also

Types

Companion
Link copied to clipboard
object Companion
Factory
Link copied to clipboard
abstract class Factory<M : CustomMessage>(typeName: String)

序列化和反序列化此消息的工厂, 将会自动注册. 应实现为 object.

JsonSerializerFactory
Link copied to clipboard
abstract class JsonSerializerFactory<M : CustomMessage>(typeName: String) : CustomMessage.Factory<M>

使用 Json 作为序列模式的 Factory 推荐在调试时使用此工厂

ProtoBufSerializerFactory
Link copied to clipboard
abstract class ProtoBufSerializerFactory<M : CustomMessage>(typeName: String) : CustomMessage.Factory<M>

使用 ProtoBuf 作为序列模式的 Factory. 推荐使用此工厂

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".

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
abstract override fun toString(): String

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

Inheritors

CustomMessageMetadata
Link copied to clipboard