Fix inconsistent message length (#855)

* Fix #195 again, also fix #539

* Let AtAll consistent with At

Co-authored-by: Him188 <Him188@mamoe.net>

Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
sandtechnology 2021-01-13 17:25:07 +08:00 committed by GitHub
parent 9d25f05569
commit 72f870a3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,8 +11,6 @@ package net.mamoe.mirai.internal.utils
import net.mamoe.mirai.contact.ContactOrBot
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.AtAll.display
import net.mamoe.mirai.utils.safeCast
internal fun Int.toIpV4AddressString(): String {
@ -48,10 +46,10 @@ internal fun MessageChain.estimateLength(target: ContactOrBot, upTo: Int): Int =
internal fun SingleMessage.estimateLength(target: ContactOrBot, upTo: Int): Int {
return when (this) {
is QuoteReply -> 444 + this.source.originalMessage.estimateLength(target, upTo) // Magic number
is Image -> 260 // Magic number
is Image -> 40 //magic number
is PlainText -> content.chineseLength(upTo)
is At -> this.getDisplay(target.safeCast()).chineseLength(upTo)
is AtAll -> display.chineseLength(upTo)
is At -> 60 //magic number
is AtAll -> 60 //magic number
else -> this.toString().chineseLength(upTo)
}
}