diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt index 142a8c4a0..cf327da36 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt @@ -163,7 +163,7 @@ class MessageSubscribersBuilder>( crossinline onEvent: @MessageDsl suspend T.(String) -> Unit ): Listener = content({ it.startsWith(prefix) }) { - if (removePrefix) this.onEvent(this.message.stringValue.substringAfter(prefix)) + if (removePrefix) this.onEvent(this.message.toString().substringAfter(prefix)) else onEvent(this, this.message.toString()) } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt index c0492697e..667bc16b0 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt @@ -11,8 +11,7 @@ import net.mamoe.mirai.contact.QQ inline class At(val target: Long) : Message { constructor(target: QQ) : this(target.id) - override val stringValue: String get() = "[@$target]" // TODO: 2019/11/25 使用群名称进行 at. 因为手机端只会显示这个文字 - override fun toString(): String = stringValue + override fun toString(): String = "[@$target]" // TODO: 2019/11/25 使用群名称进行 at. 因为手机端只会显示这个文字 companion object Key : Message.Key } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt index 1096494d5..507ea34ee 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Face.kt @@ -6,8 +6,7 @@ import kotlin.jvm.JvmStatic * QQ 自带表情 */ inline class Face(val id: FaceId) : Message { - override val stringValue: String get() = "[face${id.value}]" - override fun toString(): String = stringValue + override fun toString(): String = "[face${id.value}]" companion object Key : Message.Key } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt index dc1756267..cc4af34b4 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt @@ -14,8 +14,7 @@ import net.mamoe.mirai.utils.ExternalImage * @param id 这个图片的 [ImageId] */ inline class Image(inline val id: ImageId) : Message { - override val stringValue: String get() = "[${id.value}]" - override fun toString(): String = stringValue + override fun toString(): String = "[${id.value}]" companion object Key : Message.Key } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt index 39a508534..3bf641d2c 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt @@ -47,18 +47,6 @@ import net.mamoe.mirai.contact.sendMessage * @see Contact.sendMessage 发送消息 */ interface Message { - /** - * 易读的 [String] 值 - * 如: - * ``` - * [@123456789] - * [face123] - * ``` - * - * 使用 [toString] 将得到同样的值 - */ - val stringValue: String - /** * 类型 Key. * 除 [MessageChain] 外, 每个 [Message] 类型都拥有一个`伴生对象`(companion object) 来持有一个 Key @@ -73,7 +61,7 @@ interface Message { /** * 将 [stringValue] 与 [other] 比较 */ - infix fun eq(other: String): Boolean = this.stringValue == other + infix fun eq(other: String): Boolean = this.toString() == other operator fun contains(sub: String): Boolean = false diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt index 87f20e6c9..45c72c825 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt @@ -20,8 +20,6 @@ import kotlin.reflect.KProperty */ interface MessageChain : Message, MutableList { // region Message override - override val stringValue: String - override operator fun contains(sub: String): Boolean override fun followedBy(tail: Message): MessageChain // endregion @@ -185,10 +183,7 @@ class EmptyMessageChain : MessageChain { toIndex ) else throw IndexOutOfBoundsException("given args that from $fromIndex to $toIndex, but the list is empty") - override val stringValue: String - get() = if (initialized) delegate.stringValue else "" - - override fun toString(): String = stringValue + override fun toString(): String = if (initialized) delegate.toString() else "" override fun contains(sub: String): Boolean = if (initialized) delegate.contains(sub) else false override fun contains(element: Message): Boolean = if (initialized) delegate.contains(element) else false @@ -240,8 +235,6 @@ class EmptyMessageChain : MessageChain { object NullMessageChain : MessageChain { override fun subList(fromIndex: Int, toIndex: Int): MutableList = error("accessing NullMessageChain") - override val stringValue: String get() = "null" - override fun toString(): String = "null" override fun contains(sub: String): Boolean = error("accessing NullMessageChain") @@ -291,9 +284,7 @@ internal inline class MessageChainImpl constructor( constructor(vararg messages: Message) : this(messages.toMutableList()) // region Message override - override val stringValue: String get() = this.delegate.joinToString("") { it.stringValue } - - override fun toString(): String = stringValue + override fun toString(): String = this.delegate.joinToString("") { it.toString() } override operator fun contains(sub: String): Boolean = delegate.any { it.contains(sub) } override fun followedBy(tail: Message): MessageChain { @@ -342,8 +333,6 @@ internal inline class SingleMessageChainImpl( MessageChain { // region Message override - override val stringValue: String get() = this.delegate.stringValue - override operator fun contains(sub: String): Boolean = delegate.contains(sub) override fun followedBy(tail: Message): MessageChain { require(tail !is SingleOnly) { "SingleOnly Message cannot follow another message" } @@ -354,7 +343,7 @@ internal inline class SingleMessageChainImpl( override fun plusAssign(message: Message) = throw UnsupportedOperationException("SingleMessageChainImpl cannot be plusAssigned") - override fun toString(): String = stringValue + override fun toString(): String = delegate.toString() // endregion // region MutableList override diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt index f591994a4..67b784862 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/PlainText.kt @@ -1,7 +1,7 @@ package net.mamoe.mirai.message.data -inline class PlainText(override val stringValue: String) : Message { +inline class PlainText(val stringValue: String) : Message { override operator fun contains(sub: String): Boolean = sub in stringValue override fun toString(): String = stringValue diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt index e86afdd81..78b0ca2a1 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt @@ -7,7 +7,7 @@ package net.mamoe.mirai.message.data * * @see buildXMLMessage */ -inline class XMLMessage(override val stringValue: String) : Message, +inline class XMLMessage(val stringValue: String) : Message, SingleOnly { override fun followedBy(tail: Message): Nothing = error("XMLMessage Message cannot be followed") override fun toString(): String = stringValue diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt index 8ec4f5104..13bc5d5e3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt @@ -242,7 +242,7 @@ fun MessageChain.toPacket(): ByteReadPacket = buildPacket { writeShortLVPacket { writeByte(0x01) - writeShortLVString(stringValue) // 这个应该是 "@群名", 手机上面会显示这个消息, 电脑会显示下面那个 + writeShortLVString(message.toString()) // 这个应该是 "@群名", 手机上面会显示这个消息, 电脑会显示下面那个 // 06 00 0D 00 01 00 00 00 08 00 76 E4 B8 DD 00 00 writeHex("06 00 0D 00 01 00 00 00 08 00") writeQQ(target)