From b42a57736d8f68bcb38cf98bf8b199c37d83b643 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 11 Nov 2021 23:30:29 +0800 Subject: [PATCH] Fix ServiceMessage not refined in `ANDROID_WATCH`; fix #1652 --- .../kotlin/message/ReceiveMessageHandler.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/ReceiveMessageHandler.kt b/mirai-core/src/commonMain/kotlin/message/ReceiveMessageHandler.kt index 488edc3bc..afe5ad91b 100644 --- a/mirai-core/src/commonMain/kotlin/message/ReceiveMessageHandler.kt +++ b/mirai-core/src/commonMain/kotlin/message/ReceiveMessageHandler.kt @@ -489,7 +489,23 @@ internal object ReceiveMessageTransformer { else -> error("unknown compression flag=${richMsg.template1[0]}") } } - when (richMsg.serviceId) { + + fun findStringProperty(name: String): String { + return content.substringAfter("$name=\"", "").substringBefore("\"", "") + } + + val serviceId = when (val sid = richMsg.serviceId) { + 0 -> { + val serviceIdStr = findStringProperty("serviceID") + if (serviceIdStr.isEmpty() || serviceIdStr.isBlank()) { + 0 + } else { + serviceIdStr.toIntOrNull() ?: 0 + } + } + else -> sid + } + when (serviceId) { // 5: 使用微博长图转换功能分享到QQ群 /* { - builder.add(SimpleServiceMessage(richMsg.serviceId, content)) + builder.add(SimpleServiceMessage(serviceId, content)) } } }