mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
chore:fix
This commit is contained in:
parent
8841cbb3d0
commit
2f2c1f263a
@ -1,6 +1,6 @@
|
||||
import { OB11Constructor } from '@/onebot/helper/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { OB11Constructor } from '@/onebot/helper/constructor';
|
||||
|
||||
export class GetFriendWithCategory extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
|
@ -9,6 +9,7 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { OB11Constructor } from '@/onebot/helper/data';
|
||||
import { logOB11Message } from '@/onebot/helper/log';
|
||||
import { proxiedListenerOf } from '@/common/utils/proxy-handler';
|
||||
import { createActionMap } from './action';
|
||||
|
||||
//OneBot实现类
|
||||
export class NapCatOneBot11Adapter {
|
||||
@ -50,8 +51,10 @@ export class NapCatOneBot11Adapter {
|
||||
this.context.logger.setLogSelfInfo(selfInfo);
|
||||
}).catch(this.context.logger.logError);
|
||||
this.context.logger.log(`[Notice] [OneBot11] ${serviceInfo}`);
|
||||
let actions = createActionMap(this, this.core);
|
||||
let OB11NetworkManagerWrap = new OB11NetworkManager();
|
||||
OB11NetworkManagerWrap.registerAdapter(new OB11PassiveHttpAdapter(ob11Config.http.port, ob11Config.token, this.core, this));
|
||||
OB11NetworkManagerWrap.registerAllActions(actions);
|
||||
OB11NetworkManagerWrap.openAllAdapters();
|
||||
// Todo 开始启动NetWork
|
||||
await this.initMsgListener();
|
||||
|
@ -28,7 +28,8 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
registerHeartBeat() {
|
||||
// HttpPost 心跳
|
||||
}
|
||||
|
||||
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||
}
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
// Passive http adapter does not need to register actions
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
this.coreContext = coreContext;
|
||||
this.onebotContext = onebotContext;
|
||||
}
|
||||
|
||||
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||
this.actionMap = actionMap;
|
||||
}
|
||||
registerHeartBeat() {
|
||||
if (this.connection) {
|
||||
this.heartbeatTimer = setInterval(() => {
|
||||
|
@ -7,6 +7,8 @@ export type OB11EmitEventContent = OB11BaseEvent | OB11Message;
|
||||
export interface IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T): void;
|
||||
|
||||
registerActionMap(actionMap: Map<string, BaseAction<any, any>>): void;
|
||||
|
||||
onEvent<T extends OB11EmitEventContent>(event: T): void;
|
||||
|
||||
open(): void | Promise<void>;
|
||||
@ -16,13 +18,15 @@ export interface IOB11NetworkAdapter {
|
||||
|
||||
export class OB11NetworkManager {
|
||||
adapters: IOB11NetworkAdapter[] = [];
|
||||
|
||||
async getAllAdapters() {
|
||||
return this.adapters;
|
||||
}
|
||||
async openAllAdapters() {
|
||||
return Promise.all(this.adapters.map(adapter => adapter.open()));
|
||||
}
|
||||
async registerAllActions(actions: Map<string,BaseAction<any, any>>) {
|
||||
return Promise.all(this.adapters.map(adapter => adapter.registerActionMap(actions)));
|
||||
}
|
||||
async emitEvent(event: OB11EmitEventContent) {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
return Promise.all(this.adapters.map(adapter => adapter.onEvent(event)));
|
||||
|
@ -27,7 +27,9 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||
this.actionMap = actionMap;
|
||||
}
|
||||
registerHeartBeat() {
|
||||
//空心跳
|
||||
}
|
||||
@ -52,7 +54,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
|
||||
this.app.use(express.json());
|
||||
|
||||
this.app.all('*', this.handleRequest.bind(this));
|
||||
this.app.all('/*', this.handleRequest.bind(this));
|
||||
|
||||
this.server.listen(this.port, () => {
|
||||
this.coreContext.context.logger.log(`HTTP server listening on port ${this.port}`);
|
||||
|
@ -44,7 +44,9 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||
this.actionMap = actionMap;
|
||||
}
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user