From 7e7262415b52d278bd01547472c18d29f9cf40e1 Mon Sep 17 00:00:00 2001 From: Nepenthe <113700307+pohgxz@users.noreply.github.com> Date: Wed, 31 Dec 2025 13:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=8F=92=E4=BB=B6=E6=89=93?= =?UTF-8?q?=E5=8C=85=E9=97=AE=E9=A2=98=20(#1486)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复打包错误 * fix: 完善插件模板 * Update index.ts --- packages/napcat-plugin/index.ts | 12 +++++++++++- packages/napcat-plugin/vite.config.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/napcat-plugin/index.ts b/packages/napcat-plugin/index.ts index f2b28f16..e00a739d 100644 --- a/packages/napcat-plugin/index.ts +++ b/packages/napcat-plugin/index.ts @@ -1,12 +1,22 @@ +import { createActionMap } from 'napcat-onebot/action'; import { EventType } from 'napcat-onebot/event/OneBotEvent'; import type { PluginModule } from 'napcat-onebot/network/plugin'; +/** + * 导入 napcat 包时候不使用 @/napcat...,直接使用 napcat... + * 因为 @/napcat... 会导致打包时包含整个 napcat 包,而不是只包含需要的部分 + */ + +// action 作为参数传递时请用这个 +let actionMap: ReturnType | undefined = undefined; + const plugin_init: PluginModule['plugin_init'] = async (_core, _obContext, _actions, _instance) => { console.log('[Plugin: example] 插件已初始化'); + actionMap = _actions; }; const plugin_onmessage: PluginModule['plugin_onmessage'] = async (adapter, _core, _obCtx, event, actions, instance) => { if (event.post_type === EventType.MESSAGE && event.raw_message.includes('ping')) { await actions.get('send_group_msg')?.handle({ group_id: String(event.group_id), message: 'pong' }, adapter, instance.config); } }; -export { plugin_init, plugin_onmessage }; +export { plugin_init, plugin_onmessage, actionMap }; diff --git a/packages/napcat-plugin/vite.config.ts b/packages/napcat-plugin/vite.config.ts index 4fe33a3e..5a8de9cb 100644 --- a/packages/napcat-plugin/vite.config.ts +++ b/packages/napcat-plugin/vite.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ resolve: { conditions: ['node', 'default'], alias: { - '@/napcat-core': resolve(__dirname, '../core'), + '@/napcat-core': resolve(__dirname, '../napcat-core'), '@': resolve(__dirname, '../'), }, },