3 Commits

Author SHA1 Message Date
筱傑
d95b54182b Update README.md 2021-11-01 22:08:19 +08:00
筱傑
a7d1370c39 Add Search addon by project id
Add `/jcf id` Command
2021-11-01 22:04:55 +08:00
筱傑
05a50b3b44 Fix paging index error 2021-11-01 20:12:09 +08:00
5 changed files with 33 additions and 3 deletions

View File

@@ -10,6 +10,7 @@
支持查看文件列表与其下载地址,单独查看文件的更新日志。
## Usage
- /jcf id <projectId> # 根据id查找
- /jcf help # 帮助
- /jcf ss \<filter\> # 直接搜索
- /jcf sspack \<filter\> # 搜索整合包
@@ -32,6 +33,7 @@
- [x] 搜索整合包
- [x] 搜索资源包
- [x] ~~搜索存档~~
- [x] 根据项目ID搜索
---
- [x] 分页选择
- [ ] 获取介绍

View File

@@ -7,7 +7,7 @@ plugins {
}
group = "me.jie65535"
version = "0.1.0"
version = "0.1.1"
repositories {
maven("https://maven.aliyun.com/repository/public")

View File

@@ -10,7 +10,7 @@ object JCurseforge : KotlinPlugin(
JvmPluginDescription(
id = "me.jie65535.jcf",
name = "J Curseforge Util",
version = "0.1.0",
version = "0.1.1",
) {
author("jie65535")
info("""

View File

@@ -50,4 +50,9 @@ object JcfCommand : CompositeCommand(
// MinecraftService.search(this, MinecraftService.SECTION_ID_WORLDS, filter)
// }
@SubCommand("id")
@Description("根据id查找")
suspend fun UserCommandSender.getAddonById(projectId: Int) {
MinecraftService.searchAddonByProjectId(this, projectId)
}
}

View File

@@ -1,5 +1,7 @@
package me.jie65535.jcf
import io.ktor.client.features.*
import io.ktor.http.*
import kotlinx.coroutines.TimeoutCancellationException
import me.jie65535.jcf.model.addon.Addon
import me.jie65535.jcf.model.addon.AddonSortMethod
@@ -77,6 +79,27 @@ object MinecraftService {
showAddon(sender, addon)
}
/**
* 根据项目ID搜索资源
*/
suspend fun searchAddonByProjectId(sender: UserCommandSender, projectId: Int) {
try {
val addon = curseClient.getAddon(projectId)
showAddon(sender, addon)
} catch (e: ClientRequestException) {
if (e.response.status == HttpStatusCode.NotFound) {
sender.sendMessage("未搜索到指定项目ID的资源请使用正确的项目ID")
} else {
sender.sendMessage("请求异常,错误代码:" + e.response.status)
throw e
}
} catch (e: Throwable) {
sender.sendMessage("内部发生异常,此次查询已取消,请重新查询。")
throw e
}
}
private suspend fun showAddon(sender: UserCommandSender, addon: Addon) {
val builder = MessageHandler.parseAddon(addon, sender.subject)
if (addon.latestFiles.isNotEmpty())
@@ -148,7 +171,7 @@ object MinecraftService {
sort = AddonSortMethod.POPULARITY,
sortDescending = true,
gameVersion = null,
index = pageIndex,
index = pageIndex * pageSize,
pageSize = pageSize,
searchFilter = filter,
)