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
d5868ed7
Commit
d5868ed7
authored
Apr 02, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `MessageTooLargeException` to differentiate with mute exception
parent
069753e9
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
78 additions
and
26 deletions
+78
-26
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+12
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
...tlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
+2
-10
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
...commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
+3
-0
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Contact.kt
...src/androidMain/kotlin/net/mamoe/mirai/contact/Contact.kt
+2
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
.../kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
+3
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
...e/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
+2
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt
.../src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt
+2
-1
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/QQ.kt
...core/src/androidMain/kotlin/net/mamoe/mirai/contact/QQ.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
.../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
...e/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/MessageTooLargeException.kt
...otlin/net.mamoe.mirai/contact/MessageTooLargeException.kt
+32
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
...-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
+2
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Contact.kt
...ore/src/jvmMain/kotlin/net/mamoe/mirai/contact/Contact.kt
+2
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
.../kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
+2
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
...-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
+2
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Member.kt
...core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Member.kt
+2
-1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/QQ.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/QQ.kt
+2
-1
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
d5868ed7
...
...
@@ -285,8 +285,18 @@ internal class GroupImpl(
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"
}
val
length
=
event
.
message
.
estimateLength
(
5001
)
if
(!(
length
<=
5000
&&
event
.
message
.
count
{
it
is
Image
}
<=
50
))
{
throw
MessageTooLargeException
(
this
,
message
,
event
.
message
,
"message(${event.message.joinToString(
""
,
limit
=
10
)})
is
too
large
.
Allow
up
to
5000
in
weight
(
Chinese
char
=
4
,
English
char
=
1
,
Quote
=
700
,
Image
=
800
,
others
are
estimated
in
String
length
.)
"
)
}
if
(
length
>=
800
)
{
return
bot
.
_lowLevelSendLongGroupMessage
(
this
.
id
,
event
.
message
)
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt
View file @
d5868ed7
...
...
@@ -14,7 +14,6 @@ package net.mamoe.mirai.qqandroid.network
import
kotlinx.atomicfu.AtomicInt
import
kotlinx.atomicfu.atomic
import
kotlinx.io.core.*
import
net.mamoe.mirai.BotAccount
import
net.mamoe.mirai.RawAccountIdUse
import
net.mamoe.mirai.data.OnlineStatus
import
net.mamoe.mirai.qqandroid.QQAndroidBot
...
...
@@ -22,12 +21,8 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import
net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger
import
net.mamoe.mirai.qqandroid.network.protocol.packet.Tlv
import
net.mamoe.mirai.qqandroid.utils.*
import
net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils
import
net.mamoe.mirai.qqandroid.utils.NetworkType
import
net.mamoe.mirai.qqandroid.utils.cryptor.ECDH
import
net.mamoe.mirai.qqandroid.utils.cryptor.TEA
import
net.mamoe.mirai.qqandroid.utils.read
import
net.mamoe.mirai.qqandroid.utils.toUHexString
import
net.mamoe.mirai.utils.*
import
kotlin.random.Random
import
kotlin.random.nextInt
...
...
@@ -63,10 +58,7 @@ internal fun getRandomByteArray(length: Int): ByteArray = ByteArray(length) { Ra
@PublishedApi
internal
open
class
QQAndroidClient
(
context
:
Context
,
@MiraiInternalAPI
(
"Be careful. Do not use the id in BotAccount. use client.uin instead"
)
val
account
:
BotAccount
,
val
id
:
Long
,
val
ecdh
:
ECDH
=
ECDH
(),
val
device
:
DeviceInfo
=
SystemDeviceInfo
(
context
),
bot
:
QQAndroidBot
...
...
@@ -97,7 +89,7 @@ internal open class QQAndroidClient(
}
override
fun
toString
():
String
{
// extremely slow
return
"QQAndroidClient(
account=$account
, ecdh=$ecdh, device=$device, tgtgtKey=${tgtgtKey.toUHexString()}, randomKey=${randomKey.toUHexString()}, miscBitMap=$miscBitMap, mainSigMap=$mainSigMap, subSigMap=$subSigMap, openAppId=$openAppId, apkVersionName=${apkVersionName.toUHexString()}, loginState=$loginState, appClientVersion=$appClientVersion, networkType=$networkType, apkSignatureMd5=${apkSignatureMd5.toUHexString()}, protocolVersion=$protocolVersion, apkId=${apkId.toUHexString()}, t150=${t150?.value?.toUHexString()}, rollbackSig=${rollbackSig?.toUHexString()}, ipFromT149=${ipFromT149?.toUHexString()}, timeDifference=$timeDifference, uin=$uin, t530=${t530?.toUHexString()}, t528=${t528?.toUHexString()}, ksid='$ksid', pwdFlag=$pwdFlag, loginExtraData=$loginExtraData, wFastLoginInfo=$wFastLoginInfo, reserveUinInfo=$reserveUinInfo, wLoginSigInfo=$wLoginSigInfo, tlv113=${tlv113?.toUHexString()}, qrPushSig=${qrPushSig.toUHexString()}, mainDisplayName='$mainDisplayName')"
return
"QQAndroidClient(
id=$id
, ecdh=$ecdh, device=$device, tgtgtKey=${tgtgtKey.toUHexString()}, randomKey=${randomKey.toUHexString()}, miscBitMap=$miscBitMap, mainSigMap=$mainSigMap, subSigMap=$subSigMap, openAppId=$openAppId, apkVersionName=${apkVersionName.toUHexString()}, loginState=$loginState, appClientVersion=$appClientVersion, networkType=$networkType, apkSignatureMd5=${apkSignatureMd5.toUHexString()}, protocolVersion=$protocolVersion, apkId=${apkId.toUHexString()}, t150=${t150?.value?.toUHexString()}, rollbackSig=${rollbackSig?.toUHexString()}, ipFromT149=${ipFromT149?.toUHexString()}, timeDifference=$timeDifference, uin=$uin, t530=${t530?.toUHexString()}, t528=${t528?.toUHexString()}, ksid='$ksid', pwdFlag=$pwdFlag, loginExtraData=$loginExtraData, wFastLoginInfo=$wFastLoginInfo, reserveUinInfo=$reserveUinInfo, wLoginSigInfo=$wLoginSigInfo, tlv113=${tlv113?.toUHexString()}, qrPushSig=${qrPushSig.toUHexString()}, mainDisplayName='$mainDisplayName')"
}
var
onlineStatus
:
OnlineStatus
=
OnlineStatus
.
ONLINE
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
View file @
d5868ed7
...
...
@@ -13,6 +13,7 @@
package
net.mamoe.mirai.qqandroid.utils
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.message.data.AtAll.display
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -48,6 +49,8 @@ internal fun SingleMessage.estimateLength(upTo: Int = Int.MAX_VALUE): Int {
}
is
Image
->
300
is
PlainText
->
stringValue
.
chineseLength
(
upTo
)
is
At
->
display
.
chineseLength
(
upTo
)
is
AtAll
->
display
.
chineseLength
(
upTo
)
else
->
this
.
toString
().
chineseLength
(
upTo
)
}
}
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Contact.kt
View file @
d5868ed7
...
...
@@ -59,8 +59,9 @@ actual abstract class Contact : CoroutineScope, ContactJavaFriendlyAPI() {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
*/
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
View file @
d5868ed7
...
...
@@ -53,8 +53,10 @@ actual abstract class ContactJavaFriendlyAPI {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出 * @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
*/
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
View file @
d5868ed7
...
...
@@ -130,8 +130,9 @@ actual abstract class Group : Contact(), CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Member.kt
View file @
d5868ed7
...
...
@@ -115,8 +115,9 @@ actual abstract class Member : MemberJavaFriendlyAPI() {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/QQ.kt
View file @
d5868ed7
...
...
@@ -83,8 +83,9 @@ actual abstract class QQ : Contact(), CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
View file @
d5868ed7
...
...
@@ -62,8 +62,9 @@ expect abstract class Contact() : CoroutineScope, ContactJavaFriendlyAPI {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
View file @
d5868ed7
...
...
@@ -134,8 +134,9 @@ expect abstract class Group() : Contact, CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
View file @
d5868ed7
...
...
@@ -137,8 +137,9 @@ expect abstract class Member() : MemberJavaFriendlyAPI {
* @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable
* @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/MessageTooLargeException.kt
0 → 100644
View file @
d5868ed7
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* 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
*/
@
file
:
Suppress
(
"unused"
)
package
net.mamoe.mirai.contact
import
net.mamoe.mirai.message.data.Message
import
net.mamoe.mirai.utils.SinceMirai
/**
* 发送消息时消息过长抛出的异常.
*/
@SinceMirai
(
"0.32.0"
)
class
MessageTooLargeException
(
val
target
:
Contact
,
/**
* 原发送消息
*/
val
originalMessage
:
Message
,
/**
* 经过事件拦截处理后的消息
*/
val
messageAfterEvent
:
Message
,
exceptionMessage
:
String
)
:
RuntimeException
(
exceptionMessage
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/QQ.kt
View file @
d5868ed7
...
...
@@ -92,8 +92,9 @@ expect abstract class QQ() : Contact, CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Contact.kt
View file @
d5868ed7
...
...
@@ -58,8 +58,9 @@ actual abstract class Contact : CoroutineScope, ContactJavaFriendlyAPI() {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/ContactJavaFriendlyAPI.kt
View file @
d5868ed7
...
...
@@ -53,8 +53,9 @@ actual abstract class ContactJavaFriendlyAPI {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可 [引用回复][MessageReceipt.quote](仅群聊)或 [撤回][MessageReceipt.recall] 这条消息.
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
View file @
d5868ed7
...
...
@@ -132,8 +132,9 @@ actual abstract class Group : Contact(), CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Member.kt
View file @
d5868ed7
...
...
@@ -123,8 +123,9 @@ actual abstract class Member : MemberJavaFriendlyAPI() {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/QQ.kt
View file @
d5868ed7
...
...
@@ -83,8 +83,9 @@ actual abstract class QQ : Contact(), CoroutineScope {
* @see FriendMessageSendEvent 发送好友信息事件, cancellable
* @see GroupMessageSendEvent 发送群消息事件. cancellable
*
* @throws EventCancelledException 当发送消息事件被取消
* @throws EventCancelledException 当发送消息事件被取消
时抛出
* @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出
* @throws MessageTooLargeException 当消息过长时抛出
*
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
...
...
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