feat: support config showDeletion
This commit is contained in:
parent
94cfa82270
commit
3d45f4cf81
12
package.json
12
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "koishi-plugin-market-info",
|
||||
"description": "Koishi plugin market information",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.0",
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
"files": [
|
||||
@ -25,7 +25,7 @@
|
||||
"browser": true,
|
||||
"description": {
|
||||
"en": "Plugin market information",
|
||||
"zh": "插件市场信息查询与订阅"
|
||||
"zh": "插件市场查询与订阅,第一时间获知插件更新!"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
@ -43,10 +43,10 @@
|
||||
"koishi": "^4.10.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@koishijs/registry": "^4.1.6",
|
||||
"@koishijs/registry": "^4.2.1",
|
||||
"@types/node": "^17.0.45",
|
||||
"atsc": "^1.2.1",
|
||||
"koishi": "^4.10.5",
|
||||
"typescript": "^4.9.3"
|
||||
"atsc": "^1.2.2",
|
||||
"koishi": "^4.10.10",
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
|
17
src/index.ts
17
src/index.ts
@ -1,5 +1,5 @@
|
||||
import { Context, Dict, Logger, Schema, Time } from 'koishi'
|
||||
import type { MarketPackage, MarketResult } from '@koishijs/registry'
|
||||
import type { AnalyzedPackage, MarketResult } from '@koishijs/registry'
|
||||
|
||||
const logger = new Logger('market')
|
||||
|
||||
@ -22,23 +22,25 @@ export const Rule: Schema<Rule> = Schema.object({
|
||||
export interface Config {
|
||||
rules: Rule[]
|
||||
interval: number
|
||||
showDeletion: boolean
|
||||
}
|
||||
|
||||
export const Config: Schema<Config> = Schema.object({
|
||||
rules: Schema.array(Rule).description('推送规则。'),
|
||||
interval: Schema.number().default(Time.minute * 30).description('轮询间隔 (毫秒)。'),
|
||||
showDeletion: Schema.boolean().default(false).description('是否显示删除的插件。'),
|
||||
})
|
||||
|
||||
function makeDict(result: MarketResult) {
|
||||
const dict: Dict<MarketPackage> = {}
|
||||
const dict: Dict<AnalyzedPackage> = {}
|
||||
for (const object of result.objects) {
|
||||
dict[object.name] = object
|
||||
dict[object.shortname] = object
|
||||
}
|
||||
return dict
|
||||
}
|
||||
|
||||
export function apply(ctx: Context, config: Config) {
|
||||
ctx.i18n.define('zh', require('./locales/zh-CN.yml'))
|
||||
ctx.i18n.define('zh', require('./locales/zh-CN'))
|
||||
|
||||
const getMarket = async () => {
|
||||
const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json')
|
||||
@ -55,12 +57,13 @@ export function apply(ctx: Context, config: Config) {
|
||||
|
||||
ctx.setInterval(async () => {
|
||||
const current = await getMarket()
|
||||
const diff = Object.keys(current).map((name) => {
|
||||
const diff = Object.keys({ ...previous, ...current }).map((name) => {
|
||||
const version1 = previous[name]?.version
|
||||
const version2 = current[name]?.version
|
||||
if (version1 === version2) return
|
||||
if (!version1) return '新增:' + name
|
||||
return `更新:${name} (${version1} → ${version2})`
|
||||
if (!version1) return `新增:${name}`
|
||||
if (version2) return `更新:${name} (${version1} → ${version2})`
|
||||
if (config.showDeletion) return `删除:${name}`
|
||||
}).filter(Boolean).sort()
|
||||
previous = current
|
||||
if (!diff.length) return
|
||||
|
Loading…
Reference in New Issue
Block a user