From 513023e1e6ca0edb3c89b1a7342e50ebe661c87e Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 3 Apr 2020 11:28:22 +0800 Subject: [PATCH] Update to mirai-core 0.32.0 --- gradle.properties | 16 +++++++--------- gradle/wrapper/gradle-wrapper.properties | 4 ++-- mirai-api-http/build.gradle.kts | 2 +- .../kotlin/net/mamoe/mirai/api/http/Session.kt | 4 ++-- .../mirai/api/http/data/common/BotEventDTO.kt | 15 +++++++-------- .../mirai/api/http/data/common/MessageDTO.kt | 2 +- .../net/mamoe/mirai/api/http/queue/CacheQueue.kt | 14 ++++++-------- .../mamoe/mirai/api/http/queue/MessageQueue.kt | 3 --- .../mirai/api/http/route/AuthRouteModule.kt | 3 +-- .../mirai/api/http/route/CommandRouteModule.kt | 2 +- .../mirai/api/http/route/WebSocketRouteModule.kt | 4 ++-- 11 files changed, 30 insertions(+), 39 deletions(-) diff --git a/gradle.properties b/gradle.properties index cfee6574..cb199549 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,22 @@ # build httpVersion=v1.4.0 - # style guide kotlin.code.style=official # config -miraiVersion=0.31.4 -miraiConsoleVersion=0.3.9 +miraiVersion=0.32.0 +miraiConsoleVersion=0.4.2 kotlin.incremental.multiplatform=true kotlin.parallel.tasks.in.project=true # kotlin -kotlinVersion=1.4-M1 +kotlinVersion=1.3.71 # kotlin libraries -serializationVersion=0.20.0-1.4-M1 -coroutinesVersion=1.3.5-1.4-M1 -atomicFuVersion=0.14.2-1.4-M1 +serializationVersion=0.20.0 +coroutinesVersion=1.3.5 +atomicFuVersion=0.14.2 kotlinXIoVersion=0.1.16 - coroutinesIoVersion=0.1.16 # utility -ktorVersion=1.3.2-1.4-M1 +ktorVersion=1.3.2 klockVersion=1.7.0 # gradle plugin protobufJavaVersion=3.10.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 64f0fd9b..8a9185b3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ -#Thu Feb 27 13:09:44 CST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip +#Fri Feb 28 20:15:46 CST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/mirai-api-http/build.gradle.kts b/mirai-api-http/build.gradle.kts index b7ace2ce..877b9abd 100644 --- a/mirai-api-http/build.gradle.kts +++ b/mirai-api-http/build.gradle.kts @@ -48,7 +48,7 @@ kotlin { api(ktor("server-cio")) api(ktor("http-jvm")) api(ktor("websockets")) - api(kotlinx("io-jvm")) + compileOnly(kotlinx("io-jvm")) api("org.slf4j:slf4j-simple:1.7.26") } } diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt index ec46c8de..efc7fb30 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/Session.kt @@ -17,7 +17,7 @@ import net.mamoe.mirai.api.http.queue.MessageQueue import net.mamoe.mirai.event.Listener import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.event.subscribeAlways -import net.mamoe.mirai.message.MessagePacket +import net.mamoe.mirai.message.ContactMessage import net.mamoe.mirai.utils.currentTimeSeconds import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext @@ -124,7 +124,7 @@ class AuthedSession internal constructor(val bot: Bot, originKey: String, corout enableWebsocket = HttpApiPluginBase.enableWebsocket ) private var _listener: Listener - private val _cache: Listener> + private val _cache: Listener private val releaseJob: Job //手动释放将会在下一次检查时回收Session internal var latestUsed = currentTimeSeconds diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt index f0149a82..02fbc931 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/BotEventDTO.kt @@ -12,21 +12,20 @@ package net.mamoe.mirai.api.http.data.common import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import net.mamoe.mirai.contact.MemberPermission -import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.event.events.* -import net.mamoe.mirai.message.MessagePacket +import net.mamoe.mirai.message.ContactMessage @Serializable sealed class BotEventDTO : EventDTO() suspend fun BotEvent.toDTO() = when (this) { - is MessagePacket<*, *> -> toDTO() + is ContactMessage -> toDTO() else -> when (this) { - is BotOnlineEvent -> BotOnlineEventDTO(bot.uin) - is BotOfflineEvent.Active -> BotOfflineEventActiveDTO(bot.uin) - is BotOfflineEvent.Force -> BotOfflineEventForceDTO(bot.uin, title, message) - is BotOfflineEvent.Dropped -> BotOfflineEventDroppedDTO(bot.uin) - is BotReloginEvent -> BotReloginEventDTO(bot.uin) + is BotOnlineEvent -> BotOnlineEventDTO(bot.id) + is BotOfflineEvent.Active -> BotOfflineEventActiveDTO(bot.id) + is BotOfflineEvent.Force -> BotOfflineEventForceDTO(bot.id, title, message) + is BotOfflineEvent.Dropped -> BotOfflineEventDroppedDTO(bot.id) + is BotReloginEvent -> BotReloginEventDTO(bot.id) is MessageRecallEvent.GroupRecall -> GroupRecallEventDTO( authorId, messageId, diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt index 36792d4c..e29b230c 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt @@ -182,7 +182,7 @@ suspend fun MessageDTO.toMessage(contact: Contact) = when (this) { // ignore is QuoteDTO, is MessageSourceDTO, - is UnknownMessageDTO, + is UnknownMessageDTO -> null } diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/CacheQueue.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/CacheQueue.kt index 62e6a661..d0c15eb2 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/CacheQueue.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/CacheQueue.kt @@ -9,24 +9,22 @@ package net.mamoe.mirai.api.http.queue -import net.mamoe.mirai.event.events.BotEvent -import net.mamoe.mirai.message.MessagePacket +import net.mamoe.mirai.message.ContactMessage import net.mamoe.mirai.message.data.MessageSource -import net.mamoe.mirai.utils.firstKey -class CacheQueue : LinkedHashMap>() { +class CacheQueue : LinkedHashMap() { var cacheSize = 4096 - override fun get(key: Long): MessagePacket<*, *> = super.get(key) ?: throw NoSuchElementException() + override fun get(key: Long): ContactMessage = super.get(key) ?: throw NoSuchElementException() - override fun put(key: Long, value: MessagePacket<*, *>): MessagePacket<*, *>? = super.put(key, value).also { + override fun put(key: Long, value: ContactMessage): ContactMessage? = super.put(key, value).also { if (size > cacheSize) { - remove(firstKey()) + remove(this.entries.first().key) } } - fun add(packet: MessagePacket<*, *>) { + fun add(packet: ContactMessage) { put(packet[MessageSource].id, packet) } } \ No newline at end of file diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt index 42c1102a..2a8c562e 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/queue/MessageQueue.kt @@ -13,9 +13,6 @@ import net.mamoe.mirai.api.http.data.common.EventDTO import net.mamoe.mirai.api.http.data.common.IgnoreEventDTO import net.mamoe.mirai.api.http.data.common.toDTO import net.mamoe.mirai.event.events.BotEvent -import net.mamoe.mirai.message.MessagePacket -import net.mamoe.mirai.message.data.MessageSource -import net.mamoe.mirai.utils.firstKey import java.util.concurrent.ConcurrentLinkedDeque class MessageQueue : ConcurrentLinkedDeque() { diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt index 740431a6..e6144e43 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt @@ -21,7 +21,6 @@ import net.mamoe.mirai.api.http.data.StateCode import net.mamoe.mirai.api.http.data.common.AuthDTO import net.mamoe.mirai.api.http.data.common.DTO import net.mamoe.mirai.api.http.data.common.VerifyDTO -import kotlin.coroutines.EmptyCoroutineContext fun Application.authModule() { @@ -43,7 +42,7 @@ fun Application.authModule() { miraiVerify("/release") { val bot = getBotOrThrow(it.qq) val session = SessionManager[it.sessionKey] as AuthedSession - if (bot.uin == session.bot.uin) { + if (bot.id == session.bot.id) { SessionManager.closeSession(it.sessionKey) call.respondStateCode(StateCode.Success) } else { diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/CommandRouteModule.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/CommandRouteModule.kt index 448a8e34..74401433 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/CommandRouteModule.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/CommandRouteModule.kt @@ -128,7 +128,7 @@ data class CommandDTO( val name: String, val friend: Long, val group: Long, - val args: List, + val args: List ) : DTO @Serializable diff --git a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/WebSocketRouteModule.kt b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/WebSocketRouteModule.kt index 21ae32a1..51b5ed60 100644 --- a/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/WebSocketRouteModule.kt +++ b/mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/WebSocketRouteModule.kt @@ -28,7 +28,7 @@ import net.mamoe.mirai.api.http.util.toJson import net.mamoe.mirai.event.events.BotEvent import net.mamoe.mirai.event.subscribeAlways import net.mamoe.mirai.event.subscribeMessages -import net.mamoe.mirai.message.MessagePacket +import net.mamoe.mirai.message.ContactMessage fun Application.websocketRouteModule() { routing { @@ -51,7 +51,7 @@ fun Application.websocketRouteModule() { miraiWebsocket("/event") { val listener = it.bot.subscribeAlways { - if (this !is MessagePacket<*, *>) { + if (this !is ContactMessage) { this.toDTO().takeIf { dto -> dto != IgnoreEventDTO }?.apply { outgoing.send(Frame.Text(this.toJson())) }