@SinceMirai("0.39.0") class ForwardMessageBuilder : MutableList<INode>
转发消息 DSL 构建器.
使用 DSL 构造一个转发:
buildForwardMessage {
123456789 named "鸽子 A" says "咕" // 意为 名为 "鸽子 A" 的用户 123456789 发送了一条内容为 "咕" 的消息
100200300 named "鸽子 C" at 1582315452 says "咕咕咕" // at 设置时间 (在 PC 端显示, 在手机端不影响顺序)
987654321 named "鸽子 B" says "咕" // 未指定时间, 则自动顺序安排时间
myFriend says "咕" // User.says
bot says { // 构造消息链, 同 `buildMessageChain`
+"发个图片试试"
+Image("{90CCED1C-2D64-313B-5D66-46625CAB31D7}.jpg")
}
val member: Member = ...
member says "我是幸运群员" // 使用 `User says` 则会同时设置发送人名称
}
下文中 S
代表消息发送人. 可接受: 发送人账号 id(Long 或 Int) 或 User
下文中 M
代表消息内容. 可接受: String, Message, 或 构造消息链 的 DSL 代码块
语句 123456789 named "鸽子 A" says "咕"
创建并添加了一条名为 "鸽子 A" 的用户 123456789 发送的内容为 "咕" 的消息
一条 '陈述' 必须包含以下属性:
sender says M
, sender named "xxx"
, sender at 123
says
函数的参数设置, 即 says M
.现支持的可选属性为 named
, at
最基础的陈述为 S says M
. 可在 says
前按任意顺序添加组合属性:
S named "xxx" says M
;
S at 123456 says M
; 其中 123456
为发信时间
属性的顺序并不重要. 如下两句陈述效果相同.
S named "xxx" at 123456 says M
;
S at 123456 named "xxx" says M
;
若属性有重复, 新属性会替换旧属性.
S named "name1" named "name2" says M
最终的发送人名称为 "name2"
BuilderNode |
inner class BuilderNode : INode |
<init> |
ForwardMessageBuilder(context: Contact) ForwardMessageBuilder(context: Contact, initialSize: Int) |
context |
val context: Contact |
currentTime |
当前时间. 在使用 says 时若不指定时间, 则会使用 currentTime 自增 1 的时间. var currentTime: Int |
displayStrategy |
var displayStrategy: DisplayStrategy |
at |
为一条消息指定时间. infix fun Int.at(time: Int): BuilderNode infix fun Long.at(time: Int): BuilderNode
为一条消息指定时间和发送人名称. infix fun User.at(time: Int): BuilderNode |
build |
fun build(): ForwardMessage |
named |
为一条消息指定发送人名称. infix fun Int.named(name: String): BuilderNode infix fun Long.named(name: String): BuilderNode infix fun User.named(name: String): BuilderNode |
says |
添加一条消息, 自动按顺序调整时间 infix fun Long.says(message: String): ForwardMessageBuilder infix fun Int.says(message: String): ForwardMessageBuilder infix fun Long.says(message: Message): ForwardMessageBuilder infix fun Int.says(message: Message): ForwardMessageBuilder infix fun Int.says(chain: MessageChainBuilder.() -> Unit): ForwardMessageBuilder infix fun Bot.says(message: String): ForwardMessageBuilder infix fun User.says(message: String): ForwardMessageBuilder infix fun User.says(message: Message): ForwardMessageBuilder infix fun Bot.says(message: Message): ForwardMessageBuilder
构造并添加一个 MessageChain, 自动按顺序调整时间 infix fun Long.says(chain: MessageChainBuilder.() -> Unit): ForwardMessageBuilder infix fun User.says(chain: MessageChainBuilder.() -> Unit): ForwardMessageBuilder infix fun Bot.says(chain: MessageChainBuilder.() -> Unit): ForwardMessageBuilder |