feat: add command and i18n
This commit is contained in:
		
							parent
							
								
									6251df10b1
								
							
						
					
					
						commit
						94cfa82270
					
				
							
								
								
									
										6
									
								
								crowdin.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								crowdin.yml
									
									
									
									
									
										Normal 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 | ||||||
| @ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "koishi-plugin-market-info", |   "name": "koishi-plugin-market-info", | ||||||
|   "description": "Koishi plugin market information", |   "description": "Koishi plugin market information", | ||||||
|   "version": "1.0.0", |   "version": "1.0.1", | ||||||
|   "main": "lib/index.js", |   "main": "lib/index.js", | ||||||
|   "typings": "lib/index.d.ts", |   "typings": "lib/index.d.ts", | ||||||
|   "files": [ |   "files": [ | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								readme.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | # koishi-plugin-market-info | ||||||
|  | 
 | ||||||
|  | [](https://www.npmjs.com/package/koishi-plugin-market-info) | ||||||
|  | 
 | ||||||
|  | 插件市场信息查询与订阅。 | ||||||
							
								
								
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							| @ -38,6 +38,8 @@ function makeDict(result: MarketResult) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function apply(ctx: Context, config: Config) { | export function apply(ctx: Context, config: Config) { | ||||||
|  |   ctx.i18n.define('zh', require('./locales/zh-CN.yml')) | ||||||
|  | 
 | ||||||
|   const getMarket = async () => { |   const getMarket = async () => { | ||||||
|     const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json') |     const data = await ctx.http.get<MarketResult>('https://registry.koishi.chat/market.json') | ||||||
|     return makeDict(data) |     return makeDict(data) | ||||||
| @ -46,14 +48,18 @@ export function apply(ctx: Context, config: Config) { | |||||||
|   ctx.on('ready', async () => { |   ctx.on('ready', async () => { | ||||||
|     let previous = await getMarket() |     let previous = await getMarket() | ||||||
| 
 | 
 | ||||||
|  |     ctx.command('market') | ||||||
|  |       .action(async ({ session }) => { | ||||||
|  |         return session.text('.overview', [Object.keys(previous).length]) | ||||||
|  |       }) | ||||||
|  | 
 | ||||||
|     ctx.setInterval(async () => { |     ctx.setInterval(async () => { | ||||||
|       const current = await getMarket() |       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 version1 = previous[name]?.version | ||||||
|         const version2 = current[name]?.version |         const version2 = current[name]?.version | ||||||
|         if (version1 === version2) return |         if (version1 === version2) return | ||||||
|         if (!version1) return '新增:' + name |         if (!version1) return '新增:' + name | ||||||
|         if (!version2) return '移除:' + name |  | ||||||
|         return `更新:${name} (${version1} → ${version2})` |         return `更新:${name} (${version1} → ${version2})` | ||||||
|       }).filter(Boolean).sort() |       }).filter(Boolean).sort() | ||||||
|       previous = current |       previous = current | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								src/locales/zh-CN.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/locales/zh-CN.yml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | commands: | ||||||
|  |   market: | ||||||
|  |     description: 插件市场信息 | ||||||
|  | 
 | ||||||
|  |     messages: | ||||||
|  |       overview: 当前共有 {0} 个插件。 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user