Commit e23f91ba authored by Him188's avatar Him188

Estimate length of originalMessage

parent 6f5441bf
......@@ -13,6 +13,7 @@
package net.mamoe.mirai.qqandroid.utils
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.AtAll.display
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
......@@ -33,7 +34,7 @@ internal fun Int.toIpV4AddressString(): String {
internal fun String.chineseLength(upTo: Int): Int {
return this.sumUpTo(upTo) {
when(it) {
when (it) {
in '\u0000'..'\u007F' -> 1
in '\u0080'..'\u07FF' -> 2
in '\u0800'..'\uFFFF' -> 3
......@@ -42,14 +43,14 @@ internal fun String.chineseLength(upTo: Int): Int {
}
}
internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int =
internal fun MessageChain.estimateLength(upTo: Int): Int =
sumUpTo(upTo) { it, up ->
it.estimateLength(up)
}
internal fun SingleMessage.estimateLength(upTo: Int = Int.MAX_VALUE): Int {
internal fun SingleMessage.estimateLength(upTo: Int): Int {
return when (this) {
is QuoteReply -> 444 // Magic number
is QuoteReply -> 444 + this.source.originalMessage.estimateLength(upTo) // Magic number
is Image -> 260 // Magic number
is PlainText -> stringValue.chineseLength(upTo)
is At -> display.chineseLength(upTo)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment