mirror of
https://github.com/jie65535/mirai-console-jcf-plugin.git
synced 2025-06-02 17:39:15 +08:00
更新依赖到最新版本
更新插件版本号到v1.1.0
This commit is contained in:
parent
184a6d9228
commit
1ffd53cab1
@ -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")
|
||||
}
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -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
|
||||
|
@ -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<GetGameResponse>(
|
||||
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<GameVersionsByType> {
|
||||
return json.decodeFromString<GetVersionsResponse>(
|
||||
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<GameVersionType> {
|
||||
return json.decodeFromString<GetVersionTypesResponse>(
|
||||
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<GetModResponse>(
|
||||
http.get("/v1/mods/$modId")
|
||||
http.get("/v1/mods/$modId").body()
|
||||
).data
|
||||
}
|
||||
|
||||
@ -183,8 +185,8 @@ class CurseforgeApi(apiKey: String) {
|
||||
return json.decodeFromString<GetModsResponse>(
|
||||
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<GetFeaturedModsResponse>(
|
||||
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<StringResponse>(
|
||||
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<GetModFileResponse>(
|
||||
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<GetFilesResponse>(
|
||||
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<StringResponse>(
|
||||
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<StringResponse>(
|
||||
http.get("/v1/mods/$modId/files/$fileId/download-url")
|
||||
http.get("/v1/mods/$modId/files/$fileId/download-url").body()
|
||||
).data
|
||||
}
|
||||
|
||||
|
@ -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 <T> MessageEvent.handlePagedList(pagedList: PagedList<T>, format: (T)->Message): T? {
|
||||
private suspend fun <T> MessageEvent.handlePagedList(pagedList: PagedList<T>, 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<Mod>) {
|
||||
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) }
|
||||
}
|
||||
|
@ -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" +
|
||||
|
Loading…
Reference in New Issue
Block a user