Files
NapCatQQ/src/onebot/network/plugin.ts
2025-02-21 21:12:46 +08:00

41 lines
1.2 KiB
TypeScript

import { OB11EmitEventContent, OB11NetworkReloadType } from './index';
import { NapCatOneBot11Adapter, OB11Message } from '@/onebot';
import { NapCatCore } from '@/core';
import { PluginConfig } from '../config/config';
import { plugin_onmessage } from '@/plugin';
import { ActionMap } from '../action';
import { IOB11NetworkAdapter } from '@/onebot/network/adapter';
export class OB11PluginAdapter extends IOB11NetworkAdapter<PluginConfig> {
constructor(
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
) {
const config = {
name: name,
messagePostFormat: 'array',
reportSelfMessage: false,
enable: true,
debug: true,
};
super(name, config, core, obContext, actions);
}
onEvent<T extends OB11EmitEventContent>(event: T) {
if (event.post_type === 'message') {
plugin_onmessage(this.config.name, this.core, this.obContext, event as OB11Message, this.actions, this).then().catch(console.log);
}
}
open() {
this.isEnable = true;
}
async close() {
this.isEnable = false;
}
async reload() {
return OB11NetworkReloadType.Normal;
}
}