From 3f7bba77b55e0cb6ba49352dace037d648a1a7a2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 10 Apr 2020 23:52:37 +0800 Subject: [PATCH 01/17] Update bintray plugin to 1.8.5 --- buildSrc/src/main/kotlin/Versions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 45b374517..757c3fa41 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -29,8 +29,7 @@ object Versions { } object Publishing { - const val bintray = "1.8.4-jetbrains-3" - + const val bintray = "1.8.5" } } From 40c22f42e53eed56c8ec4056aeb7c117ee46ec38 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 00:04:45 +0800 Subject: [PATCH 02/17] Add bintray publisher workflow --- .github/workflows/bintray.yml | 48 ++++++++++ .gitignore | 4 +- buildSrc/src/main/kotlin/upload/Bintray.kt | 79 ++++++++++++++++ gradle/publish-japt.gradle | 104 --------------------- gradle/publish.gradle | 14 ++- 5 files changed, 136 insertions(+), 113 deletions(-) create mode 100644 .github/workflows/bintray.yml create mode 100644 buildSrc/src/main/kotlin/upload/Bintray.kt delete mode 100644 gradle/publish-japt.gradle diff --git a/.github/workflows/bintray.yml b/.github/workflows/bintray.yml new file mode 100644 index 000000000..ee748d30f --- /dev/null +++ b/.github/workflows/bintray.yml @@ -0,0 +1,48 @@ +# This is a basic workflow to help you get started with Actions + +name: Bintray Publish + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + release: + types: + - created + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Gradle clean + run: ./gradlew clean + - name: Gradle build + run: ./gradlew build # if test's failed, don't publish + - name: Gradle :mirai-core:bintrayUpload + run: ./gradlew :mirai-core:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} + - name: Gradle :mirai-core-qqandroid:bintrayUpload + run: ./gradlew :mirai-core-qqandroid:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} + + +# - name: Upload artifact +# uses: actions/upload-artifact@v1.0.0 +# with: +# # Artifact name +# name: mirai-core +# # Directory containing files to upload +# path: "mirai-core/build/libs/mirai-core-*-all.jar" +# - name: Upload artifact +# uses: actions/upload-artifact@v1.0.0 +# with: +# # Artifact name +# name: mirai-core-qqandroid-all +# # Directory containing files to upload +# path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar" diff --git a/.gitignore b/.gitignore index d6367b15d..9315f8357 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,6 @@ local.properties keys.properties /plugins/ -token.txt \ No newline at end of file +token.txt +bintray.user.txt +bintray.key.txt \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/upload/Bintray.kt b/buildSrc/src/main/kotlin/upload/Bintray.kt new file mode 100644 index 000000000..5da25b57f --- /dev/null +++ b/buildSrc/src/main/kotlin/upload/Bintray.kt @@ -0,0 +1,79 @@ +package upload + +import org.gradle.api.Project +import org.gradle.kotlin.dsl.provideDelegate +import java.io.File + +/* + * 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 + */ +object Bintray { + + @JvmStatic + fun getUser(project: Project): String { + kotlin.runCatching { + @Suppress("UNUSED_VARIABLE", "LocalVariableName") + val bintray_user: String by project + return bintray_user + } + + System.getProperty("bintray_user", null)?.let { + return it.trim() + } + + File(File(System.getProperty("user.dir")).parent, "/bintray.user.txt").let { local -> + if (local.exists()) { + return local.readText().trim() + } + } + + File(File(System.getProperty("user.dir")), "/bintray.user.txt").let { local -> + if (local.exists()) { + return local.readText().trim() + } + } + + error( + "Cannot find bintray user, " + + "please specify by creating a file bintray.user.txt in project dir, " + + "or by providing JVM parameter 'bintray_user'" + ) + } + + @JvmStatic + fun getKey(project: Project): String { + kotlin.runCatching { + @Suppress("UNUSED_VARIABLE", "LocalVariableName") + val bintray_key: String by project + return bintray_key + } + + System.getProperty("bintray_key", null)?.let { + return it.trim() + } + + File(File(System.getProperty("user.dir")).parent, "/bintray.key.txt").let { local -> + if (local.exists()) { + return local.readText().trim() + } + } + + File(File(System.getProperty("user.dir")), "/bintray.key.txt").let { local -> + if (local.exists()) { + return local.readText().trim() + } + } + + error( + "Cannot find bintray key, " + + "please specify by creating a file bintray.key.txt in project dir, " + + "or by providing JVM parameter 'bintray_key'" + ) + } + +} \ No newline at end of file diff --git a/gradle/publish-japt.gradle b/gradle/publish-japt.gradle deleted file mode 100644 index 083199bfb..000000000 --- a/gradle/publish-japt.gradle +++ /dev/null @@ -1,104 +0,0 @@ -// 部分源码来自 kotlinx.coroutines - -def pomConfig = { - licenses { - license { - name "AGPL-V3" - url "https://www.gnu.org/licenses/agpl-3.0.txt" - distribution "repo" - } - } - developers { - developer { - id "mamoe" - name "Mamoe Technologies" - } - } - scm { - url "https://github.com/mamoe/mirai" - } -} - -bintray { - def keyProps = new Properties() - def keyFile = file("../keys.properties") - if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) } - - user = keyProps.getProperty("bintrayUser") - key = keyProps.getProperty("bintrayKey") - - pkg { - repo = 'mirai' - name = "mirai-japt" - licenses = ['AGPL'] - vcsUrl = 'https://github.com/mamoe/mirai' - } -} - -afterEvaluate { - project.publishing.publications.forEach { publication -> - publication.pom.withXml { - def root = asNode() - //root.appendNode('groupId', project.group) - //root.appendNode('artifactId', project.name) - //root.appendNode('version', project.version) - root.appendNode('name', project.name) - root.appendNode('description', project.description) - root.appendNode('url', 'https://github.com/mamoe/mirai') - root.children().last() + pomConfig - } - } -} - -bintrayUpload.doFirst { - publications = project.publishing.publications -} - -bintrayUpload.dependsOn { - def list = new LinkedList() - list.add(tasks.getByName("build")) - - list.addAll(tasks.findAll { task -> task.name.contains('Jar') }) - list.addAll(tasks.findAll { task -> task.name.startsWith('generateMetadataFileFor') }) - list.addAll(tasks.findAll { task -> task.name.startsWith('generatePomFileFor') }) - - list -} - - -// empty xxx-javadoc.jar -task javadocJar(type: Jar) { - archiveClassifier = 'javadoc' -} - -publishing { - publications.all { - // add empty javadocs (no need for MPP root publication which publishes only pom file) - if (it.name != 'kotlinMultiplatform') { - it.artifact(javadocJar) - } - - // Rename MPP artifacts for backward compatibility - def type = it.name - switch (type) { - case 'kotlinMultiplatform': - it.artifactId = "$project.name" - break - case 'metadata': - it.artifactId = "$project.name-common" - break - case 'jvm': - it.artifactId = "$project.name" - break - case 'js': - case 'native': - it.artifactId = "$project.name-$type" - break - } - - // disable metadata everywhere, but in native modules - if (type == 'maven' || type == 'metadata' || type == 'jvm' || type == 'js') { - moduleDescriptorGenerator = null - } - } -} \ No newline at end of file diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 842ca6910..9a08238a9 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,3 +1,5 @@ +import upload.Bintray + // 部分源码来自 kotlinx.coroutines // Source code from kotlinx.coroutines @@ -22,12 +24,8 @@ def pomConfig = { } bintray { - def keyProps = new Properties() - def keyFile = file("../keys.properties") - if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) } - - user = keyProps.getProperty("bintrayUser") - key = keyProps.getProperty("bintrayKey") + user = Bintray.getUser(project) + key = Bintray.getKey(project) pkg { repo = 'mirai' @@ -67,14 +65,14 @@ bintrayUpload.dependsOn { list } -try{ +try { // empty xxx-javadoc.jar task javadocJar(type: Jar) { archiveClassifier = 'javadoc' } -} catch (Exception e){ +} catch (Exception ignored) { } publishing { From bb548fc20c7a576b1e1e8389590d6e5e6ef2cdbc Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 00:10:14 +0800 Subject: [PATCH 03/17] Add more ways to get bintray_key --- buildSrc/src/main/kotlin/upload/Bintray.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/buildSrc/src/main/kotlin/upload/Bintray.kt b/buildSrc/src/main/kotlin/upload/Bintray.kt index 5da25b57f..ac085f181 100644 --- a/buildSrc/src/main/kotlin/upload/Bintray.kt +++ b/buildSrc/src/main/kotlin/upload/Bintray.kt @@ -22,6 +22,12 @@ object Bintray { return bintray_user } + kotlin.runCatching { + @Suppress("UNUSED_VARIABLE", "LocalVariableName") + val bintray_user: String by project.rootProject + return bintray_user + } + System.getProperty("bintray_user", null)?.let { return it.trim() } @@ -53,6 +59,12 @@ object Bintray { return bintray_key } + kotlin.runCatching { + @Suppress("UNUSED_VARIABLE", "LocalVariableName") + val bintray_key: String by project.rootProject + return bintray_key + } + System.getProperty("bintray_key", null)?.let { return it.trim() } From 34a24f5df425e660e1528397ac2f0bfb83b690d9 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 00:18:14 +0800 Subject: [PATCH 04/17] Add bintray availability check --- buildSrc/src/main/kotlin/upload/Bintray.kt | 8 ++++++++ gradle/publish.gradle | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/buildSrc/src/main/kotlin/upload/Bintray.kt b/buildSrc/src/main/kotlin/upload/Bintray.kt index ac085f181..62636213e 100644 --- a/buildSrc/src/main/kotlin/upload/Bintray.kt +++ b/buildSrc/src/main/kotlin/upload/Bintray.kt @@ -14,6 +14,14 @@ import java.io.File */ object Bintray { + @JvmStatic + fun isBintrayAvailable(project: Project): Boolean { + return kotlin.runCatching { + getUser(project) + getKey(project) + }.isSuccess + } + @JvmStatic fun getUser(project: Project): String { kotlin.runCatching { diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 9a08238a9..51f070870 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -3,6 +3,12 @@ import upload.Bintray // 部分源码来自 kotlinx.coroutines // Source code from kotlinx.coroutines + +if (!Bintray.isBintrayAvailable(project)) { + println("bintray isn't available. NO PUBLICATIONS WILL BE SET") + return +} + def pomConfig = { licenses { license { From 37eb969d4cc6f75b0fe6bb07d0cdd5221012e9c3 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 00:21:44 +0800 Subject: [PATCH 05/17] Add bintray availability check --- .github/workflows/bintray.yml | 2 ++ gradle/publish.gradle | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/bintray.yml b/.github/workflows/bintray.yml index ee748d30f..6b19d6a10 100644 --- a/.github/workflows/bintray.yml +++ b/.github/workflows/bintray.yml @@ -26,6 +26,8 @@ jobs: run: ./gradlew clean - name: Gradle build run: ./gradlew build # if test's failed, don't publish + - name: Check keys + run: ./gradlew :mirai-core:ensureBintrayAvailable :mirai-core-qqandroid:ensureBintrayAvailable - name: Gradle :mirai-core:bintrayUpload run: ./gradlew :mirai-core:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - name: Gradle :mirai-core-qqandroid:bintrayUpload diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 51f070870..f1c11f1d2 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -3,6 +3,11 @@ import upload.Bintray // 部分源码来自 kotlinx.coroutines // Source code from kotlinx.coroutines +task ensureBintrayAvailable() { + if (!Bintray.isBintrayAvailable(project)) { + throw new IllegalStateException("bintray isn't available. ") + } +} if (!Bintray.isBintrayAvailable(project)) { println("bintray isn't available. NO PUBLICATIONS WILL BE SET") From 751fa4b50e7268876a661018e44fc225208af1b0 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 00:28:18 +0800 Subject: [PATCH 06/17] Fix task --- gradle/publish.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gradle/publish.gradle b/gradle/publish.gradle index f1c11f1d2..af2f3a5a1 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -4,8 +4,10 @@ import upload.Bintray // Source code from kotlinx.coroutines task ensureBintrayAvailable() { - if (!Bintray.isBintrayAvailable(project)) { - throw new IllegalStateException("bintray isn't available. ") + doLast { + if (!Bintray.isBintrayAvailable(project)) { + throw new IllegalStateException("bintray isn't available. ") + } } } From 686d7577c6c9b9e49953e3baf2ab095b247e31b9 Mon Sep 17 00:00:00 2001 From: Anders <44516212+Anders233@users.noreply.github.com> Date: Sat, 11 Apr 2020 13:37:02 +0800 Subject: [PATCH 07/17] Update BotEvents.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将注释: 机器人被邀请加入群 更改为: 一个账号请求加入群事件 --- .../kotlin/net.mamoe.mirai/event/events/BotEvents.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index 174f3fe4d..77d808610 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -594,7 +594,7 @@ data class NewFriendRequestEvent( } /** - * 机器人被邀请加入群 + * 一个账号请求加入群事件 */ @SinceMirai("0.35.0") data class MemberJoinRequestEvent( @@ -650,4 +650,4 @@ data class MemberJoinRequestEvent( runBlocking { bot.ignoreMemberJoinRequest(this@MemberJoinRequestEvent, blackList) } } -// endregion 好友、群认证 \ No newline at end of file +// endregion 好友、群认证 From d3b52732d7422a82310025dd3245e654f65ad46f Mon Sep 17 00:00:00 2001 From: Anders <44516212+Anders233@users.noreply.github.com> Date: Sat, 11 Apr 2020 13:57:23 +0800 Subject: [PATCH 08/17] Update BotEvents.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "入群申请消息"更改为"申请好友消息" --- .../commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt index 77d808610..8039c7cd2 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt @@ -551,7 +551,7 @@ data class NewFriendRequestEvent( */ val eventId: Long, /** - * 入群申请消息 + * 申请好友消息 */ val message: String, /** From 30303c0473e1f2af0ab6cfe6c2cca2c7d2b1e218 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 16:05:01 +0800 Subject: [PATCH 09/17] Fix unsigned values --- .../mamoe/mirai/qqandroid/message/MessageSourceImpl.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt index 54c311d4a..bb96c16da 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceImpl.kt @@ -86,7 +86,7 @@ internal class MessageSourceFromFriendImpl( type = 0, time = msg.msgHead.msgTime, pbReserve = SourceMsg.ResvAttr( - origUids = id.toULong().toLong() + origUids = id.toLong() and 0xFFFF_FFFF ).toByteArray(SourceMsg.ResvAttr.serializer()), srcMsg = MsgComm.Msg( msgHead = MsgComm.MsgHead( @@ -96,7 +96,7 @@ internal class MessageSourceFromFriendImpl( c2cCmd = msg.msgHead.c2cCmd, msgSeq = msg.msgHead.msgSeq, msgTime = msg.msgHead.msgTime, - msgUid = id.toULong().toLong(), // ok + msgUid = id.toLong() and 0xFFFF_FFFF, // ok // groupInfo = MsgComm.GroupInfo(groupCode = msg.msgHead.groupInfo.groupCode), isSrcMsg = true ), @@ -151,7 +151,7 @@ internal class MessageSourceFromTempImpl( type = 0, time = msg.msgHead.msgTime, pbReserve = SourceMsg.ResvAttr( - origUids = id.toULong().toLong() + origUids = id.toLong() and 0xFFFF_FFFF ).toByteArray(SourceMsg.ResvAttr.serializer()), srcMsg = MsgComm.Msg( msgHead = MsgComm.MsgHead( @@ -161,7 +161,7 @@ internal class MessageSourceFromTempImpl( c2cCmd = msg.msgHead.c2cCmd, msgSeq = msg.msgHead.msgSeq, msgTime = msg.msgHead.msgTime, - msgUid = id.toULong().toLong(), // ok + msgUid = id.toLong() and 0xFFFF_FFFF, // ok // groupInfo = MsgComm.GroupInfo(groupCode = msg.msgHead.groupInfo.groupCode), isSrcMsg = true ), From 505943cb3d957f1abd2b7e5e79704417fd3b6249 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 16:05:29 +0800 Subject: [PATCH 10/17] Handle SMS login --- .../qqandroid/network/QQAndroidBotNetworkHandler.kt | 13 +++++++++++-- .../network/protocol/packet/login/WtLogin.kt | 2 +- .../net.mamoe.mirai/network/LoginFailedException.kt | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt index 2ada44bd3..fe9fb1343 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt @@ -23,6 +23,7 @@ import net.mamoe.mirai.event.events.BotOnlineEvent import net.mamoe.mirai.message.FriendMessage import net.mamoe.mirai.message.GroupMessage import net.mamoe.mirai.network.BotNetworkHandler +import net.mamoe.mirai.network.UnsupportedSMSLoginException import net.mamoe.mirai.network.WrongPasswordException import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.contact.FriendInfoImpl @@ -105,6 +106,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler }.also { heartbeatJob = it } } + @OptIn(MiraiExperimentalAPI::class) override suspend fun relogin(cause: Throwable?) { heartbeatJob?.cancel(CancellationException("relogin", cause)) heartbeatJob?.join() @@ -163,9 +165,15 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler } is WtLogin.Login.LoginPacketResponse.Success -> { - logger.info("Login successful") + logger.info { "Login successful" } break@mainloop } + + is WtLogin.Login.LoginPacketResponse.SMSVerifyCodeNeeded -> { + val message = "SMS required: $response, which isn't yet supported" + logger.error(message) + throw UnsupportedSMSLoginException(message) + } } } @@ -600,7 +608,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler internal val packetListeners = LockFreeLinkedList() @PublishedApi - internal inner class PacketListener( // callback + internal inner class PacketListener( + // callback val commandName: String, val sequenceId: Int ) : CompletableDeferred by CompletableDeferred(supervisor) { diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt index 7a2ee8eb0..70c7d7fca 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/login/WtLogin.kt @@ -300,7 +300,7 @@ internal class WtLogin { class SMSVerifyCodeNeeded(val t402: ByteArray, val t403: ByteArray) : LoginPacketResponse() { override fun toString(): String { - return "LoginPacketResponse.SMSVerifyCodeNeeded" + return "LoginPacketResponse.SMSVerifyCodeNeeded(t402=${t402.toUHexString()}, t403=${t403.toUHexString()})" } } diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt index 370b1ee88..3d9cc2254 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/LoginFailedException.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.network import net.mamoe.mirai.Bot +import net.mamoe.mirai.utils.MiraiExperimentalAPI /** * 在 [登录][Bot.login] 失败时抛出, 可正常地中断登录过程. @@ -28,6 +29,12 @@ sealed class LoginFailedException : RuntimeException { */ class WrongPasswordException(message: String?) : LoginFailedException(message) +/** + * 需要短信验证时抛出. mirai 目前还不支持短信验证. + */ +@MiraiExperimentalAPI +class UnsupportedSMSLoginException(message: String?) : LoginFailedException(message) + /** * 非 mirai 实现的异常 */ From 6d9aceae6ea0e42d210b42b17dd2c3327fb58f53 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 16:05:35 +0800 Subject: [PATCH 11/17] Fix docs --- .../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt | 2 +- .../src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt index 08fdcce40..89db1d58a 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt @@ -31,7 +31,7 @@ import kotlin.jvm.JvmSynthetic /** - * 联系人. 虽然叫做联系人, 但他的子类有 [QQ] 和 [群][Group]. + * 联系人. 虽然叫做联系人, 但他的子类有 [QQ], [群成员][Member] 和 [群][Group]. * * @author Him188moe */ // 不要删除多平台结构 !!! kotlin bug diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt index 2203a9346..fae99f800 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt @@ -61,7 +61,7 @@ expect abstract class Group() : Contact, CoroutineScope { abstract val owner: Member /** - * [Bot] 在群内的 [newMember] 实例 + * [Bot] 在群内的 [Member] 实例 */ @MiraiExperimentalAPI abstract val botAsMember: Member From b6d9154580735979e84d6ea2907036b570c8208e Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 16:07:19 +0800 Subject: [PATCH 12/17] Add `.group` shortcuts to temp OnlineMessageSource --- .../kotlin/net.mamoe.mirai/message/data/MessageSource.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt index fb28ae285..ccb6b3f21 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt @@ -164,6 +164,7 @@ sealed class OnlineMessageSource : MessageSource() { } abstract override val target: Member + val group: Group get() = target.group final override val subject: Member get() = target } @@ -211,6 +212,7 @@ sealed class OnlineMessageSource : MessageSource() { } abstract override val sender: Member + val group: Group get() = sender.group final override val subject: Member get() = sender } From f3cf0004affc9ea01437a3e2e19bdac0b833f22d Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 16:07:37 +0800 Subject: [PATCH 13/17] Fix values --- .../network/protocol/packet/chat/PbMessageSvc.kt | 5 ++--- .../protocol/packet/chat/receive/MessageSvc.kt | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt index 10eaf1fae..b17258d2e 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/PbMessageSvc.kt @@ -20,7 +20,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgSvc import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket -import net.mamoe.mirai.qqandroid.utils._miraiContentToString import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf @@ -93,7 +92,7 @@ internal class PbMessageSvc { fromUin = client.bot.id, toUin = toUin, msgSeq = messageSequenceId, - msgUid = 1000000000000000000L or messageRandom.toULong().toLong(), + msgUid = 0x0100000000000000L or messageRandom.toLong().and(0xFFFF_FFFF), msgTime = time.toLong(), routingHead = MsgSvc.RoutingHead( grpTmp = MsgSvc.GrpTmp(groupUin, toUin) @@ -124,7 +123,7 @@ internal class PbMessageSvc { fromUin = client.bot.id, toUin = toUin, msgSeq = messageSequenceId, - msgUid = 1000000000000000000L or messageRandom.toULong().toLong(), + msgUid = 0x1000000000000000L or messageRandom.toLong().and(0xFFFF_FFFF), msgTime = time.toLong(), routingHead = MsgSvc.RoutingHead( c2c = MsgSvc.C2C( diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt index 547240a24..55037f7dc 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt @@ -49,7 +49,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.* import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.GroupInfoImpl import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.NewContact import net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList -import net.mamoe.mirai.qqandroid.utils._miraiContentToString import net.mamoe.mirai.qqandroid.utils.io.serialization.decodeUniPacket import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray @@ -132,7 +131,7 @@ internal class MessageSvc { open class Response(internal val syncFlagFromServer: MsgSvc.SyncFlag, delegate: List) : MultiPacketByIterable(delegate) { override fun toString(): String = - "MessageSvc.PbGetMsg.Response($syncFlagFromServer=$syncFlagFromServer, messages=))" + "MessageSvc.PbGetMsg.Response(syncFlagFromServer=$syncFlagFromServer, messages=))" } object EmptyResponse : GetMsgSuccess(emptyList()) @@ -370,12 +369,13 @@ internal class MessageSvc { message: MessageChain, crossinline sourceCallback: (MessageSourceToFriendImpl) -> Unit ): OutgoingPacket { + val rand = Random.nextInt().absoluteValue val source = MessageSourceToFriendImpl( - id = Random.nextInt().absoluteValue, + id = rand, sender = client.bot, target = qq, time = currentTimeSeconds.toInt(), - sequenceId = client.atomicNextMessageSequenceId(), + sequenceId = rand, originalMessage = message ) sourceCallback(source) @@ -406,7 +406,7 @@ internal class MessageSvc { ), msgSeq = source.sequenceId, msgRand = source.id, - syncCookie = SyncCookie(time = source.time.toULong().toLong()).toByteArray(SyncCookie.serializer()) + syncCookie = SyncCookie(time = source.time.toLong()).toByteArray(SyncCookie.serializer()) // msgVia = 1 ) ) @@ -454,7 +454,7 @@ internal class MessageSvc { ), msgSeq = source.sequenceId, msgRand = source.id, - syncCookie = SyncCookie(time = source.time.toULong().toLong()).toByteArray(SyncCookie.serializer()) + syncCookie = SyncCookie(time = source.time.toLong()).toByteArray(SyncCookie.serializer()) ) ) } From 16d6c562020832277378441e05dc9985b44a7ea9 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 18:24:52 +0800 Subject: [PATCH 14/17] Add `soutv` for debugging purposes --- .../net/mamoe/mirai/qqandroid/utils/contentToString.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/contentToString.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/contentToString.kt index 8d05fe307..1c6fdedbc 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/contentToString.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/contentToString.kt @@ -11,6 +11,8 @@ package net.mamoe.mirai.qqandroid.utils +import net.mamoe.mirai.utils.DefaultLogger +import net.mamoe.mirai.utils.debug import kotlin.reflect.KClass import kotlin.reflect.KProperty import kotlin.reflect.KProperty1 @@ -26,6 +28,12 @@ private fun Sequence.joinToStringPrefixed(prefix: String, transform: (T) return this.joinToString(prefix = "$prefix$indent", separator = "\n$prefix$indent", transform = transform) } +private val SoutvLogger by lazy { DefaultLogger("soutv") } +internal fun Any?.soutv(name: String) { + @Suppress("DEPRECATION") + SoutvLogger.debug { "$name = ${this._miraiContentToString()}" } +} + /** * 将内容格式化为较可读的字符串输出. * From 0dfea0698c148624923066ec1d0f1fb7ee4a15d4 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 18:47:40 +0800 Subject: [PATCH 15/17] Add sequence cache to filter duplicated events, fix #221 --- .../qqandroid/network/QQAndroidClient.kt | 1 + .../packet/chat/receive/OnlinePush.kt | 35 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt index b1665ced2..e4500ab21 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt @@ -131,6 +131,7 @@ internal open class QQAndroidClient( internal fun nextHighwayDataTransSequenceIdForApplyUp(): Int = highwayDataTransSequenceIdForApplyUp.getAndAdd(2) internal val onlinePushCacheList: LockFreeLinkedList = LockFreeLinkedList() + internal val pbPushTransMsgCacheList: LockFreeLinkedList = LockFreeLinkedList() val appClientVersion: Int = 0 diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt index 4ee23c4cb..3bc0096f1 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt @@ -123,6 +123,14 @@ internal class OnlinePush { override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet? { val content = this.readProtoBuf(OnlinePushTrans.PbMsgInfo.serializer()) + val cache = bot.client.pbPushTransMsgCacheList.removeUntilFirst { it == content.msgSeq } + if (cache == null) { + bot.client.pbPushTransMsgCacheList.addLast(content.msgSeq) + } else { + bot.client.pbPushTransMsgCacheList.remove(cache) + return null + } + content.msgData.read { when (content.msgType) { 44 -> { @@ -237,17 +245,6 @@ internal class OnlinePush { }.flatMap { it.vMsg.read { mapper(it) } } } - private inline fun LockFreeLinkedList.removeUntilFirst(block: (Short) -> Boolean): Short? { - this.forEach { - if (!block(it)) { - this.remove(it) - } else { - return it - } - } - return null - } - private fun lambda732(block: ByteReadPacket.(group: GroupImpl, bot: QQAndroidBot) -> Sequence): ByteReadPacket.(group: GroupImpl, bot: QQAndroidBot) -> Sequence { return block @@ -514,7 +511,7 @@ internal class OnlinePush { ?.let { processor -> processor(notifyMsgBody, bot) } ?: kotlin.run { bot.network.logger.debug { - "unknown group 528 type ${notifyMsgBody.uSubMsgType}, data: " + notifyMsgBody.vProtobuf.toUHexString() + "unknown group 528 type 0x${notifyMsgBody.uSubMsgType.toUHexString("")}, data: " + notifyMsgBody.vProtobuf.toUHexString() } return@deco emptySequence() } @@ -572,4 +569,16 @@ internal class OnlinePush { } } } -} \ No newline at end of file +} + +private inline fun LockFreeLinkedList.removeUntilFirst(block: (E) -> Boolean): E? { + this.forEach { + if (!block(it)) { + this.remove(it) + } else { + return it + } + } + return null +} + From 6b93129048cf04b11850eb04bdddac5d3d6fbdeb Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 19:03:15 +0800 Subject: [PATCH 16/17] Add contextual exceptions --- .../mirai/qqandroid/message/convension.kt | 103 +++++++++++------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt index 57ef53d46..ab79ed492 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt @@ -20,16 +20,14 @@ import net.mamoe.mirai.message.data.* import net.mamoe.mirai.qqandroid.network.protocol.data.proto.HummerCommelem import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgComm -import net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils -import net.mamoe.mirai.qqandroid.utils.encodeToString -import net.mamoe.mirai.qqandroid.utils.hexToBytes +import net.mamoe.mirai.qqandroid.utils.* import net.mamoe.mirai.qqandroid.utils.io.serialization.loadAs import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray -import net.mamoe.mirai.qqandroid.utils.read import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiInternalAPI -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.debug +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract private val UNSUPPORTED_MERGED_MESSAGE_PLAIN = PlainText("你的QQ暂不支持查看[转发多条消息],请期待后续版本。") @@ -181,7 +179,12 @@ private val PB_RESERVE_FOR_DOUTU = "78 00 90 01 01 F8 01 00 A0 02 00 C8 02 00".h private val PB_RESERVE_FOR_ELSE = "78 00 F8 01 00 C8 02 00".hexToBytes() @OptIn(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class) -internal fun MsgComm.Msg.toMessageChain(bot: Bot, groupIdOrZero: Long, onlineSource: Boolean, isTemp: Boolean = false): MessageChain { +internal fun MsgComm.Msg.toMessageChain( + bot: Bot, + groupIdOrZero: Long, + onlineSource: Boolean, + isTemp: Boolean = false +): MessageChain { val elements = this.msgBody.richText.elems return buildMessageChain(elements.size + 1) { @@ -251,43 +254,40 @@ internal inline fun Iterable<*>.firstIsInstanceOrNull(): R? { @OptIn(MiraiInternalAPI::class, LowLevelAPI::class) internal fun List.joinToMessageChain(groupIdOrZero: Long, bot: Bot, message: MessageChainBuilder) { // (this._miraiContentToString()) - this.forEach { + this.forEach { element -> when { - it.srcMsg != null -> message.add( - QuoteReply( - OfflineMessageSourceImplBySourceMsg( - it.srcMsg, - bot, - groupIdOrZero - ) - ) - ) - it.notOnlineImage != null -> message.add(OnlineFriendImageImpl(it.notOnlineImage)) - it.customFace != null -> message.add(OnlineGroupImageImpl(it.customFace)) - it.face != null -> message.add(Face(it.face.index)) - it.text != null -> { - if (it.text.attr6Buf.isEmpty()) { - message.add(it.text.str.toMessage()) + element.srcMsg != null -> + message.add(QuoteReply(OfflineMessageSourceImplBySourceMsg(element.srcMsg, bot, groupIdOrZero))) + element.notOnlineImage != null -> message.add(OnlineFriendImageImpl(element.notOnlineImage)) + element.customFace != null -> message.add(OnlineGroupImageImpl(element.customFace)) + element.face != null -> message.add(Face(element.face.index)) + element.text != null -> { + if (element.text.attr6Buf.isEmpty()) { + message.add(element.text.str.toMessage()) } else { val id: Long - it.text.attr6Buf.read { + element.text.attr6Buf.read { discardExact(7) id = readUInt().toLong() } if (id == 0L) { message.add(AtAll) } else { - message.add(At._lowLevelConstructAtInstance(id, it.text.str)) + message.add(At._lowLevelConstructAtInstance(id, element.text.str)) } } } - it.lightApp != null -> { - val content = MiraiPlatformUtils.unzip(it.lightApp.data, 1).encodeToString() + element.lightApp != null -> { + val content = runWithBugReport("解析 lightApp", { element.lightApp.data.toUHexString() }) { + MiraiPlatformUtils.unzip(element.lightApp.data, 1).encodeToString() + } message.add(LightApp(content)) } - it.richMsg != null -> { - val content = MiraiPlatformUtils.unzip(it.richMsg.template1, 1).encodeToString() - when (it.richMsg.serviceId) { + element.richMsg != null -> { + val content = runWithBugReport("解析 richMsg", { element.richMsg.template1.toUHexString() }) { + MiraiPlatformUtils.unzip(element.richMsg.template1, 1).encodeToString() + } + when (element.richMsg.serviceId) { 1 -> message.add(JsonMessage(content)) 60 -> message.add(XmlMessage(content)) 35 -> { @@ -373,26 +373,24 @@ internal fun List.joinToMessageChain(groupIdOrZero: Long, bot: B } } else -> { - @Suppress("DEPRECATION") - MiraiLogger.debug { - "unknown richMsg.serviceId: ${it.richMsg.serviceId}, content=${it.richMsg.template1.contentToString()}, \ntryUnzip=${content}" - } + throw contextualBugReportException("richMsg.serviceId", + "richMsg.serviceId: ${element.richMsg.serviceId}, content=${element.richMsg.template1.contentToString()}, \n" + "tryUnzip=${content}") } } } - it.elemFlags2 != null - || it.extraInfo != null - || it.generalFlags != null -> { + element.elemFlags2 != null + || element.extraInfo != null + || element.generalFlags != null -> { } - it.commonElem != null -> { - when (it.commonElem.serviceType) { + element.commonElem != null -> { + when (element.commonElem.serviceType) { 2 -> { - val proto = it.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype2.serializer()) + val proto = element.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype2.serializer()) message.add(PokeMessage(proto.pokeType, proto.vaspokeId)) } 3 -> { - val proto = it.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype3.serializer()) + val proto = element.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype3.serializer()) if (proto.flashTroopPic != null) { message.add(GroupFlashImage(OnlineGroupImageImpl(proto.flashTroopPic))) } @@ -408,4 +406,27 @@ internal fun List.joinToMessageChain(groupIdOrZero: Long, bot: B } } +} + + +internal fun contextualBugReportException( + context: String, + forDebug: String, + e: Throwable? = null +): IllegalStateException { + return IllegalStateException("在 $context 时遇到了意料之中的问题. 请完整复制此日志提交给 mirai. 调试信息: $forDebug", e) +} + +@OptIn(ExperimentalContracts::class) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "RESULT_CLASS_IN_RETURN_TYPE") +@kotlin.internal.InlineOnly +internal inline fun runWithBugReport(context: String, forDebug: () -> String, block: () -> R): R { + contract { + callsInPlace(block, InvocationKind.EXACTLY_ONCE) + callsInPlace(forDebug, InvocationKind.AT_MOST_ONCE) + } + + return runCatching(block).getOrElse { + throw contextualBugReportException(context, forDebug(), it) + } } \ No newline at end of file From 0f86ad024093f24bc0094667e86b1e8d735df3f8 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 19:11:55 +0800 Subject: [PATCH 17/17] Cleanup --- .../network/protocol/packet/chat/receive/OnlinePush.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt index 3bc0096f1..388373db9 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt @@ -494,7 +494,7 @@ internal class OnlinePush { discardExact(1) Transformers732[internalType] - ?.let { it(this@deco, group as GroupImpl, bot) } + ?.let { it(this@deco, group, bot) } ?: kotlin.run { bot.network.logger.debug { "unknown group 732 type $internalType, data: " + readBytes().toUHexString()