mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-12 07:50:25 +00:00
feat: plugin
This commit is contained in:
@@ -34,7 +34,11 @@ export class OB11NetworkManager {
|
||||
}
|
||||
|
||||
async emitEvent(event: OB11EmitEventContent) {
|
||||
return Promise.all(Array.from(this.adapters.values()).map(adapter => adapter.onEvent(event)));
|
||||
return Promise.all(Array.from(this.adapters.values()).map(adapter => {
|
||||
if (adapter.isEnable) {
|
||||
return adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async emitEvents(events: OB11EmitEventContent[]) {
|
||||
@@ -44,19 +48,21 @@ export class OB11NetworkManager {
|
||||
async emitEventByName(names: string[], event: OB11EmitEventContent) {
|
||||
return Promise.all(names.map(name => {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (adapter) {
|
||||
if (adapter && adapter.isEnable) {
|
||||
return adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async emitEventByNames(map: Map<string, OB11EmitEventContent>) {
|
||||
return Promise.all(Array.from(map.entries()).map(([name, event]) => {
|
||||
const adapter = this.adapters.get(name);
|
||||
if (adapter) {
|
||||
if (adapter && adapter.isEnable) {
|
||||
return adapter.onEvent(event);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
registerAdapter(adapter: IOB11NetworkAdapter) {
|
||||
this.adapters.set(adapter.name, adapter);
|
||||
}
|
||||
@@ -104,6 +110,9 @@ export class OB11NetworkManager {
|
||||
async readloadSomeAdapters<T>(configMap: Map<string, T>) {
|
||||
await Promise.all(Array.from(configMap.entries()).map(([name, config]) => this.readloadAdapter(name, config)));
|
||||
}
|
||||
async getAllConfig() {
|
||||
return Array.from(this.adapters.values()).map(adapter => adapter.config);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './active-http';
|
||||
|
||||
44
src/onebot/network/plugin.ts
Normal file
44
src/onebot/network/plugin.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent, OB11NetworkReloadType } from './index';
|
||||
import { OB11Message } from '@/onebot';
|
||||
import { NapCatCore } from '@/core';
|
||||
import { ActionMap } from '../action';
|
||||
import { AdapterConfig } from '../config/config';
|
||||
import { plugin_onmessage } from '@/core/plugin';
|
||||
|
||||
export class OB11PluginAdapter implements IOB11NetworkAdapter {
|
||||
isEnable: boolean = true;
|
||||
public config: AdapterConfig;
|
||||
|
||||
constructor(
|
||||
public name: string,
|
||||
public core: NapCatCore,
|
||||
public actions: ActionMap,
|
||||
) {
|
||||
// 基础配置
|
||||
this.config = {
|
||||
name: name,
|
||||
messagePostFormat: 'array',
|
||||
reportSelfMessage: false,
|
||||
enable: true,
|
||||
debug: false,
|
||||
}
|
||||
}
|
||||
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
if (event.post_type === 'message') {
|
||||
plugin_onmessage(this.config.name, this.core, this.actions, event as OB11Message).then().catch();
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
}
|
||||
|
||||
async close() {
|
||||
|
||||
}
|
||||
|
||||
async reload() {
|
||||
return OB11NetworkReloadType.Normal;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user