mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 06:31:13 +00:00
Refactor plugin to use context actions and update deps
Refactored the builtin plugin to pass actions and adapterName explicitly from context instead of relying on a global variable. Updated napcat-types dependency to version 0.0.8.
This commit is contained in:
parent
4b693bf6e2
commit
1ae10ae0c6
@ -6,8 +6,6 @@ import type { OB11Message, OB11PostSendMsg } from 'napcat-types/napcat-onebot/ty
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import type { PluginConfigSchema } from 'napcat-types/napcat-onebot/network/plugin-manger';
|
||||
|
||||
let actions: ActionMap | undefined = undefined;
|
||||
let startTime: number = Date.now();
|
||||
|
||||
interface BuiltinPluginConfig {
|
||||
@ -28,33 +26,26 @@ let currentConfig: BuiltinPluginConfig = {
|
||||
|
||||
export let plugin_config_ui: PluginConfigSchema = [];
|
||||
|
||||
/**
|
||||
* 插件初始化
|
||||
*/
|
||||
/**
|
||||
* 插件初始化
|
||||
*/
|
||||
const plugin_init: PluginModule['plugin_init'] = async (ctx) => {
|
||||
console.log('[Plugin: builtin] NapCat 内置插件已初始化');
|
||||
actions = ctx.actions;
|
||||
// platformInstance = _instance; // No longer valid or needed like this
|
||||
|
||||
const NapCatConfig = ctx.NapCatConfig;
|
||||
plugin_config_ui = NapCatConfig.combine(
|
||||
NapCatConfig.html('<div style="padding: 10px; background: rgba(0,0,0,0.05); border-radius: 8px;"><h3>👋 Welcome to NapCat Builtin Plugin</h3><p>This is a demonstration of the plugin configuration interface.</p></div>'),
|
||||
NapCatConfig.text('prefix', 'Command Prefix', '#napcat', 'The prefix to trigger the version info command'),
|
||||
NapCatConfig.boolean('enableReply', 'Enable Reply', true, 'Switch to enable or disable the reply functionality'),
|
||||
NapCatConfig.select('theme', 'Theme Selection', [
|
||||
plugin_config_ui = ctx.NapCatConfig.combine(
|
||||
ctx.NapCatConfig.html('<div style="padding: 10px; background: rgba(0,0,0,0.05); border-radius: 8px;"><h3>👋 Welcome to NapCat Builtin Plugin</h3><p>This is a demonstration of the plugin configuration interface.</p></div>'),
|
||||
ctx.NapCatConfig.text('prefix', 'Command Prefix', '#napcat', 'The prefix to trigger the version info command'),
|
||||
ctx.NapCatConfig.boolean('enableReply', 'Enable Reply', true, 'Switch to enable or disable the reply functionality'),
|
||||
ctx.NapCatConfig.select('theme', 'Theme Selection', [
|
||||
{ label: 'Light Mode', value: 'light' },
|
||||
{ label: 'Dark Mode', value: 'dark' },
|
||||
{ label: 'Auto', value: 'auto' }
|
||||
], 'light', 'Select a theme for the response (Demo purpose only)'),
|
||||
NapCatConfig.multiSelect('features', 'Enabled Features', [
|
||||
ctx.NapCatConfig.multiSelect('features', 'Enabled Features', [
|
||||
{ label: 'Version Info', value: 'version' },
|
||||
{ label: 'Status Report', value: 'status' },
|
||||
{ label: 'Debug Log', value: 'debug' }
|
||||
], ['version'], 'Select features to enable'),
|
||||
NapCatConfig.text('description', 'Description', '这是一个内置插件的配置示例', 'A multi-line text area for notes')
|
||||
ctx.NapCatConfig.text('description', 'Description', '这是一个内置插件的配置示例', 'A multi-line text area for notes')
|
||||
);
|
||||
|
||||
// Try to load config
|
||||
@ -107,11 +98,11 @@ const plugin_onmessage: PluginModule['plugin_onmessage'] = async (_ctx, event) =
|
||||
}
|
||||
|
||||
try {
|
||||
const versionInfo = await getVersionInfo('ob11', {});
|
||||
const versionInfo = await getVersionInfo(_ctx.actions, _ctx.adapterName, {});
|
||||
if (!versionInfo) return;
|
||||
|
||||
const message = formatVersionMessage(versionInfo);
|
||||
await sendMessage(event, message, 'ob11', {});
|
||||
await sendMessage(_ctx.actions, event, message, _ctx.adapterName, {});
|
||||
|
||||
console.log('[Plugin: builtin] 已回复版本信息');
|
||||
} catch (error) {
|
||||
@ -122,7 +113,7 @@ const plugin_onmessage: PluginModule['plugin_onmessage'] = async (_ctx, event) =
|
||||
/**
|
||||
* 获取版本信息(完美的类型推导,无需 as 断言)
|
||||
*/
|
||||
async function getVersionInfo (adapter: string, config: any) {
|
||||
async function getVersionInfo (actions: ActionMap, adapter: string, config: any) {
|
||||
if (!actions) return null;
|
||||
|
||||
try {
|
||||
@ -169,9 +160,7 @@ function formatVersionMessage (info: { appName: string; appVersion: string; prot
|
||||
/**
|
||||
* 发送消息(完美的类型推导)
|
||||
*/
|
||||
async function sendMessage (event: OB11Message, message: string, adapter: string, config: any) {
|
||||
if (!actions) return;
|
||||
|
||||
async function sendMessage (actions: ActionMap, event: OB11Message, message: string, adapter: string, config: any) {
|
||||
const params: OB11PostSendMsg = {
|
||||
message,
|
||||
message_type: event.message_type,
|
||||
|
||||
@ -210,21 +210,11 @@ importers:
|
||||
specifier: ^1.6.7
|
||||
version: 1.6.7
|
||||
|
||||
packages/napcat-plugin:
|
||||
dependencies:
|
||||
napcat-types:
|
||||
specifier: workspace:*
|
||||
version: link:../napcat-types
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^22.0.1
|
||||
version: 22.19.1
|
||||
|
||||
packages/napcat-plugin-builtin:
|
||||
dependencies:
|
||||
napcat-types:
|
||||
specifier: 0.0.7
|
||||
version: 0.0.7
|
||||
specifier: 0.0.8
|
||||
version: 0.0.8
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^22.0.1
|
||||
@ -5448,8 +5438,8 @@ packages:
|
||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||
hasBin: true
|
||||
|
||||
napcat-types@0.0.7:
|
||||
resolution: {integrity: sha512-PIDaQ6YnTxxpC1yb+VIDsQDamV6Ry+fUhHUBCXUVSzj1outisf6jSKFr2O7c9wX9zdX6Pi6NaVECNRy0ob4dmg==}
|
||||
napcat-types@0.0.8:
|
||||
resolution: {integrity: sha512-QxpYmAWr44tGimWmA6Az+eODlSOU3H2cJ9QzHvC09eaEwLvP6BpD0TApdWFYkzNBFFiHVLXv6lqdCAyAV3RAPg==}
|
||||
|
||||
napcat.protobuf@1.1.4:
|
||||
resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==}
|
||||
@ -12819,7 +12809,7 @@ snapshots:
|
||||
|
||||
nanoid@3.3.11: {}
|
||||
|
||||
napcat-types@0.0.7:
|
||||
napcat-types@0.0.8:
|
||||
dependencies:
|
||||
'@sinclair/typebox': 0.34.41
|
||||
'@types/cors': 2.8.19
|
||||
|
||||
Loading…
Reference in New Issue
Block a user