mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-22 13:46:13 +08:00
plugin center
This commit is contained in:
parent
e72beccfbc
commit
8c63819ef3
@ -28,7 +28,7 @@ dependencies {
|
|||||||
api("com.google.code.gson:gson:2.8.6")
|
api("com.google.code.gson:gson:2.8.6")
|
||||||
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
||||||
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
|
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
|
||||||
|
api("org.jsoup:jsoup:1.12.1")
|
||||||
|
|
||||||
testApi("net.mamoe:mirai-core-qqandroid-jvm:${Versions.Mirai.core}")
|
testApi("net.mamoe:mirai-core-qqandroid-jvm:${Versions.Mirai.core}")
|
||||||
testApi(kotlin("stdlib"))
|
testApi(kotlin("stdlib"))
|
||||||
|
@ -1,12 +1,73 @@
|
|||||||
package net.mamoe.mirai.console.center
|
package net.mamoe.mirai.console.center
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonArray
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
|
||||||
object CuiPluginCenter: PluginCenter{
|
object CuiPluginCenter: PluginCenter{
|
||||||
|
|
||||||
|
var plugins:JsonArray? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一页10个吧,pageMinNum=1
|
||||||
|
*/
|
||||||
override suspend fun fetchPlugin(page: Int): Map<String, PluginCenter.PluginInsight> {
|
override suspend fun fetchPlugin(page: Int): Map<String, PluginCenter.PluginInsight> {
|
||||||
TODO("Not yet implemented")
|
check(page > 0)
|
||||||
|
val startIndex = (page-1)*10
|
||||||
|
val endIndex = startIndex+9
|
||||||
|
val map = mutableMapOf<String, PluginCenter.PluginInsight>()
|
||||||
|
(startIndex until endIndex).forEach {
|
||||||
|
if(plugins == null){
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
if(it > plugins!!.size()){
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
val info = plugins!![it]
|
||||||
|
with(info.asJsonObject){
|
||||||
|
map[this.get("name").asString] = PluginCenter.PluginInsight(
|
||||||
|
this.get("name").asString,
|
||||||
|
this.get("version").asString,
|
||||||
|
this.get("core").asString,
|
||||||
|
this.get("console").asString,
|
||||||
|
this.get("author").asString,
|
||||||
|
this.get("contact").asString,
|
||||||
|
this.get("tags").asJsonArray.map { it.asString },
|
||||||
|
this.get("commands").asJsonArray.map { it.asString }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findPlugin(name: String): PluginCenter.PluginInfo? {
|
override suspend fun findPlugin(name: String): PluginCenter.PluginInfo? {
|
||||||
TODO("Not yet implemented")
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun refresh() {
|
||||||
|
val results =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
Jsoup
|
||||||
|
.connect("https://miraiapi.jasonczc.cn/getPluginList")
|
||||||
|
.ignoreContentType(true)
|
||||||
|
.execute()
|
||||||
|
}.body().asJson()
|
||||||
|
if(!(results.has("success") && results["success"].asBoolean)){
|
||||||
|
error("Failed to fetch plugin list from Cui Cloud")
|
||||||
|
}
|
||||||
|
plugins = results.getAsJsonArray("result")//先不解析
|
||||||
|
}
|
||||||
|
|
||||||
|
override val name: String
|
||||||
|
get() = "崔云"
|
||||||
|
|
||||||
|
|
||||||
|
fun String.asJson(): JsonObject {
|
||||||
|
return JsonParser.parseString(this).asJsonObject
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -44,5 +44,13 @@ interface PluginCenter {
|
|||||||
* null则没有
|
* null则没有
|
||||||
*/
|
*/
|
||||||
suspend fun findPlugin(name:String):PluginInfo?
|
suspend fun findPlugin(name:String):PluginInfo?
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新
|
||||||
|
*/
|
||||||
|
suspend fun refresh()
|
||||||
|
|
||||||
|
val name:String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user