chore: clean-up

This commit is contained in:
Wesley F. Young committed 2024-08-11 23:08:41 +08:00
1 parent f91ab8b550
commit fe51c46bb8
3 files changed
+51 -58

No files matched your search

+12 -15
View File
@@ -6,33 +6,30 @@ import { NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '../main';
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
token: string;
coreContext: NapCatCore;
obContext: NapCatOneBot11Adapter;
private app: Express | undefined;
private server: http.Server | undefined;
private isOpen: boolean = false;
private hasBeenClosed: boolean = false;
private actionMap: Map<string, BaseAction<any, any>> = new Map();
private port: number;
token: string;
coreContext: NapCatCore;
onebotContext: NapCatOneBot11Adapter;
constructor(port: number, token: string, coreContext: NapCatCore, onebotContext: NapCatOneBot11Adapter) {
this.port = port;
this.token = token;
this.coreContext = coreContext;
this.onebotContext = onebotContext;
this.obContext = onebotContext;
}
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
this.actionMap.set(action.actionName, action);
}
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
this.actionMap = actionMap;
}
registerHeartBeat() {
//空心跳
}
onEvent<T extends OB11EmitEventContent>(event: T) {
// 事件处理逻辑可以在这里实现
@@ -48,6 +45,13 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
}
}
async close() {
this.isOpen = false;
this.hasBeenClosed = true;
this.server?.close();
this.app = undefined;
}
private initializeServer() {
this.app = express();
this.server = http.createServer(this.app);
@@ -80,11 +84,4 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
res.status(404).send('Action not found');
}
}
async close() {
this.isOpen = false;
this.hasBeenClosed = true;
this.server?.close();
this.app = undefined;
}
}