From 98b6dfa4328ec2883ab5eaa97b60a39dfb58ccdb Mon Sep 17 00:00:00 2001 From: sunlei Date: Fri, 19 Jun 2026 19:45:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DBilibili=E6=8F=92?= =?UTF-8?q?=E4=BB=B6seed=E8=BF=90=E8=A1=8C=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/refactor-v3/01-seed-core.sql | 63 +++++++++++++++++-- sql/refactor-v3/99-verify.sql | 30 +++++++-- .../plugins/plugin-platform-migration.spec.ts | 23 +++++++ 3 files changed, 106 insertions(+), 10 deletions(-) diff --git a/sql/refactor-v3/01-seed-core.sql b/sql/refactor-v3/01-seed-core.sql index a4920d9..e33cad1 100644 --- a/sql/refactor-v3/01-seed-core.sql +++ b/sql/refactor-v3/01-seed-core.sql @@ -272,18 +272,68 @@ INSERT INTO qqbot_plugin_version ( 1000000000000001105, 1000000000000000105, '1.0.0', - 'builtin-bilibili-card-1.0.0', + 'bilibili-card:1.0.0', JSON_OBJECT( - 'key', 'bilibili-card', + 'pluginKey', 'bilibili-card', 'name', 'Bilibili Card', 'version', '1.0.0', + 'minApiSdkVersion', '1.0.0', + 'description', '解析 QQ 中的 Bilibili 视频链接卡片并回复视频摘要。', + 'author', 'KT', 'entry', 'src/index.ts', + 'permissions', JSON_ARRAY( + 'qqbot.event.receive', + 'qqbot.send', + 'runtime.http', + 'plugin.config.read' + ), + 'runtime', JSON_OBJECT( + 'workerType', 'thread', + 'timeoutMs', 10000, + 'memoryMb', 128, + 'maxConcurrency', 1, + 'configKeys', JSON_ARRAY( + 'QQBOT_BILIBILI_CARD_HTTP_TIMEOUT_MS', + 'QQBOT_BILIBILI_CARD_MAX_REDIRECTS', + 'QQBOT_BILIBILI_CARD_DEDUPE_TTL_MS', + 'QQBOT_BILIBILI_CARD_DESC_MAX_LENGTH' + ) + ), + 'configSchema', JSON_OBJECT( + 'type', 'object', + 'properties', JSON_OBJECT( + 'QQBOT_BILIBILI_CARD_HTTP_TIMEOUT_MS', JSON_OBJECT( + 'type', 'number', + 'title', 'HTTP 超时毫秒', + 'default', 6000 + ), + 'QQBOT_BILIBILI_CARD_MAX_REDIRECTS', JSON_OBJECT( + 'type', 'number', + 'title', '短链最大跳转次数', + 'default', 5 + ), + 'QQBOT_BILIBILI_CARD_DEDUPE_TTL_MS', JSON_OBJECT( + 'type', 'number', + 'title', '同视频去重毫秒', + 'default', 600000 + ), + 'QQBOT_BILIBILI_CARD_DESC_MAX_LENGTH', JSON_OBJECT( + 'type', 'number', + 'title', '简介最大长度', + 'default', 80 + ) + ) + ), + 'operations', JSON_ARRAY(), 'events', JSON_ARRAY(JSON_OBJECT( 'key', 'bilibili-card.message', 'eventName', 'message', 'handlerName', 'handleMessage', - 'name', 'Bilibili 卡片解析' - )) + 'name', 'Bilibili 卡片解析', + 'description', '解析 QQ 中的 Bilibili 视频链接卡片并回复视频摘要。' + )), + 'assets', JSON_ARRAY(), + 'migrations', JSON_ARRAY() ) ) ON DUPLICATE KEY UPDATE package_hash = VALUES(package_hash), @@ -300,10 +350,11 @@ INSERT INTO qqbot_plugin_installation ( 1000000000000001205, 1000000000000000105, 1000000000000001105, - 'installed', - 'idle', + 'enabled', + 'stopped', 'src/modules/qqbot/plugins/bilibili-card' ) ON DUPLICATE KEY UPDATE + version_id = VALUES(version_id), status = VALUES(status), runtime_status = VALUES(runtime_status), installed_path = VALUES(installed_path); diff --git a/sql/refactor-v3/99-verify.sql b/sql/refactor-v3/99-verify.sql index 955427b..5eb57b0 100644 --- a/sql/refactor-v3/99-verify.sql +++ b/sql/refactor-v3/99-verify.sql @@ -41,11 +41,33 @@ FROM qqbot_plugin WHERE plugin_key = 'bilibili-card' AND status = 'installed'; +SELECT 'seed_qqbot_plugin_version_bilibili_card' AS check_name, COUNT(*) AS matched_rows +FROM qqbot_plugin_version v +JOIN qqbot_plugin p ON p.id = v.plugin_id +WHERE p.plugin_key = 'bilibili-card' + AND v.version = '1.0.0' + AND v.package_hash = 'bilibili-card:1.0.0' + AND JSON_UNQUOTE(JSON_EXTRACT(v.manifest_json, '$.pluginKey')) = 'bilibili-card' + AND JSON_UNQUOTE(JSON_EXTRACT(v.manifest_json, '$.runtime.workerType')) = 'thread' + AND JSON_UNQUOTE(JSON_EXTRACT(v.manifest_json, '$.events[0].key')) = 'bilibili-card.message'; + +SELECT 'seed_qqbot_plugin_installation_bilibili_card' AS check_name, COUNT(*) AS matched_rows +FROM qqbot_plugin_installation i +JOIN qqbot_plugin p ON p.id = i.plugin_id +JOIN qqbot_plugin_version v ON v.id = i.version_id +WHERE p.plugin_key = 'bilibili-card' + AND v.version = '1.0.0' + AND i.status = 'enabled' + AND i.runtime_status = 'stopped' + AND i.installed_path = 'src/modules/qqbot/plugins/bilibili-card'; + SELECT 'seed_qqbot_plugin_event_bilibili_card' AS check_name, COUNT(*) AS matched_rows -FROM qqbot_plugin_event_handler -WHERE event_key = 'bilibili-card.message' - AND handler_name = 'handleMessage' - AND enabled = 1; +FROM qqbot_plugin_event_handler h +JOIN qqbot_plugin p ON p.id = h.plugin_id +WHERE p.plugin_key = 'bilibili-card' + AND h.event_key = 'bilibili-card.message' + AND h.handler_name = 'handleMessage' + AND h.enabled = 1; SELECT 'seed_qqbot_command_bangdream_song' AS check_name, COUNT(*) AS matched_rows FROM qqbot_command diff --git a/test/modules/qqbot/plugins/plugin-platform-migration.spec.ts b/test/modules/qqbot/plugins/plugin-platform-migration.spec.ts index 6636125..82b4612 100644 --- a/test/modules/qqbot/plugins/plugin-platform-migration.spec.ts +++ b/test/modules/qqbot/plugins/plugin-platform-migration.spec.ts @@ -95,9 +95,32 @@ describe('QQBot existing plugin platform migration', () => { join(repoRoot, 'sql/refactor-v3/01-seed-core.sql'), 'utf8', ); + const refactorVerifySql = readFileSync( + join(repoRoot, 'sql/refactor-v3/99-verify.sql'), + 'utf8', + ); expect(refactorSeedSql).toContain(`'bilibili-card'`); expect(refactorSeedSql).toContain(`'bilibili-card.message'`); + expect(refactorSeedSql).toContain(`'pluginKey', 'bilibili-card'`); + expect(refactorSeedSql).toContain(`'runtime', JSON_OBJECT(`); + expect(refactorSeedSql).toContain(`'permissions', JSON_ARRAY(`); + expect(refactorSeedSql).toContain(`'configSchema', JSON_OBJECT(`); + expect(refactorSeedSql).toContain(`'bilibili-card:1.0.0'`); + expect(refactorSeedSql).toContain(`'enabled',`); + expect(refactorSeedSql).toContain(`'stopped',`); + expect(refactorSeedSql).toContain( + `version_id = VALUES(version_id),`, + ); + expect(refactorVerifySql).toContain( + `'seed_qqbot_plugin_version_bilibili_card'`, + ); + expect(refactorVerifySql).toContain( + `'seed_qqbot_plugin_installation_bilibili_card'`, + ); + expect(refactorVerifySql).toContain( + `JOIN qqbot_plugin p ON p.id = h.plugin_id`, + ); }); it('keeps BangDream manifest operations as the single metadata source', () => {