feat: add command and i18n

This commit is contained in:
Shigma 2022-12-10 00:33:55 +08:00
parent 6251df10b1
commit 94cfa82270
No known key found for this signature in database
GPG Key ID: 414458B84ACF8744
5 changed files with 26 additions and 3 deletions

6
crowdin.yml Normal file
View File

@ -0,0 +1,6 @@
pull_request_title: 'i18n: update translations'
pull_request_labels:
- i18n
files:
- source: /src/locales/zh-CN.yml
translation: /src/locales/%locale%.yml

View File

@ -1,7 +1,7 @@
{
"name": "koishi-plugin-market-info",
"description": "Koishi plugin market information",
"version": "1.0.0",
"version": "1.0.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [

5
readme.md Normal file
View File

@ -0,0 +1,5 @@
# koishi-plugin-market-info
[![npm](https://img.shields.io/npm/v/koishi-plugin-market-info?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-market-info)
插件市场信息查询与订阅。

View File

@ -38,6 +38,8 @@ function makeDict(result: MarketResult) {
}
export function apply(ctx: Context, config: Config) {
ctx.i18n.define('zh', require('./locales/zh-CN.yml'))
const getMarket = async () => {
const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json')
return makeDict(data)
@ -46,14 +48,18 @@ export function apply(ctx: Context, config: Config) {
ctx.on('ready', async () => {
let previous = await getMarket()
ctx.command('market')
.action(async ({ session }) => {
return session.text('.overview', [Object.keys(previous).length])
})
ctx.setInterval(async () => {
const current = await getMarket()
const diff = Object.keys({ ...previous, ...current }).map((name) => {
const diff = Object.keys(current).map((name) => {
const version1 = previous[name]?.version
const version2 = current[name]?.version
if (version1 === version2) return
if (!version1) return '新增:' + name
if (!version2) return '移除:' + name
return `更新:${name} (${version1}${version2})`
}).filter(Boolean).sort()
previous = current

6
src/locales/zh-CN.yml Normal file
View File

@ -0,0 +1,6 @@
commands:
market:
description: 插件市场信息
messages:
overview: 当前共有 {0} 个插件。