Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Him188 2021-01-13 22:02:57 +08:00
commit b9635404a5
6 changed files with 35 additions and 14 deletions

View File

@ -140,7 +140,8 @@ internal class GroupImpl(
return MiraiImpl.lowLevelSendGroupLongOrForwardMessage(bot, this.id, message.nodeList, false, message)
}
val msg: MessageChain = if (message !is LongMessage && message !is ForwardMessageInternal) {
val isLongOrForward = message is LongMessage || message is ForwardMessageInternal
val msg: MessageChain = if (!isLongOrForward) {
val chain = kotlin.runCatching {
GroupMessagePreSendEvent(this, message).broadcast()
}.onSuccess {
@ -162,7 +163,7 @@ internal class GroupImpl(
imageCnt = it
})
if (length > 702 || imageCnt > 2) { // 阈值为700左右限制到3的倍数
if (length > 702 || imageCnt > 1) { // 阈值为700左右限制到3的倍数
return MiraiImpl.lowLevelSendGroupLongOrForwardMessage(
bot,
this.id,
@ -194,7 +195,7 @@ internal class GroupImpl(
}
}
val result = bot.network.runCatching {
val result = bot.network.runCatching sendMsg@{
val source: OnlineMessageSourceToGroupImpl
MessageSvcPbSendMsg.createToGroup(
bot.client,
@ -204,6 +205,21 @@ internal class GroupImpl(
) {
source = it
}.sendAndExpect<MessageSvcPbSendMsg.Response>().let {
if (!isLongOrForward && it is MessageSvcPbSendMsg.Response.MessageTooLarge) {
return@sendMsg MiraiImpl.lowLevelSendGroupLongOrForwardMessage(
bot,
this@GroupImpl.id,
listOf(
ForwardMessage.Node(
senderId = bot.id,
time = currentTimeSeconds().toInt(),
messageChain = msg,
senderName = bot.nick
)
),
true, null
)
}
check(it is MessageSvcPbSendMsg.Response.SUCCESS) {
"Send group message failed: $it"
}

View File

@ -154,9 +154,9 @@ internal inline fun MessageChain.verityLength(
}
val chain = this
val length = estimateLength(target, 5001)
val length = estimateLength(target, 15001)
lengthCallback(length)
if (length > 5000 || count { it is Image }.apply { imageCntCallback(this) } > 50) {
if (length > 15000 || count { it is Image }.apply { imageCntCallback(this) } > 50) {
throw MessageTooLargeException(
target, message, this,
"message(${

View File

@ -244,7 +244,7 @@ internal suspend fun MsgComm.Msg.transform(bot: QQAndroidBot, fromSync: Boolean
when (msgHead.msgType) {
33 -> bot.groupListModifyLock.withLock {
msgBody.msgContent.read {
val groupUin = readUInt().toLong()
val groupUin = Mirai.calculateGroupUinByGroupCode(readUInt().toLong())
val group = bot.getGroupByUinOrNull(groupUin) ?: bot.createGroupForBot(groupUin) ?: return null
discardExact(1)
val joinedMemberUin = readUInt().toLong()

View File

@ -46,6 +46,10 @@ internal object MessageSvcPbSendMsg : OutgoingPacketFactory<MessageSvcPbSendMsg.
override fun toString(): String = "MessageSvcPbSendMsg.Response.SUCCESS"
}
object MessageTooLarge : Response() {
override fun toString(): String = "MessageSvcPbSendMsg.Response.MessageTooLarge"
}
/**
* 121: 被限制? 个别号才不能发
*/
@ -338,14 +342,15 @@ internal object MessageSvcPbSendMsg : OutgoingPacketFactory<MessageSvcPbSendMsg.
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
val response = readProtoBuf(MsgSvc.PbSendMsgResp.serializer())
return if (response.result == 0) {
Response.SUCCESS
} else {
Response.Failed(
return when (response.result) {
0 -> Response.SUCCESS
10 -> Response.MessageTooLarge
else -> Response.Failed(
response.result,
response.errtype,
response.errmsg
)
}
}
}

View File

@ -209,7 +209,7 @@ internal object OnlinePushPbPushTransMsg :
A8 32 51 A1
83 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 39 32 46 45 30 36 31 41 33 37 36 43 44 35 37 35 37 39 45 37 32 34 44 37 37 30 36 46 39 39 43 35 35 33 33 31 34 44 32 44 46 35 45 42 43 31 31 36
*/
readUInt().toLong() // groupUin
readUInt().toLong() // groupCode
readByte().toInt() // follow type
val target = readUInt().toLong()
val type = readUByte().toInt()

View File

@ -46,10 +46,10 @@ internal fun MessageChain.estimateLength(target: ContactOrBot, upTo: Int): Int =
internal fun SingleMessage.estimateLength(target: ContactOrBot, upTo: Int): Int {
return when (this) {
is QuoteReply -> 444 + this.source.originalMessage.estimateLength(target, upTo) // Magic number
is Image -> 40 //magic number
is Image -> 260 //Magic number
is PlainText -> content.chineseLength(upTo)
is At -> 60 //magic number
is AtAll -> 60 //magic number
is At -> 60 //Magic number
is AtAll -> 60 //Magic number
else -> this.toString().chineseLength(upTo)
}
}