From db1a9e33e6b45b211bffeb8a8c776e93ae4bf3ef Mon Sep 17 00:00:00 2001 From: itzdrli Date: Sat, 3 May 2025 16:24:53 +0200 Subject: [PATCH] Code Rebase - 1.0.0 by itzdrli --- crowdin.yml | 6 ------ package.json | 17 +++++++-------- src/{index.tsx => index.ts} | 41 +++++++++++++++++++++++-------------- src/locales/zh-CN.yml | 21 ------------------- src/renderImage.ts | 40 ++++++++++++++++++++++++++++++++++++ tsconfig.json | 12 ++++++++--- 6 files changed, 84 insertions(+), 53 deletions(-) delete mode 100644 crowdin.yml rename src/{index.tsx => index.ts} (80%) delete mode 100644 src/locales/zh-CN.yml create mode 100644 src/renderImage.ts diff --git a/crowdin.yml b/crowdin.yml deleted file mode 100644 index 2f787ca..0000000 --- a/crowdin.yml +++ /dev/null @@ -1,6 +0,0 @@ -pull_request_title: 'i18n: update translations' -pull_request_labels: - - i18n -files: - - source: /src/locales/zh-CN.yml - translation: /src/locales/%locale%.yml diff --git a/package.json b/package.json index f8b8841..bc9b265 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,25 @@ { - "name": "koishi-plugin-market-info", + "name": "koishi-plugin-market-info-plus", "description": "Koishi plugin market information", - "version": "2.1.0", + "version": "1.0.0", "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ "lib", "dist" ], - "author": "Shigma ", + "author": "itzdrli ", "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/koishijs/koishi-plugin-market-info.git" + "url": "git+https://github.com/itzdrli/koishi-plugin-market-info-plus.git" }, "bugs": { - "url": "https://github.com/koishijs/koishi-plugin-market-info/issues" + "url": "https://github.com/itzdrli/koishi-plugin-market-info-plus/issues" }, - "homepage": "https://github.com/koishijs/koishi-plugin-market-info#readme", + "homepage": "https://github.com/itzdrli/koishi-plugin-market-info-plus#readme", "scripts": { - "build": "atsc -b" + "build": "yakumo build" }, "koishi": { "description": { @@ -39,13 +39,14 @@ "manager" ], "peerDependencies": { - "koishi": "^4.15.0" + "koishi": "^4.17.0" }, "devDependencies": { "@koishijs/registry": "^6.0.4", "@types/node": "^20.8.10", "atsc": "^1.2.2", "koishi": "^4.15.0", + "koishi-plugin-puppeteer": "^3.9.0", "typescript": "^5.2.2" } } diff --git a/src/index.tsx b/src/index.ts similarity index 80% rename from src/index.tsx rename to src/index.ts index 8c45581..2e0986e 100644 --- a/src/index.tsx +++ b/src/index.ts @@ -1,8 +1,10 @@ import { Context, Dict, Schema, Time, deepEqual, pick, sleep } from 'koishi' import {} from '@koishijs/plugin-market' import type { SearchObject, SearchResult } from '@koishijs/registry' +import { } from 'koishi-plugin-puppeteer' +import { renderMarketUpdate } from './renderImage' -export const name = 'market-info' +export const name = 'market-info-plus' interface Receiver { platform: string @@ -11,6 +13,8 @@ interface Receiver { guildId?: string } +export const inject = ["puppeteer"] + const Receiver: Schema = Schema.object({ platform: Schema.string().required().description('平台名称。'), selfId: Schema.string().required().description('机器人 ID。'), @@ -30,7 +34,7 @@ export interface Config { export const Config: Schema = Schema.object({ rules: Schema.array(Receiver).role('table').description('推送规则列表。'), - endpoint: Schema.string().default('https://registry.koishi.chat/index.json').description('插件市场地址。'), + endpoint: Schema.string().default('https://kp.itzdrli.cc').description('插件市场地址。'), interval: Schema.number().default(Time.minute * 30).description('轮询间隔 (毫秒)。'), showHidden: Schema.boolean().default(false).description('是否显示隐藏的插件。'), showDeletion: Schema.boolean().default(false).description('是否显示删除的插件。'), @@ -39,9 +43,7 @@ export const Config: Schema = Schema.object({ }) export function apply(ctx: Context, config: Config) { - ctx.i18n.define('zh', require('./locales/zh-CN')) - - const logger = ctx.logger('market') + const logger = ctx.logger('market-info-plus') const makeDict = (result: SearchResult) => { const dict: Dict = {} @@ -72,24 +74,25 @@ export function apply(ctx: Context, config: Config) { ) }) if (options.receive) { - if (index >= 0) return session.text('.not-modified') + if (index >= 0) return `未修改订阅信息。` config.rules.push(pick(session, ['platform', 'selfId', 'channelId', 'guildId'])) } else { - if (index < 0) return session.text('.not-modified') + if (index < 0) return `未修改订阅信息。` config.rules.splice(index, 1) } ctx.scope.update(config, false) - return session.text('.updated') + return `已更新订阅信息。` } if (!name) { const objects = Object.values(previous).filter(data => !data.manifest.hidden) - return session.text('.overview', [objects.length]) + return `当前共有 ${objects.length} 个插件` } const data = previous[name] - if (!data) return session.text('.not-found', [name]) - return session.text('.detail', data) + if (!data) `未找到插件 ${name}。` + return `${data.shortname} (${data.package.version})\n\n` + + `发布者:@${data.package.publisher.username}` }) ctx.setInterval(async () => { @@ -97,10 +100,12 @@ export function apply(ctx: Context, config: Config) { const diff = Object.keys({ ...previous, ...current }).map((name) => { const version1 = previous[name]?.package.version const version2 = current[name]?.package.version - if (version1 === version2) return + if (version1 === version2) { + return + } if (!version1) { - let output =

+ let output = `新增:${name} (${version2})` if (config.showPublisher) output += ` (@${current[name].package.publisher.username})` if (config.showDescription) { const { description } = current[name].manifest @@ -126,13 +131,19 @@ export function apply(ctx: Context, config: Config) { const content = ['[插件市场更新]', ...diff].join('\n') logger.info(content) + + // Generate image + const image = await renderMarketUpdate(ctx, config, diff, previous) + const delay = ctx.root.config.delay.broadcast for (let index = 0; index < config.rules.length; ++index) { if (index && delay) await sleep(delay) const { platform, selfId, channelId, guildId } = config.rules[index] const bot = ctx.bots.find(bot => bot.platform === platform && bot.selfId === selfId) - bot.sendMessage(channelId, content, guildId) + // Send both text and image + await bot.sendMessage(channelId, content, guildId) + await bot.sendMessage(channelId, image, guildId) } }, config.interval) }) -} +} \ No newline at end of file diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml deleted file mode 100644 index 31b3da2..0000000 --- a/src/locales/zh-CN.yml +++ /dev/null @@ -1,21 +0,0 @@ -commands: - market: - description: 插件市场信息 - - messages: - overview: 当前共有 {0} 个插件。 - not-found: 未找到插件 {0}。 - updated: 已更新订阅信息。 - not-modified: 未修改订阅信息。 - detail: |- - {name} ({version}) - {manifest.description.zh || manifest.description.en} - options: - receive.true: 订阅到此频道 - receive.false: 取消订阅到此频道 - -market-info: - header: '[插件市场更新]' - created: 新增:{0} - updated: 更新:{0} ({1} → {2})` - deleted: 移除:{0} diff --git a/src/renderImage.ts b/src/renderImage.ts new file mode 100644 index 0000000..87b645d --- /dev/null +++ b/src/renderImage.ts @@ -0,0 +1,40 @@ +import { Context } from 'koishi' +import { Config } from './index' + +// Dark theme colors +const dark = ['#2e3440', '#ffffff', '#434c5e'] + +export async function renderMarketUpdate(ctx: Context, config: Config, diff: string[], previous: any) { + const cardHtml = diff.map(item => { + return ` +
+
+

${item}

+
+
+ ` + }).join('') + + const html = ` + + + + 插件市场更新 + + + +
+
+
+

[插件市场更新]

+
+
+
+ ${cardHtml} +
+
+ + ` + + return await ctx.puppeteer.render(html) +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 2cafbb7..07b245d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,16 +2,22 @@ "compilerOptions": { "rootDir": "src", "outDir": "lib", - "target": "es2020", - "module": "commonjs", + "target": "es2022", + "module": "esnext", + "emitDeclarationOnly": true, "declaration": true, "composite": true, "incremental": true, "skipLibCheck": true, "esModuleInterop": true, - "moduleResolution": "node", + "moduleResolution": "bundler", "jsx": "react-jsx", + "resolveJsonModule": true, "jsxImportSource": "@satorijs/element", + "types": [ + "node", + "yml-register/types" + ] }, "include": [ "src"