mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 16:20:25 +00:00
Updated all network adapters' onEvent methods to be asynchronous and return Promises, ensuring consistent async event emission and handling. Adjusted related methods and event emission logic to properly await asynchronous operations, improving reliability for streaming, plugin, HTTP, and WebSocket event flows. Also improved error handling and messaging in stream and WebSocket actions.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
|
import { LogWrapper } from '@/common/log';
|
|
import { NapCatCore } from '@/core';
|
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
|
import { ActionMap } from '@/onebot/action';
|
|
import { OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index';
|
|
|
|
export abstract class IOB11NetworkAdapter<CT extends NetworkAdapterConfig> {
|
|
name: string;
|
|
isEnable: boolean = false;
|
|
config: CT;
|
|
readonly logger: LogWrapper;
|
|
readonly core: NapCatCore;
|
|
readonly obContext: NapCatOneBot11Adapter;
|
|
readonly actions: ActionMap;
|
|
|
|
constructor(name: string, config: CT, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap) {
|
|
this.name = name;
|
|
this.config = structuredClone(config);
|
|
this.core = core;
|
|
this.obContext = obContext;
|
|
this.actions = actions;
|
|
this.logger = core.context.logger;
|
|
}
|
|
|
|
abstract onEvent<T extends OB11EmitEventContent>(event: T): Promise<void>;
|
|
|
|
abstract open(): void | Promise<void>;
|
|
|
|
abstract close(): void | Promise<void>;
|
|
|
|
abstract reload(config: unknown): OB11NetworkReloadType | Promise<OB11NetworkReloadType>;
|
|
}
|