MessageChainBuilder

MessageChain 构建器.

注意: 无并发安全性.

连续 String 优化

多个连续的 String 会被连接为单个 PlainText 以优化性能。

MessageChain chain = new MessageChainBuilder()
.append("Hello ")
.append("mirai!")
.build();

// chain 将会只包含一个 [PlainText], 其内容为 "Hello mirai!".

Kotlin 示例

val chain = buildMessageChain {
+PlainText("a")
+AtAll
+Image("/f8f1ab55-bf8e-4236-b55e-955848d7069f")
add(At(123456))
}

该示例中 +MessageChainBuilder.unaryPlus. 使用 + 和使用 add 是相等的.

Java 示例

MessageChain chain = new MessageChainBuilder()
.append(new PlainText("string"))
.append("string") // 会被构造成 PlainText 再添加, 相当于上一行
.append(AtAll.INSTANCE)
.append(Image.fromId("{f8f1ab55-bf8e-4236-b55e-955848d7069f}.png"))
.build();

See also

Constructors

Link copied to clipboard
constructor()
constructor(initialSize: Int)

Functions

Link copied to clipboard
open override fun add(index: Int, element: SingleMessage)
fun add(plain: String)
fun add(element: Message): Boolean
open override fun add(element: SingleMessage): Boolean
Link copied to clipboard
open override fun addAll(index: Int, elements: Collection<SingleMessage>): Boolean
open override fun addAll(elements: Collection<SingleMessage>): Boolean
@JvmName(name = "addAllFlatten")
fun addAll(elements: Iterable<Message>): Boolean
Link copied to clipboard
open override fun append(value: Char): MessageChainBuilder
open override fun append(value: CharSequence?): MessageChainBuilder
open override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): MessageChainBuilder
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun clear()
Link copied to clipboard
open operator override fun contains(element: SingleMessage): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<SingleMessage>): Boolean
Link copied to clipboard

将所有已有元素引用复制到一个新的 MessageChainBuilder

Link copied to clipboard
open operator override fun get(index: Int): SingleMessage
Link copied to clipboard
open override fun indexOf(element: SingleMessage): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<SingleMessage>
Link copied to clipboard
open override fun lastIndexOf(element: SingleMessage): Int
Link copied to clipboard
Link copied to clipboard
operator fun plusAssign(charSequence: CharSequence)
operator fun plusAssign(plain: String)
operator fun plusAssign(message: Message)
operator fun plusAssign(message: SingleMessage)
Link copied to clipboard
open override fun remove(element: SingleMessage): Boolean
Link copied to clipboard
open override fun removeAll(elements: Collection<SingleMessage>): Boolean
Link copied to clipboard
open override fun removeAt(index: Int): SingleMessage
Link copied to clipboard
open override fun retainAll(elements: Collection<SingleMessage>): Boolean
Link copied to clipboard

转换得到 mirai 码.

Link copied to clipboard
open operator override fun set(index: Int, element: SingleMessage): SingleMessage
Link copied to clipboard
open override fun subList(fromIndex: Int, toIndex: Int): MutableList<SingleMessage>
Link copied to clipboard
Link copied to clipboard

扁平化 this 并创建一个 MessageChain.

Link copied to clipboard
operator fun String.unaryPlus()
operator fun Message.unaryPlus()

Properties

Link copied to clipboard
open override val size: Int