mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Make SingleMessage
not extending CharSequence
for clearer semantics
This commit is contained in:
parent
b30b508f4b
commit
0de76149c8
@ -178,12 +178,6 @@ class ForwardMessage @JvmOverloads constructor(
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
override fun contentToString(): String = contentToString
|
||||
override val length: Int get() = contentToString.length
|
||||
override fun get(index: Int): Char = contentToString[length]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence =
|
||||
contentToString.subSequence(startIndex, endIndex)
|
||||
|
||||
override fun compareTo(other: String): Int = contentToString.compareTo(other)
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,13 +140,7 @@ data class PokeMessage internal constructor(
|
||||
private val stringValue = "[mirai:poke:$type,$id]"
|
||||
|
||||
override fun toString(): String = stringValue
|
||||
override val length: Int get() = stringValue.length
|
||||
override fun get(index: Int): Char = stringValue[index]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence =
|
||||
stringValue.subSequence(startIndex, endIndex)
|
||||
|
||||
override fun contentToString(): String = "[戳一戳]"
|
||||
override fun compareTo(other: String): Int = stringValue.compareTo(other)
|
||||
//businessType=0x00000001(1)
|
||||
//pbElem=08 01 18 00 20 FF FF FF FF 0F 2A 00 32 00 38 00 50 00
|
||||
//serviceType=0x00000002(2)
|
||||
@ -231,13 +225,7 @@ data class VipFace internal constructor(
|
||||
private val stringValue = "[mirai:vipface:$kind,$count]"
|
||||
|
||||
override fun toString(): String = stringValue
|
||||
override val length: Int get() = stringValue.length
|
||||
override fun get(index: Int): Char = stringValue[index]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence =
|
||||
stringValue.subSequence(startIndex, endIndex)
|
||||
|
||||
override fun contentToString(): String = "[${kind.name}]x$count"
|
||||
override fun compareTo(other: String): Int = stringValue.compareTo(other)
|
||||
}
|
||||
|
||||
|
||||
@ -299,11 +287,6 @@ sealed class FlashImage : MessageContent, HummerMessage() {
|
||||
}
|
||||
|
||||
override fun toString(): String = stringValue!!
|
||||
override val length: Int get() = stringValue!!.length
|
||||
override fun get(index: Int) = stringValue!![index]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int) = stringValue!!.subSequence(startIndex, endIndex)
|
||||
override fun compareTo(other: String) = other.compareTo(stringValue!!)
|
||||
|
||||
override fun contentToString(): String = "[闪照]"
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,7 @@ val FRIEND_IMAGE_ID_REGEX_2 = Regex("""/[0-9]*-[0-9]*-[0-9a-zA-Z]{32}""")
|
||||
*
|
||||
* `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.mirai`
|
||||
*/
|
||||
@Suppress("RegExpRedundantEscape") // This is required on Android
|
||||
@SinceMirai("0.39.2")
|
||||
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
|
||||
val GROUP_IMAGE_ID_REGEX = Regex("""\{.{8}-(.{4}-){3}.{12}\}\.mirai""")
|
||||
@ -117,6 +118,7 @@ val GROUP_IMAGE_ID_REGEX = Regex("""\{.{8}-(.{4}-){3}.{12}\}\.mirai""")
|
||||
/**
|
||||
* 在 `0.39.0` 前的图片的正则表示
|
||||
*/
|
||||
@Suppress("RegExpRedundantEscape") // This is required on Android
|
||||
@Deprecated("Only for temporal use",
|
||||
replaceWith = ReplaceWith("GROUP_IMAGE_ID_REGEX", "net.mamoe.mirai.message.data.GROUP_IMAGE_ID_REGEX"))
|
||||
@SinceMirai("0.39.2")
|
||||
@ -323,12 +325,6 @@ sealed class AbstractImage : Image {
|
||||
field = "[mirai:image:$imageId]"
|
||||
field
|
||||
}
|
||||
override val length: Int get() = _stringValue!!.length
|
||||
override fun get(index: Int): Char = _stringValue!![index]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence =
|
||||
_stringValue!!.subSequence(startIndex, endIndex)
|
||||
|
||||
override fun compareTo(other: String): Int = _stringValue!!.compareTo(other)
|
||||
final override fun toString(): String = _stringValue!!
|
||||
final override fun contentToString(): String = "[图片]"
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ interface Message { // must be interface. Don't consider any changes.
|
||||
@SinceMirai("0.39.3")
|
||||
fun Message.isContentEmpty(): Boolean = when (this) {
|
||||
is MessageMetadata -> true
|
||||
is PlainText -> this.isEmpty()
|
||||
is PlainText -> this.stringValue.isEmpty()
|
||||
is MessageChain -> this.all { it.isContentEmpty() }
|
||||
else -> false
|
||||
}
|
||||
@ -312,7 +312,7 @@ inline fun Message.repeat(count: Int): MessageChain {
|
||||
inline operator fun Message.times(count: Int): MessageChain = this.repeat(count)
|
||||
|
||||
@Suppress("OverridingDeprecatedMember")
|
||||
interface SingleMessage : Message, CharSequence, Comparable<String> {
|
||||
interface SingleMessage : Message {
|
||||
@PlannedRemoval("1.0.0")
|
||||
@JvmSynthetic
|
||||
@Deprecated(
|
||||
@ -352,12 +352,7 @@ interface SingleMessage : Message, CharSequence, Comparable<String> {
|
||||
*
|
||||
* @see ConstrainSingle 约束一个 [MessageChain] 中只存在这一种类型的元素
|
||||
*/
|
||||
interface MessageMetadata : SingleMessage {
|
||||
override val length: Int get() = 0
|
||||
override fun get(index: Int): Char = ""[index] // produce uniform exception
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = "".subSequence(startIndex, endIndex)
|
||||
override fun compareTo(other: String): Int = "".compareTo(other)
|
||||
}
|
||||
interface MessageMetadata : SingleMessage
|
||||
|
||||
/**
|
||||
* 约束一个 [MessageChain] 中只存在这一种类型的元素. 新元素将会替换旧元素, 保持原顺序.
|
||||
|
@ -86,11 +86,6 @@ interface RichMessage : MessageContent {
|
||||
}
|
||||
|
||||
val content: String
|
||||
|
||||
override val length: Int get() = content.length
|
||||
override fun get(index: Int): Char = content[index]
|
||||
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = content.subSequence(startIndex, endIndex)
|
||||
override fun compareTo(other: String): Int = content.compareTo(other)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user