Him188 vor 5 Jahren
Ursprung
Commit
1f308b3018

+ 14 - 1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt

@@ -49,7 +49,7 @@ import kotlin.jvm.JvmSynthetic
  * - 连接 [Message] 与 [Message], [String], (使用操作符 [Message.plus]):
  *  ```
  * val text = PlainText("Hello ") + PlainText("world") + "!"
- * friend.sendMessage(text)
+ * friend.sendMessage(text) // "Hello world!"
  *  ```
  * 但注意: 不能 `String + Message`. 只能 `Message + String`
  *
@@ -177,18 +177,31 @@ interface Message { // must be interface. Don't consider any changes.
         }
     }
 
+    /** 将 [another] 按顺序连接到这个消息的尾部. */
     /* final */ operator fun plus(another: MessageChain): MessageChain = this + another as Message
+
+    /** 将 [another] 按顺序连接到这个消息的尾部. */
     /* final */ operator fun plus(another: Message): MessageChain = this.followedBy(another)
+
+    /** 将 [another] 连接到这个消息的尾部. */
     /* final */ operator fun plus(another: SingleMessage): MessageChain = this.followedBy(another)
+
+    /** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
     /* final */ operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage())
+
+    /** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
     /* final */ operator fun plus(another: CharSequence): MessageChain = this.followedBy(another.toString().toMessage())
+
+    /** 将 [another] 按顺序连接到这个消息的尾部. */
     /* final */ operator fun plus(another: Iterable<Message>): MessageChain =
         another.fold(this, Message::plus).asMessageChain()
 
+    /** 将 [another] 按顺序连接到这个消息的尾部. */
     @JvmName("plusIterableString")
     /* final */ operator fun plus(another: Iterable<String>): MessageChain =
         another.fold(this, Message::plus).asMessageChain()
 
+    /** 将 [another] 按顺序连接到这个消息的尾部. */
     /* final */ operator fun plus(another: Sequence<Message>): MessageChain =
         another.fold(this, Message::plus).asMessageChain()
 }

+ 16 - 1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt

@@ -62,7 +62,22 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
     /**
      * 获取第一个类型为 [key] 的 [Message] 实例. 若不存在此实例, 返回 `null`
      *
+     * ### Kotlin 使用方法
+     * ```
+     * val chain: MessageChain = ...
+     *
+     * val at = Message[At] // At 为伴生对象
+     * ```
+     *
+     * ### Java 使用方法
+     * ```java
+     * MessageChain chain = ...
+     * chain.first(At.Key)
+     * ```
+     *
      * @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key]
+     *
+     * @see MessageChain.getOrFail 在找不到此类型的元素时抛出 [NoSuchElementException]
      */
     @JvmName("first")
     final operator fun <M : Message> get(key: Message.Key<M>): M? = firstOrNull(key)
@@ -93,7 +108,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
 // region accessors
 
 /**
- * 获取第一个类型为 [key] 的 [Message] 实例
+ * 获取第一个类型为 [key] 的 [Message] 实例, 在找不到此类型的元素时抛出 [NoSuchElementException]
  *
  * @param key 由各个类型消息的伴生对象持有. 如 [PlainText.Key]
  */