Fix forward and long detect

This commit is contained in:
Him188 2021-02-02 18:07:18 +08:00
parent 82b355a6c6
commit cd146e5976
4 changed files with 18 additions and 13 deletions

View File

@ -966,7 +966,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
override suspend fun downloadLongMessage(bot: Bot, resourceId: String): MessageChain {
bot.asQQAndroidBot()
when (val resp = MultiMsg.ApplyDown(bot.client, 1, resourceId, 1).sendAndExpect(bot)) {
when (val resp = MultiMsg.ApplyDown(bot.client, 2, resourceId, 1).sendAndExpect(bot)) {
is MultiMsg.ApplyDown.Response.RequireDownload -> {
val http = Mirai.Http
val origin = resp.origin

View File

@ -202,5 +202,5 @@ internal fun RichMessage.Key.forwardMessage(
<source name="${source.take(50)}" icon="" action="" appid="-1"/>
</msg>
""".trimIndent().replace("\n", " ")
return ForwardMessageInternal(template)
return ForwardMessageInternal(template, resId)
}

View File

@ -32,7 +32,7 @@ internal data class LongMessageInternal internal constructor(override val conten
}
// internal runtime value, not serializable
internal data class ForwardMessageInternal(override val content: String) : AbstractServiceMessage(), RefinableMessage {
internal data class ForwardMessageInternal(override val content: String, val resId: String) : AbstractServiceMessage(), RefinableMessage {
override val serviceId: Int get() = 35
override suspend fun refine(contact: Contact, context: MessageChain): Message {

View File

@ -118,12 +118,10 @@ private object ReceiveMessageTransformer {
builder: MessageChainBuilder
) {
// (this._miraiContentToString().soutv())
val generalFlags = elements.find { it.generalFlags != null }?.generalFlags
for (element in elements) {
transformElement(element, groupIdOrZero, messageSourceKind, botId, builder)
when {
element.richMsg != null -> decodeRichMessage(generalFlags, element.richMsg, builder)
element.richMsg != null -> decodeRichMessage(element.richMsg, builder)
}
}
}
@ -359,7 +357,6 @@ private object ReceiveMessageTransformer {
}
private fun decodeRichMessage(
generalFlags: ImMsgBody.GeneralFlags?,
richMsg: ImMsgBody.RichMsg,
builder: MessageChainBuilder
) {
@ -388,13 +385,21 @@ private object ReceiveMessageTransformer {
* [LongMessageInternal], [ForwardMessage]
*/
35 -> {
val resId = generalFlags?.longTextResid
if (resId != null) {
builder.add(LongMessageInternal(content, resId))
} else {
builder.add(ForwardMessageInternal(content))
fun findStringProperty(name: String): String {
return content.substringAfter("$name=\"", "").substringBefore("\"", "")
}
val resId = findStringProperty("m_resid")
val msg = when(findStringProperty("multiMsgFlag").toIntOrNull()) {
1 -> LongMessageInternal(content, resId)
0 -> ForwardMessageInternal(content, resId)
else -> {
SimpleServiceMessage(35, content)
}
}
builder.add(msg)
}
// 104 新群员入群的消息