diff --git a/mirai-core/src/commonMain/kotlin/message/conversions.kt b/mirai-core/src/commonMain/kotlin/message/conversions.kt index e3ab67275..64f115261 100644 --- a/mirai-core/src/commonMain/kotlin/message/conversions.kt +++ b/mirai-core/src/commonMain/kotlin/message/conversions.kt @@ -203,10 +203,20 @@ internal fun MessageChain.toRichTextElems( } } } - //MarketFaceImpl继承于MarketFace 会自动添加兼容信息 - //如果有用户不慎/强行使用也会转换为文本信息 - is MarketFaceImpl -> elements.add(ImMsgBody.Elem(marketFace = currentMessage.delegate)) - is MarketFace -> transformOneMessage(PlainText(currentMessage.contentToString())) + is MarketFace -> { + if (currentMessage is MarketFaceImpl) { + elements.add(ImMsgBody.Elem(marketFace = currentMessage.delegate)) + } + //兼容信息 + transformOneMessage(PlainText(currentMessage.name)) + if (currentMessage is MarketFaceImpl) { + elements.add( + ImMsgBody.Elem( + extraInfo = ImMsgBody.ExtraInfo(flags = 8, groupMask = 1) + ) + ) + } + } is VipFace -> transformOneMessage(PlainText(currentMessage.contentToString())) is PttMessage -> { elements.add( @@ -246,6 +256,9 @@ internal fun MessageChain.toRichTextElems( ) ) } + this.anyIsInstance() -> { + elements.add(ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = PB_RESERVE_FOR_MARKET_FACE))) + } this.anyIsInstance() -> { // 08 09 78 00 A0 01 81 DC 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 98 03 00 A0 03 20 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 02 08 03 90 04 80 80 80 10 B8 04 00 C0 04 00 elements.add(ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = PB_RESERVE_FOR_RICH_MESSAGE))) @@ -271,6 +284,8 @@ private val PB_RESERVE_FOR_PTT = @Suppress("SpellCheckingInspection") private val PB_RESERVE_FOR_DOUTU = "78 00 90 01 01 F8 01 00 A0 02 00 C8 02 00".hexToBytes() +private val PB_RESERVE_FOR_MARKET_FACE = + "02 78 80 80 04 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00 98 03 00 A0 03 00 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 04 08 02 10 3B 90 04 80 C0 80 80 04 B8 04 00 C0 04 00 CA 04 00 F8 04 80 80 04 88 05 00".hexToBytes() private val PB_RESERVE_FOR_ELSE = "78 00 F8 01 00 C8 02 00".hexToBytes() internal fun MsgComm.Msg.toMessageChain( @@ -353,12 +368,6 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain { return@forEach } } - if (last is MarketFaceImpl && element is PlainText) { - if (element.content == (last as MarketFaceImpl).name) { - last = element - return@forEach - } - } if (last is PokeMessage && element is PlainText) { if (element == UNSUPPORTED_POKE_MESSAGE_PLAIN) { last = element @@ -409,6 +418,7 @@ internal val MIRAI_CUSTOM_ELEM_TYPE = "mirai".hashCode() // 103904510 internal fun List.joinToMessageChain(groupIdOrZero: Long, botId: Long, list: MessageChainBuilder) { // (this._miraiContentToString().soutv()) + var marketFace: MarketFaceImpl? = null this.forEach { element -> when { element.srcMsg != null -> { @@ -419,7 +429,11 @@ internal fun List.joinToMessageChain(groupIdOrZero: Long, botId: element.face != null -> list.add(Face(element.face.index)) element.text != null -> { if (element.text.attr6Buf.isEmpty()) { - list.add(PlainText(element.text.str)) + if (marketFace != null && marketFace!!.name.isEmpty()) { + marketFace!!.delegate.faceName = element.text.str.toByteArray() + } else { + list.add(PlainText(element.text.str)) + } } else { val id: Long element.text.attr6Buf.read { @@ -434,7 +448,9 @@ internal fun List.joinToMessageChain(groupIdOrZero: Long, botId: } } element.marketFace != null -> { - list.add(MarketFaceImpl(element.marketFace)) + list.add(MarketFaceImpl(element.marketFace).also { + marketFace = it + }) } element.lightApp != null -> { val content = runWithBugReport("解析 lightApp", @@ -588,4 +604,4 @@ internal inline fun runWithBugReport(context: String, forDebug: () -> String return runCatching(block).getOrElse { throw contextualBugReportException(context, forDebug(), it) } -} \ No newline at end of file +} diff --git a/mirai-core/src/commonMain/kotlin/message/faceImpl.kt b/mirai-core/src/commonMain/kotlin/message/faceImpl.kt index bc2359c72..5fe2d7b3e 100644 --- a/mirai-core/src/commonMain/kotlin/message/faceImpl.kt +++ b/mirai-core/src/commonMain/kotlin/message/faceImpl.kt @@ -47,8 +47,9 @@ internal fun Face.toCommData(): ImMsgBody.CommonElem { internal data class MarketFaceImpl internal constructor( internal val delegate: ImMsgBody.MarketFace, ) : MarketFace { - @Transient - override val name: String = delegate.faceName.decodeToString() + + override val name: String get() = delegate.faceName.decodeToString() + @Transient override val id: Int = delegate.tabId diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt index 0862c536c..5eb1099b5 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/Msg.kt @@ -564,7 +564,7 @@ internal class ImMsgBody : ProtoBuf { @Serializable internal data class MarketFace( - @ProtoNumber(1) @JvmField val faceName: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(1) @JvmField var faceName: ByteArray = EMPTY_BYTE_ARRAY, @ProtoNumber(2) @JvmField val itemType: Int = 0, @ProtoNumber(3) @JvmField val faceInfo: Int = 0, @ProtoNumber(4) @JvmField val faceId: ByteArray = EMPTY_BYTE_ARRAY,