parent
eec3db2b86
commit
15b9c54b32
17
package.json
17
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "koishi-plugin-market-info",
|
||||
"description": "Koishi plugin market information",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.0",
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
"files": [
|
||||
@ -22,10 +22,14 @@
|
||||
"build": "atsc -b"
|
||||
},
|
||||
"koishi": {
|
||||
"browser": true,
|
||||
"description": {
|
||||
"en": "Plugin market information",
|
||||
"zh": "插件市场查询与订阅,第一时间获知插件更新!"
|
||||
},
|
||||
"service": {
|
||||
"required": [
|
||||
"installer"
|
||||
]
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
@ -40,13 +44,14 @@
|
||||
"manager"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"koishi": "^4.10.5"
|
||||
"koishi": "^4.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@koishijs/registry": "^4.6.0",
|
||||
"@koishijs/plugin-market": "^2.3.1",
|
||||
"@koishijs/registry": "^6.0.4",
|
||||
"@types/node": "^18.15.5",
|
||||
"atsc": "^1.2.2",
|
||||
"koishi": "^4.12.1",
|
||||
"typescript": "^4.9.5"
|
||||
"koishi": "^4.15.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
import { Context, Dict, Logger, Schema, Time } from 'koishi'
|
||||
import type { AnalyzedPackage, MarketResult } from '@koishijs/registry'
|
||||
import {} from '@koishijs/plugin-market'
|
||||
import type { SearchObject, SearchResult } from '@koishijs/registry'
|
||||
|
||||
const logger = new Logger('market')
|
||||
|
||||
export const name = 'market-info'
|
||||
|
||||
export const using = ['installer']
|
||||
|
||||
export interface Rule {
|
||||
platform: string
|
||||
channelId: string
|
||||
@ -40,8 +43,8 @@ export const Config: Schema<Config> = Schema.object({
|
||||
export function apply(ctx: Context, config: Config) {
|
||||
ctx.i18n.define('zh', require('./locales/zh-CN'))
|
||||
|
||||
const makeDict = (result: MarketResult) => {
|
||||
const dict: Dict<AnalyzedPackage> = {}
|
||||
const makeDict = (result: SearchResult) => {
|
||||
const dict: Dict<SearchObject> = {}
|
||||
for (const object of result.objects) {
|
||||
if (object.manifest.hidden && !config.showHidden) continue
|
||||
dict[object.shortname] = object
|
||||
@ -50,7 +53,7 @@ export function apply(ctx: Context, config: Config) {
|
||||
}
|
||||
|
||||
const getMarket = async () => {
|
||||
const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json')
|
||||
const data = await ctx.http.get<SearchResult>(ctx.installer.endpoint)
|
||||
return makeDict(data)
|
||||
}
|
||||
|
||||
@ -72,16 +75,20 @@ export function apply(ctx: Context, config: Config) {
|
||||
ctx.setInterval(async () => {
|
||||
const current = await getMarket()
|
||||
const diff = Object.keys({ ...previous, ...current }).map((name) => {
|
||||
const version1 = previous[name]?.version
|
||||
const version2 = current[name]?.version
|
||||
const version1 = previous[name]?.package.version
|
||||
const version2 = current[name]?.package.version
|
||||
if (version1 === version2) return
|
||||
|
||||
if (!version1) {
|
||||
let output = <p><i18n path="market-info.created"></i18n></p>
|
||||
if (config.showPublisher) output += ` (@${current[name].publisher.username})`
|
||||
if (config.showPublisher) output += ` (@${current[name].package.publisher.username})`
|
||||
if (config.showDescription) {
|
||||
const { description } = current[name].manifest
|
||||
output += `\n ${description.zh || description.en}`
|
||||
if (description && typeof description === 'object') {
|
||||
output += `\n ${description.zh || description.en}`
|
||||
} else if (description && typeof description === 'string') {
|
||||
output += `\n ${description}`
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user