Merge pull request #1115 from mamoe/transform_special_messages

Move Dice to MarketFace conversion from `SendMessageHandler.transformSpecialMessages`...
This commit is contained in:
Him188 2021-03-26 20:36:21 +08:00 committed by GitHub
commit c47535289a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -255,6 +255,9 @@ internal abstract class SendMessageHandler<C : Contact> {
}
/**
* 处理需要 `suspend` 操作的消息转换. 这个转换只会在发送消息时进行, 而不会在处理合并转发 [net.mamoe.mirai.internal.network.protocol.packet.chat.calculateValidationData] 等其他操作时进行.
* 在发包前还会进行最后的 [net.mamoe.mirai.internal.message.toRichTextElems] 转换, 这个转换会为所有操作使用.
*
* - [ForwardMessage] -> [ForwardMessageInternal] (by uploading through highway)
* - ... any others for future
*/
@ -284,12 +287,9 @@ internal suspend fun <C : Contact> SendMessageHandler<C>.transformSpecialMessage
)
}
fun processDice(dice: Dice): MarketFaceImpl {
return MarketFaceImpl(dice.toJceStruct())
}
// loses MessageMetadata and other message types but fine for now.
return message.takeSingleContent<ForwardMessage>()?.let { processForwardMessage(it) }?.toMessageChain()
?: message.takeSingleContent<Dice>()?.let { processDice(it) }?.toMessageChain()
?: message.toMessageChain()
}

View File

@ -194,6 +194,7 @@ internal fun MessageChain.toRichTextElems(
}
}
}
is Dice -> transformOneMessage(MarketFaceImpl(currentMessage.toJceStruct()))
is MarketFace -> {
if (currentMessage is MarketFaceImpl) {
elements.add(ImMsgBody.Elem(marketFace = currentMessage.delegate))