mirror of
https://github.com/jie65535/mirai-console-jcf-plugin.git
synced 2025-07-28 19:19:15 +08:00
Add Search addon by project id
Add `/jcf id` Command
This commit is contained in:
parent
05a50b3b44
commit
a7d1370c39
@ -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)
|
||||
}
|
||||
}
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user