mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-23 13:50:12 +08:00
Fix long message internal and forward message uploading
This commit is contained in:
parent
9bfc6ffb4a
commit
fb3b4425ed
@ -233,7 +233,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||
override suspend fun getOnlineOtherClientsList(bot: Bot, mayIncludeSelf: Boolean): List<OtherClientInfo> {
|
||||
bot.asQQAndroidBot()
|
||||
val response = bot.network.run {
|
||||
StatSvc.GetDevLoginInfo(bot.client).sendAndExpect<StatSvc.GetDevLoginInfo.Response>()
|
||||
StatSvc.GetDevLoginInfo(bot.client).sendAndExpect()
|
||||
}
|
||||
|
||||
fun SvcDevLoginInfo.toOtherClientInfo() = OtherClientInfo(
|
||||
@ -360,7 +360,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||
groupCode,
|
||||
messageIds,
|
||||
messageInternalIds
|
||||
).sendAndExpect<PbMessageSvc.PbMsgWithDraw.Response>()
|
||||
).sendAndExpect()
|
||||
}
|
||||
|
||||
response is PbMessageSvc.PbMsgWithDraw.Response.Success
|
||||
|
@ -176,20 +176,29 @@ internal fun RichMessage.Key.forwardMessage(
|
||||
): ForwardMessageInternal = with(forwardMessage) {
|
||||
val template = """
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
|
||||
<msg serviceID="35" templateID="1" action="viewMultiMsg" brief="$brief"
|
||||
<msg serviceID="35" templateID="1" action="viewMultiMsg" brief="${brief.take(30)}"
|
||||
m_resid="$resId" m_fileName="$timeSeconds"
|
||||
tSum="3" sourceMsgId="0" url="" flag="3" adverSign="0" multiMsgFlag="0">
|
||||
<item layout="1" advertiser_id="0" aid="0">
|
||||
<title size="34" maxLines="2" lineSpace="12">$title</title>
|
||||
<title size="34" maxLines="2" lineSpace="12">${title.take(50)}</title>
|
||||
${
|
||||
preview.joinToString("") {
|
||||
"""<title size="26" color="#777777" maxLines="2" lineSpace="12">$it</title>"""
|
||||
when {
|
||||
preview.size > 4 -> {
|
||||
preview.take(3).joinToString("") {
|
||||
"""<title size="26" color="#777777" maxLines="2" lineSpace="12">$it</title>"""
|
||||
} + """<title size="26" color="#777777" maxLines="2" lineSpace="12">...</title>"""
|
||||
}
|
||||
else -> {
|
||||
preview.joinToString("") {
|
||||
"""<title size="26" color="#777777" maxLines="2" lineSpace="12">$it</title>"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<hr hidden="false" style="0"/>
|
||||
<summary size="26" color="#777777">$summary</summary>
|
||||
<summary size="26" color="#777777">${summary.take(50)}</summary>
|
||||
</item>
|
||||
<source name="$source" icon="" action="" appid="-1"/>
|
||||
<source name="${source.take(50)}" icon="" action="" appid="-1"/>
|
||||
</msg>
|
||||
""".trimIndent().replace("\n", " ")
|
||||
return ForwardMessageInternal(template)
|
||||
|
@ -171,7 +171,7 @@ internal abstract class SendMessageHandler<C : Contact> {
|
||||
}
|
||||
}
|
||||
|
||||
fun sendMessageMultiProtocol(
|
||||
private fun sendMessageMultiProtocol(
|
||||
client: QQAndroidClient,
|
||||
message: MessageChain,
|
||||
fragmented: Boolean,
|
||||
@ -231,11 +231,13 @@ internal abstract class SendMessageHandler<C : Contact> {
|
||||
*/
|
||||
internal suspend fun <C : Contact> SendMessageHandler<C>.transformSpecialMessages(message: Message): MessageChain {
|
||||
return message.takeSingleContent<ForwardMessage>()?.let { forward ->
|
||||
check(forward.nodeList.size <= 200) {
|
||||
throw MessageTooLargeException(
|
||||
contact, forward, forward,
|
||||
"ForwardMessage allows up to 200 nodes, but found ${forward.nodeList.size}"
|
||||
)
|
||||
if (!(message is MessageChain && message.contains(IgnoreLengthCheck))) {
|
||||
check(forward.nodeList.size <= 200) {
|
||||
throw MessageTooLargeException(
|
||||
contact, forward, forward,
|
||||
"ForwardMessage allows up to 200 nodes, but found ${forward.nodeList.size}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val resId = MiraiImpl.uploadMessageHighway(
|
||||
@ -253,7 +255,7 @@ internal suspend fun <C : Contact> SendMessageHandler<C>.transformSpecialMessage
|
||||
}
|
||||
|
||||
/**
|
||||
* Might be recalled with [transformedMessage] `is` [LongMessageInternal] if length estimation failed ([sendMessagePacket])
|
||||
* Might be recalled with [transformedMessage] `is` [LongMessageInternal] if length estimation failed (sendMessagePacket)
|
||||
*/
|
||||
internal suspend fun <C : Contact> SendMessageHandler<C>.sendMessage(
|
||||
originalMessage: Message,
|
||||
|
Loading…
Reference in New Issue
Block a user