diff --git a/build.gradle.kts b/build.gradle.kts index 9ca5814..35464a9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,20 +1,22 @@ plugins { - val kotlinVersion = "1.6.21" + val kotlinVersion = "1.7.10" kotlin("jvm") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion - id("net.mamoe.mirai-console") version "2.11.1" + id("net.mamoe.mirai-console") version "2.13.2" } group = "top.jie65535.jcf" -version = "1.0.0" +version = "1.1.0" repositories { maven("https://maven.aliyun.com/repository/public") mavenCentral() } +val ktorVersion = "2.2.2" dependencies { - testImplementation(kotlin("test")) - testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.2") +// implementation("io.ktor:ktor-client-core:$ktorVersion") + implementation("io.ktor:ktor-client-core-jvm:$ktorVersion") + implementation("io.ktor:ktor-client-okhttp:$ktorVersion") } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69a9715..ffed3a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt b/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt index c420ab2..44f1df1 100644 --- a/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt +++ b/src/main/kotlin/top/jie65535/jcf/CurseforgeApi.kt @@ -1,9 +1,11 @@ package top.jie65535.jcf import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.engine.okhttp.* -import io.ktor.client.features.* +import io.ktor.client.plugins.* import io.ktor.client.request.* +import io.ktor.client.statement.* import io.ktor.http.* import kotlinx.serialization.* import kotlinx.serialization.json.Json @@ -31,9 +33,9 @@ class CurseforgeApi(apiKey: String) { private val http = HttpClient(OkHttp) { install(HttpTimeout) { - this.requestTimeoutMillis = 300_000 - this.connectTimeoutMillis = 300_000 - this.socketTimeoutMillis = 300_000 + this.requestTimeoutMillis = 60_000 + this.connectTimeoutMillis = 60_000 + this.socketTimeoutMillis = 60_000 } defaultRequest { url.protocol = URLProtocol.HTTPS @@ -53,7 +55,7 @@ class CurseforgeApi(apiKey: String) { http.get("/v1/games") { parameter("index", index) parameter("pageSize", pageSize) - } + }.body() ) } @@ -62,7 +64,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getGame(gameId: Int): Game { return json.decodeFromString( - http.get("/v1/games/$gameId") + http.get("/v1/games/$gameId").body() ).data } @@ -72,7 +74,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getVersions(gameId: Int): Array { return json.decodeFromString( - http.get("/v1/games/$gameId/versions") + http.get("/v1/games/$gameId/versions").body() ).data } @@ -90,7 +92,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getVersionTypes(gameId: Int): Array { return json.decodeFromString( - http.get("/v1/games/$gameId/versions") + http.get("/v1/games/$gameId/versions").body() ).data } @@ -108,7 +110,7 @@ class CurseforgeApi(apiKey: String) { http.get("/v1/categories") { parameter("gameId", gameId) parameter("classId", classId) - } + }.body() ).data } @@ -163,7 +165,7 @@ class CurseforgeApi(apiKey: String) { parameter("slug", slug) parameter("index", index) parameter("pageSize", pageSize) - } + }.body() ) } @@ -172,7 +174,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getMod(modId: Int): Mod { return json.decodeFromString( - http.get("/v1/mods/$modId") + http.get("/v1/mods/$modId").body() ).data } @@ -183,8 +185,8 @@ class CurseforgeApi(apiKey: String) { return json.decodeFromString( http.post("/v1/mods") { headers.append("Content-Type", "application/json") - body = json.encodeToString(GetModsByIdsListRequestBody(modIds)) - } + setBody(json.encodeToString(GetModsByIdsListRequestBody(modIds))) + }.body() ).data } @@ -199,8 +201,8 @@ class CurseforgeApi(apiKey: String) { return json.decodeFromString( http.get("/v1/mods/featured") { headers.append("Content-Type", "application/json") - body = json.encodeToString(GetFeaturedModsRequestBody(gameId, excludedModIds, gameVersionTypeId)) - } + setBody(json.encodeToString(GetFeaturedModsRequestBody(gameId, excludedModIds, gameVersionTypeId))) + }.body() ).data } @@ -209,7 +211,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getModDescription(modId: Int): String { return json.decodeFromString( - http.get("/v1/mods/$modId/description") + http.get("/v1/mods/$modId/description").body() ).data } @@ -222,7 +224,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getModFile(modId: Int, fileId: Int): File { return json.decodeFromString( - http.get("/v1/mods/$modId/files/$fileId") + http.get("/v1/mods/$modId/files/$fileId").body() ).data } @@ -244,7 +246,7 @@ class CurseforgeApi(apiKey: String) { parameter("gameVersionTypeId", gameVersionTypeId) parameter("index", index) parameter("pageSize", pageSize) - } + }.body() ) } @@ -255,8 +257,8 @@ class CurseforgeApi(apiKey: String) { return json.decodeFromString( http.post("/v1/mods/files") { headers.append("Content-Type", "application/json") - body = json.encodeToString(GetModFilesRequestBody(fileIds)) - } + setBody(json.encodeToString(GetModFilesRequestBody(fileIds))) + }.body() ).data } @@ -265,7 +267,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getModFileChangelog(modId: Int, fileId: Int): String { return json.decodeFromString( - http.get("/v1/mods/$modId/files/$fileId/changelog") + http.get("/v1/mods/$modId/files/$fileId/changelog").body() ).data } @@ -274,7 +276,7 @@ class CurseforgeApi(apiKey: String) { */ suspend fun getModFileDownloadURL(modId: Int, fileId: Int): String { return json.decodeFromString( - http.get("/v1/mods/$modId/files/$fileId/download-url") + http.get("/v1/mods/$modId/files/$fileId/download-url").body() ).data } diff --git a/src/main/kotlin/top/jie65535/jcf/MessageHandler.kt b/src/main/kotlin/top/jie65535/jcf/MessageHandler.kt index 05e7db3..fab0927 100644 --- a/src/main/kotlin/top/jie65535/jcf/MessageHandler.kt +++ b/src/main/kotlin/top/jie65535/jcf/MessageHandler.kt @@ -1,7 +1,7 @@ package top.jie65535.jcf -import io.ktor.http.* import kotlinx.coroutines.* +import net.mamoe.mirai.contact.nameCardOrNick import net.mamoe.mirai.event.* import net.mamoe.mirai.event.events.GroupMessageEvent import net.mamoe.mirai.event.events.MessageEvent @@ -33,6 +33,7 @@ class MessageHandler( subject.sendMessage(message.quote() + "必须输入关键字") } else { try { + logger.info("${sender.nameCardOrNick}(${sender.id}) $modClass \"$filter\"") val pagedList = service.search(modClass, filter) with(pagedList.current()) { if (isEmpty()) { @@ -59,7 +60,7 @@ class MessageHandler( * @param format 格式化方法 * @return 用户选中项,null表示未选择任何项 */ - private suspend fun MessageEvent.handlePagedList(pagedList: PagedList, format: (T)->Message): T? { + private suspend fun MessageEvent.handlePagedList(pagedList: PagedList, format: suspend (T)->Message): T? { do { var isContinue = false val list = pagedList.current() @@ -109,13 +110,14 @@ class MessageHandler( */ private suspend fun MessageEvent.handleModsSearchResult(pagedList: PagedList) { val selectedMod = handlePagedList(pagedList) { mod -> - PlainText( + val text = PlainText( """ [${mod.name}] by ${mod.authors.firstOrNull()?.name} ${formatCount(mod.downloadCount)} Downloads Updated ${mod.dateModified.toLocalDate()} ${mod.summary} ${mod.links.websiteUrl} """.trimIndent()) + mod.logo?.thumbnailUrl?.let { loadImage(it) + text } ?: text } selectedMod?.let { handleShowMod(it) } } diff --git a/src/main/kotlin/top/jie65535/jcf/PluginMain.kt b/src/main/kotlin/top/jie65535/jcf/PluginMain.kt index 21e941d..89db064 100644 --- a/src/main/kotlin/top/jie65535/jcf/PluginMain.kt +++ b/src/main/kotlin/top/jie65535/jcf/PluginMain.kt @@ -11,7 +11,7 @@ object PluginMain: KotlinPlugin( JvmPluginDescription( id = "top.jie65535.jcf", name = "J Curseforge Util", - version = "1.0.0", + version = "1.1.0", ) { author("jie65535") info("MC Curseforge Util\n" +