Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
fcf2f5c8
Commit
fcf2f5c8
authored
Apr 05, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix message length estimate again, #195
parent
215e7962
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
20 deletions
+27
-20
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+7
-9
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
...commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
+11
-7
mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/io/serialization/JceInputTest.kt
...et.mamoe.mirai.qqandroid/io/serialization/JceInputTest.kt
+9
-4
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
fcf2f5c8
...
@@ -32,6 +32,7 @@ import net.mamoe.mirai.qqandroid.network.highway.HighwayHelper
...
@@ -32,6 +32,7 @@ import net.mamoe.mirai.qqandroid.network.highway.HighwayHelper
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.TroopManagement
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.TroopManagement
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.image.ImgStore
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.image.ImgStore
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
import
net.mamoe.mirai.qqandroid.utils.estimateLength
import
net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
import
net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.*
import
kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.ExperimentalContracts
...
@@ -286,8 +287,10 @@ internal class GroupImpl(
...
@@ -286,8 +287,10 @@ internal class GroupImpl(
throw
EventCancelledException
(
"cancelled by GroupMessageSendEvent"
)
throw
EventCancelledException
(
"cancelled by GroupMessageSendEvent"
)
}
}
val
length
=
event
.
message
.
toString
().
length
val
length
=
event
.
message
.
estimateLength
(
703
)
// 阈值为700左右,限制到3的倍数
if
(!(
length
<=
5000
&&
event
.
message
.
count
{
it
is
Image
}
<=
50
))
{
var
imageCnt
=
0
// 通过下方逻辑短路延迟计算
if
(
length
>
5000
||
event
.
message
.
count
{
it
is
Image
}.
apply
{
imageCnt
=
this
}
>
50
)
{
throw
MessageTooLargeException
(
throw
MessageTooLargeException
(
this
,
this
,
message
,
message
,
...
@@ -299,13 +302,8 @@ internal class GroupImpl(
...
@@ -299,13 +302,8 @@ internal class GroupImpl(
)
)
}
}
val
imageCount
=
event
.
message
.
count
{
it
is
Image
}
if
(
length
>
702
||
imageCnt
>
2
)
return
bot
.
lowLevelSendLongGroupMessage
(
this
.
id
,
event
.
message
)
if
(
length
>=
800
||
imageCount
>=
4
||
(
event
.
message
.
any
<
QuoteReply
>()
&&
(
imageCount
!=
0
||
length
>
100
))
)
return
bot
.
lowLevelSendLongGroupMessage
(
this
.
id
,
event
.
message
)
msg
=
event
.
message
msg
=
event
.
message
}
else
msg
=
message
.
asMessageChain
()
}
else
msg
=
message
.
asMessageChain
()
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
View file @
fcf2f5c8
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
package
net.mamoe.mirai.qqandroid.utils
package
net.mamoe.mirai.qqandroid.utils
import
net.mamoe.mirai.message.data.*
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
...
@@ -30,9 +31,15 @@ internal fun Int.toIpV4AddressString(): String {
...
@@ -30,9 +31,15 @@ internal fun Int.toIpV4AddressString(): String {
}
}
}
}
/*
internal
fun
String
.
chineseLength
(
upTo
:
Int
):
Int
{
internal
fun
String
.
chineseLength
(
upTo
:
Int
):
Int
{
return this.sumUpTo(upTo) { if (it in '\u0391'..'\uFFE5') 3 else 1 }
return
this
.
sumUpTo
(
upTo
)
{
when
(
it
)
{
in
'\
u0000
'
..
'\
u007F
'
->
1
in
'\
u0080
'
..
'\
u07FF
'
->
2
in
'\
u0800
'
..
'\
uFFFF
'
->
3
else
->
4
}
}
}
}
internal
fun
MessageChain
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
=
internal
fun
MessageChain
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
=
...
@@ -42,10 +49,8 @@ internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int =
...
@@ -42,10 +49,8 @@ internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int =
internal
fun
SingleMessage
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
{
internal
fun
SingleMessage
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
{
return
when
(
this
)
{
return
when
(
this
)
{
is QuoteReply -> {
is
QuoteReply
->
444
// Magic number
700
is
Image
->
260
// Magic number
}
// is Image -> 300
is
PlainText
->
stringValue
.
chineseLength
(
upTo
)
is
PlainText
->
stringValue
.
chineseLength
(
upTo
)
is
At
->
display
.
chineseLength
(
upTo
)
is
At
->
display
.
chineseLength
(
upTo
)
is
AtAll
->
display
.
chineseLength
(
upTo
)
is
AtAll
->
display
.
chineseLength
(
upTo
)
...
@@ -74,4 +79,3 @@ internal inline fun CharSequence.sumUpTo(upTo: Int, selector: (Char) -> Int): In
...
@@ -74,4 +79,3 @@ internal inline fun CharSequence.sumUpTo(upTo: Int, selector: (Char) -> Int): In
}
}
return
sum
return
sum
}
}
*/
\ No newline at end of file
mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid/io/serialization/JceInputTest.kt
View file @
fcf2f5c8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
package
net.mamoe.mirai.qqandroid.io.serialization
package
net.mamoe.mirai.qqandroid.io.serialization
/*
import kotlinx.io.core.buildPacket
import kotlinx.io.core.buildPacket
import kotlinx.io.core.toByteArray
import kotlinx.io.core.toByteArray
import kotlinx.io.core.writeFully
import kotlinx.io.core.writeFully
...
@@ -31,6 +32,7 @@ internal const val STRUCT_BEGIN: Byte = 10
...
@@ -31,6 +32,7 @@ internal const val STRUCT_BEGIN: Byte = 10
internal const val STRUCT_END: Byte = 11
internal const val STRUCT_END: Byte = 11
internal const val ZERO_TYPE: Byte = 12
internal const val ZERO_TYPE: Byte = 12
*/
/*
/*
* Copyright 2020 Mamoe Technologies and contributors.
* Copyright 2020 Mamoe Technologies and contributors.
*
*
...
@@ -38,7 +40,8 @@ internal const val ZERO_TYPE: Byte = 12
...
@@ -38,7 +40,8 @@ internal const val ZERO_TYPE: Byte = 12
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*//*
@Suppress("INVISIBLE_MEMBER") // bug
@Suppress("INVISIBLE_MEMBER") // bug
internal class JceInputTest {
internal class JceInputTest {
init {
init {
...
@@ -146,10 +149,12 @@ internal class JceInputTest {
...
@@ -146,10 +149,12 @@ internal class JceInputTest {
assertEquals(
assertEquals(
TestSerializableClassA(
TestSerializableClassA(
/*mapOf(
*/
/*mapOf(
TestSerializableClassB(123, TestSerializableClassC(123123), 9)
TestSerializableClassB(123, TestSerializableClassC(123123), 9)
to TestSerializableClassC(123123)
to TestSerializableClassC(123123)
)*/
)*//*
"1"
"1"
),
),
Jce.UTF_8.load(TestSerializableClassA.serializer(), input)
Jce.UTF_8.load(TestSerializableClassA.serializer(), input)
...
@@ -582,4 +587,4 @@ internal class JceInputTest {
...
@@ -582,4 +587,4 @@ internal class JceInputTest {
assertEquals(123456.0, input.useHead { input.readJceDoubleValue(it) })
assertEquals(123456.0, input.useHead { input.readJceDoubleValue(it) })
assertEquals(true, input.useHead { input.readJceBooleanValue(it) })
assertEquals(true, input.useHead { input.readJceBooleanValue(it) })
}
}
}
}*/
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment