mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
@@ -1,18 +1,12 @@
|
|||||||
import { IOB11NetworkAdapter } from '@/onebot/network/index';
|
import { IOB11NetworkAdapter } from '@/onebot/network/index';
|
||||||
import BaseAction from '@/onebot/action/BaseAction';
|
import BaseAction from '@/onebot/action/BaseAction';
|
||||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||||
import { NapCatOneBot11Adapter } from '../main';
|
|
||||||
import { NapCatCore } from '@/core';
|
|
||||||
|
|
||||||
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
url: string;
|
url: string;
|
||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||||
obContext: NapCatOneBot11Adapter;
|
|
||||||
coreContext: NapCatCore;
|
|
||||||
|
|
||||||
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore, url: string) {
|
constructor(url: string) {
|
||||||
this.obContext = obContext;
|
|
||||||
this.coreContext = coreContext
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,8 +4,6 @@ import { WebSocket as NodeWebSocket } from 'ws';
|
|||||||
import BaseAction from '@/onebot/action/BaseAction';
|
import BaseAction from '@/onebot/action/BaseAction';
|
||||||
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||||
import { sleep } from '@/common/utils/helper';
|
import { sleep } from '@/common/utils/helper';
|
||||||
import { NapCatOneBot11Adapter } from '../main';
|
|
||||||
import { NapCatCore } from '@/core';
|
|
||||||
|
|
||||||
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -14,12 +12,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
private connection: NodeWebSocket | null = null;
|
private connection: NodeWebSocket | null = null;
|
||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||||
obContext: NapCatOneBot11Adapter;
|
|
||||||
coreContext: NapCatCore;
|
|
||||||
|
|
||||||
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore, url: string, reconnectIntervalInMillis: number) {
|
constructor(url: string, reconnectIntervalInMillis: number) {
|
||||||
this.obContext = obContext;
|
|
||||||
this.coreContext = coreContext
|
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.reconnectIntervalInMillis = reconnectIntervalInMillis;
|
this.reconnectIntervalInMillis = reconnectIntervalInMillis;
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,6 @@ import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
|||||||
import BaseAction from '@/onebot/action/BaseAction';
|
import BaseAction from '@/onebot/action/BaseAction';
|
||||||
import express, { Express, Request, Response } from 'express';
|
import express, { Express, Request, Response } from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { NapCatOneBot11Adapter } from '../main';
|
|
||||||
import { NapCatCore } from '@/core';
|
|
||||||
|
|
||||||
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
@@ -13,12 +11,8 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
private hasBeenClosed: boolean = false;
|
private hasBeenClosed: boolean = false;
|
||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||||
private port: number;
|
private port: number;
|
||||||
obContext: NapCatOneBot11Adapter;
|
|
||||||
coreContext: NapCatCore;
|
|
||||||
|
|
||||||
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore, port: number) {
|
constructor(port: number) {
|
||||||
this.obContext = obContext;
|
|
||||||
this.coreContext = coreContext
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,8 +3,6 @@ import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
|||||||
import BaseAction from '@/onebot/action/BaseAction';
|
import BaseAction from '@/onebot/action/BaseAction';
|
||||||
import { WebSocket, WebSocketServer } from 'ws';
|
import { WebSocket, WebSocketServer } from 'ws';
|
||||||
import { Mutex } from 'async-mutex';
|
import { Mutex } from 'async-mutex';
|
||||||
import { NapCatOneBot11Adapter } from '../main';
|
|
||||||
import { NapCatCore } from '@/core';
|
|
||||||
|
|
||||||
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||||
wsServer: WebSocketServer;
|
wsServer: WebSocketServer;
|
||||||
@@ -12,13 +10,10 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
wsClientsMutex = new Mutex();
|
wsClientsMutex = new Mutex();
|
||||||
isOpen: boolean = false;
|
isOpen: boolean = false;
|
||||||
hasBeenClosed: boolean = false;
|
hasBeenClosed: boolean = false;
|
||||||
obContext: NapCatOneBot11Adapter;
|
|
||||||
coreContext: NapCatCore;
|
|
||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||||
|
|
||||||
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore,ip: string, port: number, token: string) {
|
constructor(ip: string, port: number, token: string) {
|
||||||
this.obContext = obContext;
|
|
||||||
this.coreContext = coreContext
|
|
||||||
this.wsServer = new WebSocketServer({ port: port, host: ip });
|
this.wsServer = new WebSocketServer({ port: port, host: ip });
|
||||||
this.wsServer.on('connection', async (wsClient) => {
|
this.wsServer.on('connection', async (wsClient) => {
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
|
Reference in New Issue
Block a user