mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
Merge remote-tracking branch 'origin/v2' into v2
# Conflicts: # src/onebot/action/extends/GetFriendWithCategory.ts
This commit is contained in:
commit
40362590c8
@ -1,6 +1,6 @@
|
|||||||
|
import { OB11Constructor } from '@/onebot/helper/data';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { OB11Constructor } from '@/onebot/helper/data';
|
|
||||||
|
|
||||||
export class GetFriendWithCategory extends BaseAction<void, any> {
|
export class GetFriendWithCategory extends BaseAction<void, any> {
|
||||||
actionName = ActionName.GetFriendsWithCategory;
|
actionName = ActionName.GetFriendsWithCategory;
|
||||||
|
@ -3,12 +3,13 @@ import { OB11Config } from './helper/config';
|
|||||||
import { NapCatPathWrapper } from '@/common/framework/napcat';
|
import { NapCatPathWrapper } from '@/common/framework/napcat';
|
||||||
import { OneBotApiContextType } from './types/adapter';
|
import { OneBotApiContextType } from './types/adapter';
|
||||||
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api';
|
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api';
|
||||||
import { OB11NetworkManager } from '@/onebot/network';
|
import { OB11NetworkManager, OB11PassiveHttpAdapter } from '@/onebot/network';
|
||||||
import { OB11InputStatusEvent } from '@/onebot/event/notice/OB11InputStatusEvent';
|
import { OB11InputStatusEvent } from '@/onebot/event/notice/OB11InputStatusEvent';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
import { OB11Constructor } from '@/onebot/helper/data';
|
import { OB11Constructor } from '@/onebot/helper/data';
|
||||||
import { logOB11Message } from '@/onebot/helper/log';
|
import { logOB11Message } from '@/onebot/helper/log';
|
||||||
import { proxiedListenerOf } from '@/common/utils/proxy-handler';
|
import { proxiedListenerOf } from '@/common/utils/proxy-handler';
|
||||||
|
import { createActionMap } from './action';
|
||||||
|
|
||||||
//OneBot实现类
|
//OneBot实现类
|
||||||
export class NapCatOneBot11Adapter {
|
export class NapCatOneBot11Adapter {
|
||||||
@ -50,6 +51,11 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.context.logger.setLogSelfInfo(selfInfo);
|
this.context.logger.setLogSelfInfo(selfInfo);
|
||||||
}).catch(this.context.logger.logError);
|
}).catch(this.context.logger.logError);
|
||||||
this.context.logger.log(`[Notice] [OneBot11] ${serviceInfo}`);
|
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
|
// Todo 开始启动NetWork
|
||||||
await this.initMsgListener();
|
await this.initMsgListener();
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
registerHeartBeat() {
|
registerHeartBeat() {
|
||||||
// HttpPost 心跳
|
// HttpPost 心跳
|
||||||
}
|
}
|
||||||
|
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||||
|
}
|
||||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||||
// Passive http adapter does not need to register actions
|
// Passive http adapter does not need to register actions
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,9 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
this.coreContext = coreContext;
|
this.coreContext = coreContext;
|
||||||
this.onebotContext = onebotContext;
|
this.onebotContext = onebotContext;
|
||||||
}
|
}
|
||||||
|
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||||
|
this.actionMap = actionMap;
|
||||||
|
}
|
||||||
registerHeartBeat() {
|
registerHeartBeat() {
|
||||||
if (this.connection) {
|
if (this.connection) {
|
||||||
this.heartbeatTimer = setInterval(() => {
|
this.heartbeatTimer = setInterval(() => {
|
||||||
|
@ -7,6 +7,8 @@ export type OB11EmitEventContent = OB11BaseEvent | OB11Message;
|
|||||||
export interface IOB11NetworkAdapter {
|
export interface IOB11NetworkAdapter {
|
||||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T): void;
|
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;
|
onEvent<T extends OB11EmitEventContent>(event: T): void;
|
||||||
|
|
||||||
open(): void | Promise<void>;
|
open(): void | Promise<void>;
|
||||||
@ -16,11 +18,15 @@ export interface IOB11NetworkAdapter {
|
|||||||
|
|
||||||
export class OB11NetworkManager {
|
export class OB11NetworkManager {
|
||||||
adapters: IOB11NetworkAdapter[] = [];
|
adapters: IOB11NetworkAdapter[] = [];
|
||||||
|
|
||||||
async getAllAdapters() {
|
async getAllAdapters() {
|
||||||
return this.adapters;
|
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) {
|
async emitEvent(event: OB11EmitEventContent) {
|
||||||
// Mlikiowa V2.0.0 Refactor Todo
|
// Mlikiowa V2.0.0 Refactor Todo
|
||||||
return Promise.all(this.adapters.map(adapter => adapter.onEvent(event)));
|
return Promise.all(this.adapters.map(adapter => adapter.onEvent(event)));
|
||||||
|
@ -3,6 +3,8 @@ 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 { NapCatCore } from '@/core';
|
||||||
|
import { NapCatOneBot11Adapter } from '../main';
|
||||||
|
|
||||||
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
private app: Express | undefined;
|
private app: Express | undefined;
|
||||||
@ -12,16 +14,22 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||||
private port: number;
|
private port: number;
|
||||||
token: string;
|
token: string;
|
||||||
|
coreContext: NapCatCore;
|
||||||
|
onebotContext: NapCatOneBot11Adapter;
|
||||||
|
|
||||||
constructor(port: number, token: string) {
|
constructor(port: number, token: string, coreContext: NapCatCore, onebotContext: NapCatOneBot11Adapter) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
this.coreContext = coreContext;
|
||||||
|
this.onebotContext = onebotContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||||
this.actionMap.set(action.actionName, action);
|
this.actionMap.set(action.actionName, action);
|
||||||
}
|
}
|
||||||
|
registerActionMap(actionMap: Map<string, BaseAction<any, any>>) {
|
||||||
|
this.actionMap = actionMap;
|
||||||
|
}
|
||||||
registerHeartBeat() {
|
registerHeartBeat() {
|
||||||
//空心跳
|
//空心跳
|
||||||
}
|
}
|
||||||
@ -32,7 +40,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
open() {
|
open() {
|
||||||
if (this.hasBeenClosed) {
|
if (this.hasBeenClosed) {
|
||||||
throw new Error('Cannot open a closed HTTP server');
|
this.coreContext.context.logger.logError('Cannot open a closed HTTP server');
|
||||||
}
|
}
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
this.initializeServer();
|
this.initializeServer();
|
||||||
@ -46,10 +54,10 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
this.app.use(express.json());
|
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.server.listen(this.port, () => {
|
||||||
console.log(`HTTP server listening on port ${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) {
|
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||||
this.actionMap.set(action.actionName, action);
|
this.actionMap.set(action.actionName, action);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user