mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 21:10:23 +00:00
Merge branch 'main' into pr/23
This commit is contained in:
@@ -3,18 +3,22 @@ import { OB11Constructor } from '../../constructor';
|
||||
import { friends } from '@/core/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi, WebApi } from '@/core/apis';
|
||||
import { NTQQUserApi, WebApi, WebHonorType } from '@/core/apis';
|
||||
interface Payload {
|
||||
group_id: number
|
||||
group_id: number,
|
||||
type?: WebHonorType
|
||||
}
|
||||
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||
actionName = ActionName.GetGroupHonorInfo;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||
if(!payload.group_id){
|
||||
if (!payload.group_id) {
|
||||
throw '缺少参数group_id';
|
||||
}
|
||||
return await WebApi.getGroupHonorInfo(payload.group_id.toString());
|
||||
if (!payload.type) {
|
||||
payload.type = WebHonorType.ALL;
|
||||
}
|
||||
return await WebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,76 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { selfInfo } from '@/core/data';
|
||||
import { logDebug, logError } from '@/common/utils/log';
|
||||
import { ConfigBase } from '@/common/utils/ConfigBase';
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { selfInfo } from "@/core/data";
|
||||
import { logDebug, logError } from "@/common/utils/log";
|
||||
import { ConfigBase } from "@/common/utils/ConfigBase";
|
||||
import { json } from "stream/consumers";
|
||||
|
||||
export interface OB11Config {
|
||||
httpHost: string;
|
||||
httpPort: number;
|
||||
httpPostUrls: string[];
|
||||
httpSecret: string;
|
||||
wsHost: string;
|
||||
wsPort: number;
|
||||
wsReverseUrls: string[];
|
||||
enableHttp: boolean;
|
||||
enableHttpHeart: boolean;
|
||||
enableHttpPost: boolean;
|
||||
enableWs: boolean;
|
||||
enableWsReverse: boolean;
|
||||
messagePostFormat: 'array' | 'string';
|
||||
reportSelfMessage: boolean;
|
||||
enableLocalFile2Url: boolean;
|
||||
http: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
secret: string;
|
||||
enableHeart: boolean;
|
||||
enablePost: boolean;
|
||||
postUrls: string[];
|
||||
};
|
||||
ws: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
};
|
||||
reverseWs: {
|
||||
enable: boolean;
|
||||
urls: string[];
|
||||
};
|
||||
|
||||
debug: boolean;
|
||||
heartInterval: number;
|
||||
token: string;
|
||||
messagePostFormat: "array" | "string";
|
||||
enableLocalFile2Url: boolean;
|
||||
musicSignUrl: string;
|
||||
reportSelfMessage: boolean;
|
||||
token: string;
|
||||
|
||||
read(): OB11Config;
|
||||
|
||||
save(config: OB11Config): void;
|
||||
}
|
||||
|
||||
|
||||
class Config extends ConfigBase<OB11Config> implements OB11Config {
|
||||
httpHost: string = '';
|
||||
httpPort: number = 3000;
|
||||
httpPostUrls: string[] = [];
|
||||
httpSecret = '';
|
||||
wsHost: string = '';
|
||||
wsPort = 3001;
|
||||
wsReverseUrls: string[] = [];
|
||||
enableHttp = false;
|
||||
enableHttpPost = false;
|
||||
enableHttpHeart = false;
|
||||
enableWs = false;
|
||||
enableWsReverse = false;
|
||||
messagePostFormat: 'array' | 'string' = 'array';
|
||||
reportSelfMessage = false;
|
||||
http = {
|
||||
enable: false,
|
||||
host: "",
|
||||
port: 3000,
|
||||
secret: "",
|
||||
enableHeart: false,
|
||||
enablePost: false,
|
||||
postUrls: [],
|
||||
};
|
||||
ws = {
|
||||
enable: false,
|
||||
host: "",
|
||||
port: 3001,
|
||||
};
|
||||
reverseWs = {
|
||||
enable: false,
|
||||
urls: [],
|
||||
};
|
||||
debug = false;
|
||||
enableLocalFile2Url = true;
|
||||
heartInterval = 30000;
|
||||
token = '';
|
||||
musicSignUrl = '';
|
||||
messagePostFormat: "array" | "string" = "array";
|
||||
enableLocalFile2Url = true;
|
||||
musicSignUrl = "";
|
||||
reportSelfMessage = false;
|
||||
token = "";
|
||||
|
||||
getConfigPath() {
|
||||
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
||||
}
|
||||
|
||||
protected getKeys(): string[] {
|
||||
return ['httpHost', 'enableHttp', 'httpPort', 'wsHost', 'enableWs', 'wsPort', 'enableWsReverse', 'wsReverseUrls', 'enableHttpPost', 'httpPostUrls', 'enableHttpHeart', 'httpSecret', 'messagePostFormat', 'reportSelfMessage', 'debug', 'enableLocalFile2Url', 'heartInterval', 'token', 'musicSignUrl'];
|
||||
protected getKeys(): string[] | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ChatType,
|
||||
FriendRequest,
|
||||
Group,
|
||||
GroupMember,
|
||||
GroupMemberRole,
|
||||
GroupNotify,
|
||||
GroupNotifyTypes,
|
||||
@@ -43,26 +44,26 @@ export class NapCatOnebot11 {
|
||||
logDebug('ob11 ready');
|
||||
ob11Config.read();
|
||||
const serviceInfo = `
|
||||
HTTP服务 ${ob11Config.enableHttp ? '已启动' : '未启动'}, ${ob11Config.httpHost}:${ob11Config.httpPort}
|
||||
HTTP上报服务 ${ob11Config.enableHttpPost ? '已启动' : '未启动'}, 上报地址: ${ob11Config.httpPostUrls}
|
||||
WebSocket服务 ${ob11Config.enableWs ? '已启动' : '未启动'}, ${ob11Config.wsHost}:${ob11Config.wsPort}
|
||||
WebSocket反向服务 ${ob11Config.enableWsReverse ? '已启动' : '未启动'}, 反向地址: ${ob11Config.wsReverseUrls}
|
||||
HTTP服务 ${ob11Config.http.enable ? '已启动' : '未启动'}, ${ob11Config.http.host}:${ob11Config.http.port}
|
||||
HTTP上报服务 ${ob11Config.http.enablePost ? '已启动' : '未启动'}, 上报地址: ${ob11Config.http.postUrls}
|
||||
WebSocket服务 ${ob11Config.ws.enable ? '已启动' : '未启动'}, ${ob11Config.ws.host}:${ob11Config.ws.port}
|
||||
WebSocket反向服务 ${ob11Config.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${ob11Config.reverseWs.urls}
|
||||
`;
|
||||
log(serviceInfo);
|
||||
NTQQUserApi.getUserDetailInfo(selfInfo.uid).then(user => {
|
||||
selfInfo.nick = user.nick;
|
||||
setLogSelfInfo(selfInfo);
|
||||
}).catch(logError);
|
||||
if (ob11Config.enableHttp) {
|
||||
ob11HTTPServer.start(ob11Config.httpPort, ob11Config.httpHost);
|
||||
if (ob11Config.http.enable) {
|
||||
ob11HTTPServer.start(ob11Config.http.port, ob11Config.http.host);
|
||||
}
|
||||
if (ob11Config.enableWs) {
|
||||
ob11WebsocketServer.start(ob11Config.wsPort, ob11Config.wsHost);
|
||||
if (ob11Config.ws.enable) {
|
||||
ob11WebsocketServer.start(ob11Config.ws.port, ob11Config.ws.host);
|
||||
}
|
||||
if (ob11Config.enableWsReverse) {
|
||||
if (ob11Config.reverseWs.enable) {
|
||||
ob11ReverseWebsockets.start();
|
||||
}
|
||||
if (ob11Config.enableHttpHeart) {
|
||||
if (ob11Config.http.enableHeart) {
|
||||
// 启动http心跳
|
||||
httpHeart.start();
|
||||
}
|
||||
@@ -131,6 +132,17 @@ export class NapCatOnebot11 {
|
||||
//console.log('ob11 onGroupNotifiesUpdated', notifies[0]);
|
||||
this.postGroupNotifies(notifies).then().catch(e => logError('postGroupNotifies error: ', e));
|
||||
};
|
||||
groupListener.onMemberInfoChange = async (groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
|
||||
// 如果自身是非管理员也许要从这里获取Delete 成员变动 待测试与验证
|
||||
let role = (await getGroupMember(groupCode, selfInfo.uin))?.role;
|
||||
let isPrivilege = role === 3 || role === 4;
|
||||
for (const member of members.values()) {
|
||||
if (member?.isDelete && !isPrivilege) {
|
||||
const groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(groupCode), parseInt(member.uin), 0, 'leave');// 不知道怎么出去的
|
||||
postOB11Event(groupDecreaseEvent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
groupListener.onJoinGroupNotify = (...notify) => {
|
||||
// console.log('ob11 onJoinGroupNotify', notify);
|
||||
};
|
||||
@@ -209,48 +221,48 @@ export class NapCatOnebot11 {
|
||||
// throw new Error('Invalid configuration object');
|
||||
// }
|
||||
|
||||
const isHttpChanged = !isEqual(NewOb11.httpPort, ob11Config.httpPort) && NewOb11.enableHttp;
|
||||
const isWsChanged = !isEqual(NewOb11.wsPort, ob11Config.wsPort);
|
||||
const isEnableWsChanged = !isEqual(NewOb11.enableWs, ob11Config.enableWs);
|
||||
const isEnableWsReverseChanged = !isEqual(NewOb11.enableWsReverse, ob11Config.enableWsReverse);
|
||||
const isWsReverseUrlsChanged = !isEqual(NewOb11.wsReverseUrls, ob11Config.wsReverseUrls);
|
||||
const isHttpChanged = !isEqual(NewOb11.http.port, ob11Config.http.port) && NewOb11.http.enable;
|
||||
const isWsChanged = !isEqual(NewOb11.ws.port, ob11Config.ws.port);
|
||||
const isEnableWsChanged = !isEqual(NewOb11.ws.enable, ob11Config.ws.enable);
|
||||
const isEnableWsReverseChanged = !isEqual(NewOb11.reverseWs.enable, ob11Config.reverseWs.enable);
|
||||
const isWsReverseUrlsChanged = !isEqual(NewOb11.reverseWs.urls, ob11Config.reverseWs.urls);
|
||||
|
||||
if (isHttpChanged) {
|
||||
ob11HTTPServer.restart(NewOb11.httpPort, NewOb11.httpHost);
|
||||
ob11HTTPServer.restart(NewOb11.http.port, NewOb11.http.host);
|
||||
}
|
||||
|
||||
if (!NewOb11.enableHttp) {
|
||||
if (!NewOb11.http.enable) {
|
||||
ob11HTTPServer.stop();
|
||||
} else {
|
||||
ob11HTTPServer.start(NewOb11.httpPort, NewOb11.httpHost);
|
||||
ob11HTTPServer.start(NewOb11.http.port, NewOb11.http.host);
|
||||
}
|
||||
|
||||
if (isWsChanged) {
|
||||
ob11WebsocketServer.restart(NewOb11.wsPort);
|
||||
ob11WebsocketServer.restart(NewOb11.ws.port);
|
||||
}
|
||||
|
||||
if (isEnableWsChanged) {
|
||||
if (NewOb11.enableWs) {
|
||||
ob11WebsocketServer.start(NewOb11.wsPort, NewOb11.wsHost);
|
||||
if (NewOb11.ws.enable) {
|
||||
ob11WebsocketServer.start(NewOb11.ws.port, NewOb11.ws.host);
|
||||
} else {
|
||||
ob11WebsocketServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
if (isEnableWsReverseChanged) {
|
||||
if (NewOb11.enableWsReverse) {
|
||||
if (NewOb11.reverseWs.enable) {
|
||||
ob11ReverseWebsockets.start();
|
||||
} else {
|
||||
ob11ReverseWebsockets.stop();
|
||||
}
|
||||
}
|
||||
if (NewOb11.enableWsReverse && isWsReverseUrlsChanged) {
|
||||
if (NewOb11.reverseWs.enable && isWsReverseUrlsChanged) {
|
||||
logDebug('反向ws地址有变化, 重启反向ws服务');
|
||||
ob11ReverseWebsockets.restart();
|
||||
}
|
||||
if (NewOb11.enableHttpHeart) {
|
||||
if (NewOb11.http.enableHeart) {
|
||||
httpHeart.start();
|
||||
} else if (!NewOb11.enableHttpHeart) {
|
||||
} else if (!NewOb11.http.enableHeart) {
|
||||
httpHeart.stop();
|
||||
}
|
||||
ob11Config.save(NewOb11);
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
{
|
||||
"httpHost": "",
|
||||
"enableHttp": false,
|
||||
"httpPort": 3000,
|
||||
"wsHost": "",
|
||||
"enableWs": false,
|
||||
"wsPort": 3001,
|
||||
"enableWsReverse": false,
|
||||
"wsReverseUrls": [],
|
||||
"enableHttpPost": false,
|
||||
"httpPostUrls": [],
|
||||
"enableHttpHeart": false,
|
||||
"httpSecret": "",
|
||||
"messagePostFormat": "array",
|
||||
"reportSelfMessage": false,
|
||||
"http": {
|
||||
"enable": false,
|
||||
"host": "",
|
||||
"port": 3000,
|
||||
"secret": "",
|
||||
"enableHeart": false,
|
||||
"enablePost": false,
|
||||
"postUrls": []
|
||||
},
|
||||
"ws": {
|
||||
"enable": false,
|
||||
"host": "",
|
||||
"port": 3001
|
||||
},
|
||||
"reverseWs": {
|
||||
"enable": false,
|
||||
"urls": []
|
||||
},
|
||||
"debug": false,
|
||||
"enableLocalFile2Url": true,
|
||||
"heartInterval": 30000,
|
||||
"token": "",
|
||||
"musicSignUrl": ""
|
||||
}
|
||||
"messagePostFormat": "array",
|
||||
"enableLocalFile2Url": true,
|
||||
"musicSignUrl": "",
|
||||
"reportSelfMessage": false,
|
||||
"token": ""
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class OB11HTTPServer extends HttpServerBase {
|
||||
}
|
||||
|
||||
protected listen(port: number, host: string) {
|
||||
if (ob11Config.enableHttp) {
|
||||
if (ob11Config.http.enable) {
|
||||
super.listen(port, host);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,19 +78,19 @@ export function postOB11Event(msg: PostEventType, reportSelf = false, postWs = t
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (config.enableHttpPost) {
|
||||
if (config.http.enablePost) {
|
||||
const msgStr = JSON.stringify(msg);
|
||||
const hmac = crypto.createHmac('sha1', ob11Config.httpSecret);
|
||||
const hmac = crypto.createHmac('sha1', ob11Config.http.secret);
|
||||
hmac.update(msgStr);
|
||||
const sig = hmac.digest('hex');
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-self-id': selfInfo.uin
|
||||
};
|
||||
if (config.httpSecret) {
|
||||
if (config.http.secret) {
|
||||
headers['x-signature'] = 'sha1=' + sig;
|
||||
}
|
||||
for (const host of config.httpPostUrls) {
|
||||
for (const host of config.http.postUrls) {
|
||||
fetch(host, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
|
||||
@@ -116,7 +116,7 @@ export class ReverseWebsocket {
|
||||
|
||||
class OB11ReverseWebsockets {
|
||||
start() {
|
||||
for (const url of ob11Config.wsReverseUrls) {
|
||||
for (const url of ob11Config.reverseWs.urls) {
|
||||
log('开始连接反向ws', url);
|
||||
new Promise(() => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user