mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b2e0cab702 | ||
![]() |
3e3609e0f2 | ||
![]() |
83e73d9842 | ||
![]() |
673a175ddf | ||
![]() |
12eacd3530 | ||
![]() |
030f0551fd | ||
![]() |
47f5947410 | ||
![]() |
aaefa2e83c | ||
![]() |
f8e92f7c8d | ||
![]() |
b6430e6eb6 | ||
![]() |
e60605c7bb |
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -6,5 +6,7 @@
|
|||||||
"tsconfig.json": "tsconfig.*.json, env.d.ts, vite.config.ts",
|
"tsconfig.json": "tsconfig.*.json, env.d.ts, vite.config.ts",
|
||||||
"package.json": "package-lock.json, eslint*, .prettier*, .editorconfig, manifest.json, logo.png, .gitignore, LICENSE"
|
"package.json": "package-lock.json, eslint*, .prettier*, .editorconfig, manifest.json, logo.png, .gitignore, LICENSE"
|
||||||
},
|
},
|
||||||
"css.customData": [".vscode/tailwindcss.json"],
|
"css.customData": [
|
||||||
|
".vscode/tailwindcss.json"
|
||||||
|
],
|
||||||
}
|
}
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.7.6",
|
"version": "4.7.9",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.7.6",
|
"version": "4.7.9",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.7.6';
|
export const napCatVersion = '4.7.9';
|
||||||
|
@@ -5,6 +5,9 @@ export async function runTask<T, R>(workerScript: string, taskData: T): Promise<
|
|||||||
try {
|
try {
|
||||||
return await new Promise<R>((resolve, reject) => {
|
return await new Promise<R>((resolve, reject) => {
|
||||||
worker.on('message', (result: R) => {
|
worker.on('message', (result: R) => {
|
||||||
|
if ((result as any)?.error) {
|
||||||
|
reject(new Error((result as { error: string }).error));
|
||||||
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -90,7 +90,30 @@ export class NTQQUserApi {
|
|||||||
() => true,
|
() => true,
|
||||||
(profile) => profile.uid === uid,
|
(profile) => profile.uid === uid,
|
||||||
);
|
);
|
||||||
const RetUser: User = {
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUserDetailInfo(uid: string, no_cache: boolean = false): Promise<User> {
|
||||||
|
let profile = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, no_cache ? UserDetailSource.KSERVER : UserDetailSource.KDB), uid);
|
||||||
|
if (profile && profile.uin !== '0' && profile.commonExt) {
|
||||||
|
return {
|
||||||
|
...profile.simpleInfo.status,
|
||||||
|
...profile.simpleInfo.vasInfo,
|
||||||
|
...profile.commonExt,
|
||||||
|
...profile.simpleInfo.baseInfo,
|
||||||
|
...profile.simpleInfo.coreInfo,
|
||||||
|
qqLevel: profile.commonExt?.qqLevel,
|
||||||
|
age: profile.simpleInfo.baseInfo.age,
|
||||||
|
pendantId: '',
|
||||||
|
nick: profile.simpleInfo.coreInfo.nick || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
||||||
|
profile = await this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
||||||
|
if (profile && profile.uin === '0') {
|
||||||
|
profile.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
||||||
|
}
|
||||||
|
return {
|
||||||
...profile.simpleInfo.status,
|
...profile.simpleInfo.status,
|
||||||
...profile.simpleInfo.vasInfo,
|
...profile.simpleInfo.vasInfo,
|
||||||
...profile.commonExt,
|
...profile.commonExt,
|
||||||
@@ -101,33 +124,6 @@ export class NTQQUserApi {
|
|||||||
pendantId: '',
|
pendantId: '',
|
||||||
nick: profile.simpleInfo.coreInfo.nick || '',
|
nick: profile.simpleInfo.coreInfo.nick || '',
|
||||||
};
|
};
|
||||||
return RetUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUserDetailInfo(uid: string): Promise<User> {
|
|
||||||
let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB), uid);
|
|
||||||
if (retUser && retUser.uin !== '0') {
|
|
||||||
return retUser;
|
|
||||||
}
|
|
||||||
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
|
||||||
retUser = await this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
|
||||||
if (retUser && retUser.uin === '0') {
|
|
||||||
retUser.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
|
||||||
}
|
|
||||||
return retUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUserDetailInfoV2(uid: string): Promise<User> {
|
|
||||||
const fallback = new Fallback<User>((user) => FallbackUtil.boolchecker(user, user !== undefined && user.uin !== '0'))
|
|
||||||
.add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KDB))
|
|
||||||
.add(() => this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER));
|
|
||||||
const retUser = await fallback.run().then(async (user) => {
|
|
||||||
if (user && user.uin === '0') {
|
|
||||||
user.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
});
|
|
||||||
return retUser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async modifySelfProfile(param: ModifyProfileParams) {
|
async modifySelfProfile(param: ModifyProfileParams) {
|
||||||
|
@@ -38,12 +38,12 @@ export class NativePacketClient extends IPacketClient {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(pid: number, recv: string, send: string): Promise<void> {
|
async init(_pid: number, recv: string, send: string): Promise<void> {
|
||||||
const platform = process.platform + '.' + process.arch;
|
const platform = process.platform + '.' + process.arch;
|
||||||
const moehoo_path = path.join(dirname(fileURLToPath(import.meta.url)), './moehoo/MoeHoo.' + platform + '.node');
|
const moehoo_path = path.join(dirname(fileURLToPath(import.meta.url)), './moehoo/MoeHoo.' + platform + '.node');
|
||||||
process.dlopen(this.MoeHooExport, moehoo_path, constants.dlopen.RTLD_LAZY);
|
process.dlopen(this.MoeHooExport, moehoo_path, constants.dlopen.RTLD_LAZY);
|
||||||
|
|
||||||
this.MoeHooExport.exports.InitHook?.(send, recv, (type: number, uin: string, cmd: string, seq: number, hex_data: string) => {
|
this.MoeHooExport.exports.InitHook?.(send, recv, (type: number, _uin: string, cmd: string, seq: number, hex_data: string) => {
|
||||||
const trace_id = createHash('md5').update(Buffer.from(hex_data, 'hex')).digest('hex');
|
const trace_id = createHash('md5').update(Buffer.from(hex_data, 'hex')).digest('hex');
|
||||||
if (type === 0 && this.cb.get(trace_id + 'recv')) {
|
if (type === 0 && this.cb.get(trace_id + 'recv')) {
|
||||||
//此时为send 提取seq
|
//此时为send 提取seq
|
||||||
|
@@ -1,113 +0,0 @@
|
|||||||
import { Data, WebSocket, ErrorEvent } from 'ws';
|
|
||||||
import { IPacketClient, RecvPacket } from '@/core/packet/client/baseClient';
|
|
||||||
import { LogStack } from '@/core/packet/context/clientContext';
|
|
||||||
import { NapCoreContext } from '@/core/packet/context/napCoreContext';
|
|
||||||
import { PacketLogger } from '@/core/packet/context/loggerContext';
|
|
||||||
|
|
||||||
export class WsPacketClient extends IPacketClient {
|
|
||||||
private websocket: WebSocket | null = null;
|
|
||||||
private reconnectAttempts: number = 0;
|
|
||||||
private readonly maxReconnectAttempts: number = 60; // 现在暂时不可配置
|
|
||||||
private readonly clientUrl: string;
|
|
||||||
private readonly clientUrlWrap: (url: string) => string = (url: string) => `ws://${url}/ws`;
|
|
||||||
|
|
||||||
private isInitialized: boolean = false;
|
|
||||||
private initPayload: { pid: number, recv: string, send: string } | null = null;
|
|
||||||
|
|
||||||
constructor(napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) {
|
|
||||||
super(napCore, logger, logStack);
|
|
||||||
this.clientUrl = this.napcore.config.packetServer
|
|
||||||
? this.clientUrlWrap(this.napcore.config.packetServer)
|
|
||||||
: this.clientUrlWrap('127.0.0.1:8083');
|
|
||||||
}
|
|
||||||
|
|
||||||
check(): boolean {
|
|
||||||
if (!this.napcore.config.packetServer) {
|
|
||||||
this.logStack.pushLogWarn('wsPacketClient 未配置服务器地址');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
async init(pid: number, recv: string, send: string): Promise<void> {
|
|
||||||
this.initPayload = { pid, recv, send };
|
|
||||||
await this.connectWithRetry();
|
|
||||||
}
|
|
||||||
|
|
||||||
sendCommandImpl(cmd: string, data: string, trace_id: string): void {
|
|
||||||
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
|
||||||
this.websocket.send(JSON.stringify({
|
|
||||||
action: 'send',
|
|
||||||
cmd,
|
|
||||||
data,
|
|
||||||
trace_id
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
this.logStack.pushLogWarn(`WebSocket 未连接,无法发送命令: ${cmd}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async connectWithRetry(): Promise<void> {
|
|
||||||
while (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
||||||
try {
|
|
||||||
await this.connect();
|
|
||||||
return;
|
|
||||||
} catch {
|
|
||||||
this.reconnectAttempts++;
|
|
||||||
this.logStack.pushLogWarn(`第 ${this.reconnectAttempts}/${this.maxReconnectAttempts} 次尝试重连失败!`);
|
|
||||||
await this.delay(5000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.logStack.pushLogError(`wsPacketClient 在 ${this.clientUrl} 达到最大重连次数 (${this.maxReconnectAttempts})!`);
|
|
||||||
throw new Error(`无法连接到 WebSocket 服务器:${this.clientUrl}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
private connect(): Promise<void> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.websocket = new WebSocket(this.clientUrl);
|
|
||||||
this.websocket.onopen = () => {
|
|
||||||
this.available = true;
|
|
||||||
this.reconnectAttempts = 0;
|
|
||||||
this.logger.info(`wsPacketClient 已连接到 ${this.clientUrl}`);
|
|
||||||
if (!this.isInitialized && this.initPayload) {
|
|
||||||
this.websocket!.send(JSON.stringify({
|
|
||||||
action: 'init',
|
|
||||||
...this.initPayload
|
|
||||||
}));
|
|
||||||
this.isInitialized = true;
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
this.websocket.onclose = () => {
|
|
||||||
this.available = false;
|
|
||||||
this.logger.warn('WebSocket 连接关闭,尝试重连...');
|
|
||||||
reject(new Error('WebSocket 连接关闭'));
|
|
||||||
};
|
|
||||||
this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => {
|
|
||||||
this.logger.error(`处理消息时出错: ${err}`);
|
|
||||||
});
|
|
||||||
this.websocket.onerror = (event: ErrorEvent) => {
|
|
||||||
this.available = false;
|
|
||||||
this.logger.error(`WebSocket 出错: ${event.message}`);
|
|
||||||
this.websocket?.close();
|
|
||||||
reject(new Error(`WebSocket 出错: ${event.message}`));
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private delay(ms: number): Promise<void> {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleMessage(message: Data): Promise<void> {
|
|
||||||
try {
|
|
||||||
const json: RecvPacket = JSON.parse(message.toString());
|
|
||||||
const trace_id_md5 = json.trace_id_md5;
|
|
||||||
const action = json?.type ?? 'init';
|
|
||||||
const event = this.cb.get(`${trace_id_md5}${action}`);
|
|
||||||
if (event) await event(json.data);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(`解析ws消息时出错: ${(error as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,6 +1,5 @@
|
|||||||
import { IPacketClient } from '@/core/packet/client/baseClient';
|
import { IPacketClient } from '@/core/packet/client/baseClient';
|
||||||
import { NativePacketClient } from '@/core/packet/client/nativeClient';
|
import { NativePacketClient } from '@/core/packet/client/nativeClient';
|
||||||
import { WsPacketClient } from '@/core/packet/client/wsClient';
|
|
||||||
import { OidbPacket } from '@/core/packet/transformer/base';
|
import { OidbPacket } from '@/core/packet/transformer/base';
|
||||||
import { PacketLogger } from '@/core/packet/context/loggerContext';
|
import { PacketLogger } from '@/core/packet/context/loggerContext';
|
||||||
import { NapCoreContext } from '@/core/packet/context/napCoreContext';
|
import { NapCoreContext } from '@/core/packet/context/napCoreContext';
|
||||||
@@ -10,8 +9,7 @@ type clientPriorityType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const clientPriority: clientPriorityType = {
|
const clientPriority: clientPriorityType = {
|
||||||
10: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new NativePacketClient(napCore, logger, logStack),
|
10: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new NativePacketClient(napCore, logger, logStack)
|
||||||
1: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new WsPacketClient(napCore, logger, logStack),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class LogStack {
|
export class LogStack {
|
||||||
@@ -88,10 +86,6 @@ export class PacketClientContext {
|
|||||||
this.logger.info('使用指定的 NativePacketClient 作为后端');
|
this.logger.info('使用指定的 NativePacketClient 作为后端');
|
||||||
client = new NativePacketClient(this.napCore, this.logger, this.logStack);
|
client = new NativePacketClient(this.napCore, this.logger, this.logStack);
|
||||||
break;
|
break;
|
||||||
case 'frida':
|
|
||||||
this.logger.info('[Core] [Packet] 使用指定的 FridaPacketClient 作为后端');
|
|
||||||
client = new WsPacketClient(this.napCore, this.logger, this.logStack);
|
|
||||||
break;
|
|
||||||
case 'auto':
|
case 'auto':
|
||||||
case undefined:
|
case undefined:
|
||||||
client = this.judgeClient();
|
client = this.judgeClient();
|
||||||
|
@@ -16,7 +16,7 @@ export interface NodeIKernelBuddyService {
|
|||||||
|
|
||||||
getBuddyListFromCache(reqType: BuddyListReqType): Promise<Array<
|
getBuddyListFromCache(reqType: BuddyListReqType): Promise<Array<
|
||||||
{
|
{
|
||||||
categoryId: number,//9999应该跳过 那是兜底数据吧
|
categoryId: number,//9999为特别关心
|
||||||
categorySortId: number,//排序方式
|
categorySortId: number,//排序方式
|
||||||
categroyName: string,//分类名
|
categroyName: string,//分类名
|
||||||
categroyMbCount: number,//不懂
|
categroyMbCount: number,//不懂
|
||||||
|
@@ -207,6 +207,7 @@ interface PhotoWall {
|
|||||||
|
|
||||||
// 简单信息
|
// 简单信息
|
||||||
export interface SimpleInfo {
|
export interface SimpleInfo {
|
||||||
|
qqLevel?: QQLevel;//临时添加
|
||||||
uid?: string;
|
uid?: string;
|
||||||
uin?: string;
|
uin?: string;
|
||||||
coreInfo: CoreInfo;
|
coreInfo: CoreInfo;
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,8 +14,22 @@ export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
|
|||||||
override actionName = ActionName.GetFriendList;
|
override actionName = ActionName.GetFriendList;
|
||||||
override payloadSchema = SchemaData;
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(_payload: Payload) {
|
||||||
//全新逻辑
|
const buddyMap = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
|
||||||
return OB11Construct.friends(await this.core.apis.FriendApi.getBuddy(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
|
|
||||||
|
await Promise.all(
|
||||||
|
Array.from(buddyMap.values()).map(async (buddyInfo) => {
|
||||||
|
try {
|
||||||
|
const userDetail = await this.core.apis.UserApi.getUserDetailInfo(buddyInfo.coreInfo.uid);
|
||||||
|
const data = buddyMap.get(buddyInfo.coreInfo.uid);
|
||||||
|
if (data) {
|
||||||
|
data.qqLevel = userDetail.qqLevel;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.core.context.logger.logError('获取好友详细信息失败', error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return OB11Construct.friends(Array.from(buddyMap.values()));
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -20,16 +20,36 @@ export class OB11Construct {
|
|||||||
|
|
||||||
static friends(friends: FriendV2[]): OB11User[] {
|
static friends(friends: FriendV2[]): OB11User[] {
|
||||||
return friends.map(rawFriend => ({
|
return friends.map(rawFriend => ({
|
||||||
...rawFriend.baseInfo,
|
birthday_year: rawFriend.baseInfo.birthday_year,
|
||||||
...rawFriend.coreInfo,
|
birthday_month: rawFriend.baseInfo.birthday_month,
|
||||||
|
birthday_day: rawFriend.baseInfo.birthday_day,
|
||||||
user_id: parseInt(rawFriend.coreInfo.uin),
|
user_id: parseInt(rawFriend.coreInfo.uin),
|
||||||
|
age: rawFriend.baseInfo.age,
|
||||||
|
phone_num: rawFriend.baseInfo.phoneNum,
|
||||||
|
email: rawFriend.baseInfo.eMail,
|
||||||
|
category_id: rawFriend.baseInfo.categoryId,
|
||||||
nickname: rawFriend.coreInfo.nick ?? '',
|
nickname: rawFriend.coreInfo.nick ?? '',
|
||||||
remark: rawFriend.coreInfo.remark ?? rawFriend.coreInfo.nick,
|
remark: rawFriend.coreInfo.remark ?? rawFriend.coreInfo.nick,
|
||||||
sex: this.sex(rawFriend.baseInfo.sex),
|
sex: this.sex(rawFriend.baseInfo.sex),
|
||||||
level: 0,
|
level: rawFriend.qqLevel && calcQQLevel(rawFriend.qqLevel) || 0,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
static friend(friends: FriendV2): OB11User {
|
||||||
|
return {
|
||||||
|
birthday_year: friends.baseInfo.birthday_year,
|
||||||
|
birthday_month: friends.baseInfo.birthday_month,
|
||||||
|
birthday_day: friends.baseInfo.birthday_day,
|
||||||
|
user_id: parseInt(friends.coreInfo.uin),
|
||||||
|
age: friends.baseInfo.age,
|
||||||
|
phone_num: friends.baseInfo.phoneNum,
|
||||||
|
email: friends.baseInfo.eMail,
|
||||||
|
category_id: friends.baseInfo.categoryId,
|
||||||
|
nickname: friends.coreInfo.nick ?? '',
|
||||||
|
remark: friends.coreInfo.remark ?? friends.coreInfo.nick,
|
||||||
|
sex: this.sex(friends.baseInfo.sex),
|
||||||
|
level: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
static groupMemberRole(role: number): OB11GroupMemberRole | undefined {
|
static groupMemberRole(role: number): OB11GroupMemberRole | undefined {
|
||||||
return {
|
return {
|
||||||
4: OB11GroupMemberRole.owner,
|
4: OB11GroupMemberRole.owner,
|
||||||
|
@@ -1,4 +1,10 @@
|
|||||||
export interface OB11User {
|
export interface OB11User {
|
||||||
|
birthday_year?: number; // 生日
|
||||||
|
birthday_month?: number; // 生日
|
||||||
|
birthday_day?: number; // 生日
|
||||||
|
phone_num?: string; // 手机号
|
||||||
|
email?: string; // 邮箱
|
||||||
|
category_id?: number; // 分组ID
|
||||||
user_id: number; // 用户ID
|
user_id: number; // 用户ID
|
||||||
nickname: string; // 昵称
|
nickname: string; // 昵称
|
||||||
remark?: string; // 备注
|
remark?: string; // 备注
|
||||||
|
Reference in New Issue
Block a user