Przeglądaj źródła

Update core to 2.8.0 and fix deprecated except the RemoteFile

ryoii 4 lat temu
rodzic
commit
e1d911ac08

+ 2 - 0
build.gradle.kts

@@ -8,10 +8,12 @@ buildscript {
     }
     }
 
 
     val kotlinVersion: String by project.extra
     val kotlinVersion: String by project.extra
+    val atomicFuVersion: String by project.extra
 
 
     dependencies {
     dependencies {
         classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
         classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
+        classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFuVersion")
     }
     }
 }
 }
 
 

+ 2 - 1
gradle.properties

@@ -9,5 +9,6 @@ kotlin.parallel.tasks.in.project=true
 httpVersion=2.3.3
 httpVersion=2.3.3
 
 
 # kotlin
 # kotlin
-kotlinVersion=1.5.10
+kotlinVersion=1.5.30
 ktorVersion=1.5.4
 ktorVersion=1.5.4
+atomicFuVersion=0.16.3

+ 4 - 2
mirai-api-http/build.gradle.kts

@@ -1,11 +1,13 @@
 plugins {
 plugins {
     kotlin("jvm")
     kotlin("jvm")
     kotlin("plugin.serialization")
     kotlin("plugin.serialization")
+    id("kotlinx-atomicfu")
     id("net.mamoe.maven-central-publish") version "0.6.1"
     id("net.mamoe.maven-central-publish") version "0.6.1"
-    id("net.mamoe.mirai-console") version "2.7.0"
+    id("net.mamoe.mirai-console") version "2.8.0"
 }
 }
 
 
 val ktorVersion: String by rootProject.extra
 val ktorVersion: String by rootProject.extra
+val atomicFuVersion: String by rootProject.extra
 fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
 fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
 fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"
 fun ktor(id: String, version: String = this@Build_gradle.ktorVersion) = "io.ktor:ktor-$id:$version"
 
 
@@ -19,7 +21,7 @@ kotlin {
 
 
     sourceSets.all {
     sourceSets.all {
         languageSettings.enableLanguageFeature("InlineClasses")
         languageSettings.enableLanguageFeature("InlineClasses")
-        languageSettings.useExperimentalAnnotation("kotlin.Experimental")
+        languageSettings.optIn("kotlin.Experimental")
 
 
         dependencies {
         dependencies {
 
 

+ 1 - 1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/MahPluginImpl.kt

@@ -24,7 +24,7 @@ import kotlin.coroutines.CoroutineContext
 object MahPluginImpl : CoroutineScope {
 object MahPluginImpl : CoroutineScope {
     private const val DEFAULT_LOGGER_NAME = "Mirai HTTP API"
     private const val DEFAULT_LOGGER_NAME = "Mirai HTTP API"
 
 
-    var logger = MiraiLogger.create(DEFAULT_LOGGER_NAME)
+    var logger = MiraiLogger.Factory.create(MahPluginImpl::class, DEFAULT_LOGGER_NAME)
     override val coroutineContext: CoroutineContext =
     override val coroutineContext: CoroutineContext =
         CoroutineExceptionHandler { _, throwable -> logger.error(throwable) }
         CoroutineExceptionHandler { _, throwable -> logger.error(throwable) }
 
 

+ 1 - 2
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/action/file.kt

@@ -19,7 +19,6 @@ import net.mamoe.mirai.api.http.util.merge
 import net.mamoe.mirai.api.http.util.useStream
 import net.mamoe.mirai.api.http.util.useStream
 import net.mamoe.mirai.contact.FileSupported
 import net.mamoe.mirai.contact.FileSupported
 import net.mamoe.mirai.message.data.sendTo
 import net.mamoe.mirai.message.data.sendTo
-import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
 import net.mamoe.mirai.utils.RemoteFile
 import net.mamoe.mirai.utils.RemoteFile
 import java.io.InputStream
 import java.io.InputStream
 import kotlin.streams.toList
 import kotlin.streams.toList
@@ -89,7 +88,7 @@ internal suspend fun onMoveFile(dto: MoveFileDTO): StateCode {
     val contact = dto.session.bot.getFileSupported(dto)
     val contact = dto.session.bot.getFileSupported(dto)
 
 
     val moveTo = dto.moveToPath?.let(contact.filesRoot::resolve)
     val moveTo = dto.moveToPath?.let(contact.filesRoot::resolve)
-        ?: contact.filesRoot.resolveById(dto.moveTo)
+        ?: dto.moveTo?.let { contact.filesRoot.resolveById(it, deep = true) }
         ?: throw NoSuchElementException()
         ?: throw NoSuchElementException()
 
 
     val succeed = contact.filesRoot.resolveById(dto.id)
     val succeed = contact.filesRoot.resolveById(dto.id)

+ 1 - 1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/internal/dto/parameter/file.kt

@@ -79,6 +79,6 @@ internal data class MoveFileDTO(
     override val target: Long? = null,
     override val target: Long? = null,
     override val group: Long? = null,
     override val group: Long? = null,
     override val qq: Long? = null,
     override val qq: Long? = null,
-    val moveTo: String,
+    val moveTo: String? = null,
     val moveToPath: String? = null,
     val moveToPath: String? = null,
 ) : AbstractFileTargetDTO()
 ) : AbstractFileTargetDTO()

+ 5 - 6
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/reverse/client/WsClient.kt

@@ -63,14 +63,13 @@ class WsClient : CoroutineScope {
 
 
         with(destination) {
         with(destination) {
             it.method = HttpMethod(destination.method)
             it.method = HttpMethod(destination.method)
-            it.url(protocol, host, port, path) {
-                setting.extraParameters.forEach { p -> parameters[p.key] = p.value }
-                destination.extraParameters.forEach { p -> parameters[p.key] = p.value }
-            }
+            it.url(protocol, host, port, path)
+            setting.extraParameters.forEach { p -> it.parameter(p.key, p.value) }
+            destination.extraParameters.forEach { p -> it.parameter(p.key, p.value) }
 
 
             it.headers {
             it.headers {
-                setting.extraHeaders.forEach { hd -> set(hd.key, hd.value) }
-                destination.extraHeaders.forEach { hd -> set(hd.key, hd.value) }
+                setting.extraHeaders.forEach { hd -> it.header(hd.key, hd.value) }
+                destination.extraHeaders.forEach { hd -> it.header(hd.key, hd.value) }
             }
             }
         }
         }
     }
     }

+ 4 - 6
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/webhook/client/WebhookHeader.kt

@@ -26,12 +26,10 @@ class WebhookHeader(configuration: Configuration) {
 
 
     private fun appendBotHeader(builder: HttpRequestBuilder) {
     private fun appendBotHeader(builder: HttpRequestBuilder) {
         val botHeader = builder.attributes[webhookHeaderValue]
         val botHeader = builder.attributes[webhookHeaderValue]
-        builder.headers {
-            append("qq", botHeader)
-            append("X-qq", botHeader)
-            append("bot", botHeader)
-            append("X-bot", botHeader)
-        }
+        builder.header("qq", botHeader)
+        builder.header("X-qq", botHeader)
+        builder.header("bot", botHeader)
+        builder.header("X-bot", botHeader)
     }
     }
 
 
     class Configuration {
     class Configuration {

+ 5 - 5
mirai-api-http/src/test/kotlin/mock/BotMockStub.kt

@@ -43,25 +43,25 @@ class BotMockStub : Bot {
 
 
     @OptIn(MiraiInternalApi::class)
     @OptIn(MiraiInternalApi::class)
     override val friends: ContactList<Friend> by lazy {
     override val friends: ContactList<Friend> by lazy {
-        ContactList(listOf(asFriend))
+        ContactList(mutableListOf(asFriend))
     }
     }
 
 
     @OptIn(MiraiInternalApi::class)
     @OptIn(MiraiInternalApi::class)
     override val groups: ContactList<Group> by lazy {
     override val groups: ContactList<Group> by lazy {
-        ContactList(listOf(GroupMockStub(this)))
+        ContactList(mutableListOf(GroupMockStub(this)))
     }
     }
 
 
     override val id: Long = ID
     override val id: Long = ID
     override val isOnline: Boolean = true
     override val isOnline: Boolean = true
-    override val logger: MiraiLogger = MiraiLogger.create("Mock bot")
+    override val logger: MiraiLogger = MiraiLogger.Factory.create(BotMockStub::class, "Mock bot")
     override val nick: String = NICK_NAME
     override val nick: String = NICK_NAME
 
 
     @OptIn(MiraiInternalApi::class)
     @OptIn(MiraiInternalApi::class)
-    override val otherClients: ContactList<OtherClient> = ContactList(listOf())
+    override val otherClients: ContactList<OtherClient> = ContactList(mutableListOf())
 
 
     @OptIn(MiraiInternalApi::class)
     @OptIn(MiraiInternalApi::class)
     override val strangers: ContactList<Stranger> by lazy {
     override val strangers: ContactList<Stranger> by lazy {
-        ContactList(listOf(asStranger))
+        ContactList(mutableListOf(asStranger))
     }
     }
 
 
     override fun close(cause: Throwable?) {}
     override fun close(cause: Throwable?) {}

+ 3 - 0
mirai-api-http/src/test/kotlin/mock/FriendMockStub.kt

@@ -11,6 +11,7 @@ package mock
 
 
 import net.mamoe.mirai.Bot
 import net.mamoe.mirai.Bot
 import net.mamoe.mirai.contact.Friend
 import net.mamoe.mirai.contact.Friend
+import net.mamoe.mirai.contact.roaming.RoamingMessages
 import net.mamoe.mirai.message.MessageReceipt
 import net.mamoe.mirai.message.MessageReceipt
 import net.mamoe.mirai.message.data.Image
 import net.mamoe.mirai.message.data.Image
 import net.mamoe.mirai.message.data.Message
 import net.mamoe.mirai.message.data.Message
@@ -27,6 +28,8 @@ class FriendMockStub(
     override val id: Long = bot.id
     override val id: Long = bot.id
     override val nick: String = bot.nick
     override val nick: String = bot.nick
     override val remark: String = bot.nick
     override val remark: String = bot.nick
+    override val roamingMessages: RoamingMessages
+        get() = TODO("Not yet implemented")
 
 
     override suspend fun delete() {
     override suspend fun delete() {
     }
     }

+ 4 - 1
mirai-api-http/src/test/kotlin/mock/GroupMockStub.kt

@@ -15,6 +15,7 @@ import net.mamoe.mirai.contact.Group
 import net.mamoe.mirai.contact.GroupSettings
 import net.mamoe.mirai.contact.GroupSettings
 import net.mamoe.mirai.contact.NormalMember
 import net.mamoe.mirai.contact.NormalMember
 import net.mamoe.mirai.contact.announcement.Announcements
 import net.mamoe.mirai.contact.announcement.Announcements
+import net.mamoe.mirai.contact.file.RemoteFiles
 import net.mamoe.mirai.message.MessageReceipt
 import net.mamoe.mirai.message.MessageReceipt
 import net.mamoe.mirai.message.data.*
 import net.mamoe.mirai.message.data.*
 import net.mamoe.mirai.utils.ExternalResource
 import net.mamoe.mirai.utils.ExternalResource
@@ -37,7 +38,7 @@ class GroupMockStub(
     override val owner: NormalMember = MemberMockStub(this)
     override val owner: NormalMember = MemberMockStub(this)
 
 
     @OptIn(MiraiInternalApi::class)
     @OptIn(MiraiInternalApi::class)
-    override val members: ContactList<NormalMember> = ContactList(listOf(owner))
+    override val members: ContactList<NormalMember> = ContactList(mutableListOf(owner))
 
 
     override fun contains(id: Long): Boolean {
     override fun contains(id: Long): Boolean {
         return id == MemberMockStub.ID
         return id == MemberMockStub.ID
@@ -81,6 +82,8 @@ class GroupMockStub(
         get() = TODO("Not yet implemented")
         get() = TODO("Not yet implemented")
     override val coroutineContext: CoroutineContext
     override val coroutineContext: CoroutineContext
         get() = TODO("Not yet implemented")
         get() = TODO("Not yet implemented")
+    override val files: RemoteFiles
+        get() = TODO("Not yet implemented")
     override val filesRoot: RemoteFile
     override val filesRoot: RemoteFile
         get() = TODO("Not yet implemented")
         get() = TODO("Not yet implemented")
     override val settings: GroupSettings
     override val settings: GroupSettings

+ 3 - 6
mirai-api-http/src/test/kotlin/net/mamoe/mirai/api/http/request/env/enviroment.kt

@@ -92,9 +92,7 @@ internal class AdapterOperation(val port: Int) {
     suspend inline fun <reified T : DTO> get(path: String, query: Map<String, String> = emptyMap()): T {
     suspend inline fun <reified T : DTO> get(path: String, query: Map<String, String> = emptyMap()): T {
         val content = client.get<String>(path) {
         val content = client.get<String>(path) {
             port = [email protected]
             port = [email protected]
-            url {
-                query.forEach { (k, v) -> parameters.append(k, v) }
-            }
+            query.forEach { (k, v) -> parameter(k, v) }
         }
         }
         return content.jsonParseOrNull()!!
         return content.jsonParseOrNull()!!
     }
     }
@@ -111,9 +109,8 @@ internal class AdapterOperation(val port: Int) {
         var ret: WsOutgoing? = null
         var ret: WsOutgoing? = null
         runBlocking {
         runBlocking {
             wsClient.ws({
             wsClient.ws({
-                url("ws", "localhost", [email protected], "all") {
-                    query.forEach { (k, v) -> parameters[k] = v }
-                }
+                url("ws", "localhost", [email protected], "all")
+                query.forEach { (k, v) -> parameter(k ,v) }
             }) {
             }) {
                 val frame = incoming.receive()
                 val frame = incoming.receive()
                 val content = String(frame.data)
                 val content = String(frame.data)

+ 4 - 1
mirai-api-http/src/test/kotlin/net/mamoe/mirai/api/http/request/ws/WsSessionLifeCycle.kt

@@ -45,6 +45,9 @@ class WsSessionLifeCycle {
         val sessionKey = wsRet?.session
         val sessionKey = wsRet?.session
         assertNotNull(sessionKey)
         assertNotNull(sessionKey)
 
 
+        // socket 由客户端主动断开, 服务端需要一定时间感知
+        delay(1000)
+
         // after disconnect
         // after disconnect
         val session = MahContextHolder[sessionKey]
         val session = MahContextHolder[sessionKey]
         assertNull(session)
         assertNull(session)
@@ -78,7 +81,7 @@ class WsSessionLifeCycle {
         assertEquals(verifyRet.session, sessionKey)
         assertEquals(verifyRet.session, sessionKey)
 
 
         // socket 由客户端主动断开, 服务端需要一定时间感知
         // socket 由客户端主动断开, 服务端需要一定时间感知
-        delay(100)
+        delay(1000)
 
 
         // websocket 断开时, session 引用依旧被 http 引用保留
         // websocket 断开时, session 引用依旧被 http 引用保留
         assertEquals(1, session.getRefCount())
         assertEquals(1, session.getRefCount())