mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
update: EmitEventContent = Message + Event
This commit is contained in:
parent
40f85dbf5f
commit
bbe666eb73
@ -1,4 +1,4 @@
|
||||
import { IOB11NetworkAdapter } from '@/onebot/network/index';
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent } from '@/onebot/network/index';
|
||||
import BaseAction from '@/onebot/action/BaseAction';
|
||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||
import { createHmac } from 'crypto';
|
||||
@ -33,7 +33,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
// Passive http adapter does not need to register actions
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-self-id': this.coreContext.selfInfo.uin,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IOB11NetworkAdapter } from '@/onebot/network/index';
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent } from '@/onebot/network/index';
|
||||
|
||||
import { WebSocket as NodeWebSocket } from 'ws';
|
||||
import BaseAction from '@/onebot/action/BaseAction';
|
||||
@ -28,7 +28,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
if (this.connection) {
|
||||
// this.connection.send(JSON.stringify(event));
|
||||
// TODO: wrap the event, and send the wrapped to the server.
|
||||
|
@ -1,10 +1,13 @@
|
||||
import BaseAction from '@/onebot/action/BaseAction';
|
||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||
import { OB11Message } from '@/onebot';
|
||||
|
||||
export type OB11EmitEventContent = OB11BaseEvent | OB11Message;
|
||||
|
||||
export interface IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T): void;
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T): void;
|
||||
onEvent<T extends OB11EmitEventContent>(event: T): void;
|
||||
|
||||
open(): void | Promise<void>;
|
||||
|
||||
@ -18,7 +21,7 @@ export class OB11NetworkManager {
|
||||
return this.adapters;
|
||||
}
|
||||
|
||||
async emitEvent(event: OB11BaseEvent) {
|
||||
async emitEvent(event: OB11EmitEventContent) {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
return Promise.all(this.adapters.map(adapter => adapter.onEvent(event)));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IOB11NetworkAdapter } from './index';
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent } from './index';
|
||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||
import BaseAction from '@/onebot/action/BaseAction';
|
||||
import express, { Express, Request, Response } from 'express';
|
||||
@ -26,7 +26,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
//空心跳
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
// 事件处理逻辑可以在这里实现
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { IOB11NetworkAdapter } from './index';
|
||||
import { IOB11NetworkAdapter, OB11EmitEventContent } from './index';
|
||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||
import BaseAction from '@/onebot/action/BaseAction';
|
||||
import { WebSocket, WebSocketServer } from 'ws';
|
||||
@ -54,7 +54,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
//WS正向心跳
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||
this.wsClientsMutex.runExclusive(async () => {
|
||||
this.wsClients.forEach((wsClient) => {
|
||||
// wsClient.send(JSON.stringify(event));
|
||||
|
Loading…
x
Reference in New Issue
Block a user