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
8df45b40
Commit
8df45b40
authored
Mar 30, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `_lowLevelSendLongGroupMessage`, fix length counting
parent
9f8d75f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
35 deletions
+41
-35
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
...mmonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
+11
-8
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+16
-17
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
...commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
+14
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
+0
-10
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt
View file @
8df45b40
...
...
@@ -371,15 +371,13 @@ internal abstract class QQAndroidBotBase constructor(
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelSendLongGroupMessage
(
groupCode
:
Long
,
message
:
Message
):
MessageReceipt
<
Group
>
{
val
chain
=
message
.
asMessageChain
()
check
(
chain
.
toString
().
length
<=
4500
&&
chain
.
count
{
it
is
Image
}
<=
50
)
{
"message is too large. Allow up to 4500 chars or 50 images"
}
internal
suspend
fun
_lowLevelSendLongGroupMessage
(
groupCode
:
Long
,
message
:
MessageChain
):
MessageReceipt
<
Group
>
{
val
group
=
getGroup
(
groupCode
)
val
time
=
currentTimeSeconds
network
.
run
{
val
data
=
chain
.
calculateValidationDataForGroup
(
val
data
=
message
.
calculateValidationDataForGroup
(
sequenceId
=
client
.
atomicNextMessageSequenceId
(),
time
=
time
.
toInt
(),
random
=
Random
.
nextInt
().
absoluteValue
.
toUInt
(),
...
...
@@ -433,10 +431,15 @@ internal abstract class QQAndroidBotBase constructor(
return
group
.
sendMessage
(
RichMessage
.
longMessage
(
brief
=
chain
.
toString
().
let
{
// already cached
if
(
it
.
length
>
27
)
{
it
.
take
(
27
)
+
"..."
}
else
it
brief
=
message
.
joinToString
(
limit
=
27
){
when
(
it
){
is
PlainText
->
it
.
stringValue
is
At
->
it
.
display
is
AtAll
->
it
.
display
is
Image
->
"[图片]"
is
Face
->
"[表情]"
else
->
""
}
},
resId
=
resId
,
timeSeconds
=
time
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
8df45b40
...
...
@@ -30,8 +30,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.image.ImgStore
import
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
import
net.mamoe.mirai.qqandroid.utils.chineseLength
import
net.mamoe.mirai.qqandroid.utils.sumUpTo
import
net.mamoe.mirai.qqandroid.utils.estimateLength
import
net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
import
net.mamoe.mirai.utils.*
import
kotlin.contracts.ExperimentalContracts
...
...
@@ -277,30 +276,30 @@ internal class GroupImpl(
@JvmSynthetic
override
suspend
fun
sendMessage
(
message
:
Message
):
MessageReceipt
<
Group
>
{
check
(!
isBotMuted
)
{
"bot is muted. Remaining seconds=$botMuteRemaining"
}
val
event
=
GroupMessageSendEvent
(
this
,
message
.
asMessageChain
()).
broadcast
()
if
(
event
.
isCancelled
)
{
throw
EventCancelledException
(
"cancelled by GroupMessageSendEvent"
)
}
val
msg
:
MessageChain
if
(
message
!
is
LongMessage
)
{
if
(
event
.
message
.
sumUpTo
(
800
)
{
it
,
upTo
->
when
(
it
)
{
is
QuoteReply
->
700
is
Image
->
300
is
PlainText
->
it
.
stringValue
.
chineseLength
(
upTo
)
else
->
it
.
toString
().
length
}
}
>=
800
)
{
return
bot
.
_lowLevelSendLongGroupMessage
(
this
.
id
,
message
)
val
event
=
GroupMessageSendEvent
(
this
,
message
.
asMessageChain
()).
broadcast
()
if
(
event
.
isCancelled
)
{
throw
EventCancelledException
(
"cancelled by GroupMessageSendEvent"
)
}
}
val
length
=
event
.
message
.
estimateLength
(
4501
)
check
(
length
<=
4500
&&
event
.
message
.
count
{
it
is
Image
}
<=
50
)
{
"message is too large. Allow up to 4500 chars or 50 images"
}
if
(
length
>=
800
)
{
return
bot
.
_lowLevelSendLongGroupMessage
(
this
.
id
,
event
.
message
)
}
msg
=
event
.
message
}
else
msg
=
message
.
asMessageChain
()
lateinit
var
source
:
MessageSourceFromSendGroup
bot
.
network
.
run
{
val
response
:
MessageSvc
.
PbSendMsg
.
Response
=
MessageSvc
.
PbSendMsg
.
ToGroup
(
bot
.
client
,
id
,
event
.
message
msg
)
{
source
=
it
source
.
startWaitingSequenceId
(
this
)
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
View file @
8df45b40
...
...
@@ -12,6 +12,10 @@
package
net.mamoe.mirai.qqandroid.utils
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.PlainText
import
net.mamoe.mirai.message.data.QuoteReply
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -34,6 +38,16 @@ internal fun String.chineseLength(upTo: Int): Int {
return
this
.
sumUpTo
(
upTo
)
{
if
(
it
in
'\
u0391
'
..
'\
uFFE5
'
)
3
else
1
}
}
internal
fun
MessageChain
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
=
sumUpTo
(
upTo
)
{
it
,
up
->
when
(
it
)
{
is
QuoteReply
->
700
is
Image
->
300
is
PlainText
->
it
.
stringValue
.
chineseLength
(
up
)
else
->
it
.
toString
().
chineseLength
(
up
)
}
}
internal
inline
fun
<
T
>
Iterable
<
T
>.
sumUpTo
(
upTo
:
Int
,
selector
:
(
T
,
remaining
:
Int
)
->
Int
):
Int
{
var
sum
=
0
for
(
element
in
this
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
View file @
8df45b40
...
...
@@ -13,8 +13,6 @@ import kotlinx.coroutines.Job
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.data.*
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.Message
import
net.mamoe.mirai.message.data.MessageSource
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
...
...
@@ -142,14 +140,6 @@ interface LowLevelBotAPIAccessor {
@LowLevelAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelGetGroupActiveData
(
groupId
:
Long
):
GroupActiveData
/**
* 发送长消息
*/
@SinceMirai
(
"0.31.0"
)
@LowLevelAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelSendLongGroupMessage
(
groupCode
:
Long
,
message
:
Message
):
MessageReceipt
<
Group
>
}
/**
...
...
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