Remove stringValue

This commit is contained in:
Him188 2019-12-24 22:33:56 +08:00
parent 8ca7a5107a
commit 308988faae
9 changed files with 11 additions and 37 deletions

View File

@ -163,7 +163,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
crossinline onEvent: @MessageDsl suspend T.(String) -> Unit
): Listener<T> =
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())
}

View File

@ -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<At>
}

View File

@ -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<Face>
}

View File

@ -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<Image>
}

View File

@ -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

View File

@ -20,8 +20,6 @@ import kotlin.reflect.KProperty
*/
interface MessageChain : Message, MutableList<Message> {
// 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<Message> = 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

View File

@ -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

View File

@ -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

View File

@ -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)