OnlineMessageSource

sealed class OnlineMessageSource : MessageSource

在线消息的 MessageSource. 拥有对象化的 sender, target, 也可以直接 recallMessagequote

来源

机器人主动发送消息

当机器人 主动发出消息, 将会得到一个 消息回执. 此回执的 消息源 即为一个 外向消息源, 代表着刚刚发出的那条消息的来源.

机器人接受消息

当机器人接收一条消息 MessageEvent, 这条消息包含一个 内向消息源, 代表着接收到的这条消息的来源.

实现

此类的所有子类都有协议模块实现. 不要自行实现它们, 否则将无法发送

See also

Types

Incoming
Link copied to clipboard
sealed class Incoming : OnlineMessageSource

接收到的一条消息的 MessageSource

Key
Link copied to clipboard
object Key : AbstractMessageKey<OnlineMessageSource>
Outgoing
Link copied to clipboard
sealed class Outgoing : OnlineMessageSource

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 连接.

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:source:${ids.contentToString()},${internalIds.contentToString()}]"

Properties

bot
Link copied to clipboard
abstract val bot: Bot
botId
Link copied to clipboard
override val botId: Long

所属 Bot.id

fromId
Link copied to clipboard
abstract val fromId: Long

发送人用户 ID.

ids
Link copied to clipboard
abstract val ids: IntArray

消息 ids (序列号). 在获取失败时 (概率很低) 为空数组.

internalIds
Link copied to clipboard
abstract val internalIds: IntArray

内部 ids. 仅用于协议模块使用

key
Link copied to clipboard
override val key: MessageKey<MessageSource>

用于判断是否为同一种元素的 MessageKey. 使用多态类型 MessageKey 最上层的 MessageKey.

originalMessage
Link copied to clipboard
abstract val originalMessage: MessageChain

该 source 指代的原消息内容.

sender
Link copied to clipboard
abstract val sender: ContactOrBot

消息发送人. 可能为 机器人好友群员. 即类型必定为 Bot, FriendMember

subject
Link copied to clipboard
abstract val subject: Contact

消息主体. 群消息时为 Group. 好友消息时为 Friend, 临时消息为 Member 不论是机器人接收的消息还是发送的消息, 此属性都指向机器人能进行回复的目标.

target
Link copied to clipboard
abstract val target: ContactOrBot

消息发送目标. 可能为 机器人好友. 即类型必定为 Bot, FriendGroup

targetId
Link copied to clipboard
abstract val targetId: Long

消息发送目标用户或群号码.

time
Link copied to clipboard
abstract val time: Int

发送时间时间戳, 单位为秒.

Inheritors

Outgoing
Link copied to clipboard
Incoming
Link copied to clipboard

Extensions

kind
Link copied to clipboard
val OnlineMessageSource.kind: MessageSourceKind
toOffline
Link copied to clipboard
fun OnlineMessageSource.toOffline(): OfflineMessageSource

将在线消息源转换为离线消息源.