Compare commits

..

18 Commits

Author SHA1 Message Date
手瓜一十雪
914136b750 refactor: 移除异常代码 2024-07-10 21:39:03 +08:00
手瓜一十雪
f9a60795f5 feat: uid转换优化 2024-07-10 21:33:31 +08:00
手瓜一十雪
19640927c7 Merge branch 'main' of https://github.com/NapNeko/NapCatQQ 2024-07-10 21:11:43 +08:00
手瓜一十雪
22faac7e36 fix: friend uid 异常 2024-07-10 21:11:28 +08:00
手瓜一十雪
30d260ab32 Merge pull request #111 from idranme/main
fix: error catch
2024-07-10 11:55:53 +08:00
idranme
115120d066 Update file.ts 2024-07-10 11:35:55 +08:00
idranme
1327844736 fix: error catch 2024-07-10 03:25:25 +00:00
手瓜一十雪
29904f3cb7 feat: 164 way03启动脚本补充 2024-07-06 13:23:31 +08:00
手瓜一十雪
50395594b7 Merge pull request #106 from jetjinser/fix-editorconfig
fix: `.editorconfig` wrong pair `end_of_line`
2024-07-05 22:43:23 +08:00
Jinser Kafka
9360af88b3 fix: .editorconfig 2024-07-05 19:36:32 +08:00
手瓜一十雪
376370336c release: 1.6.5 2024-07-05 16:50:57 +08:00
手瓜一十雪
70df6e3302 Merge pull request #105 from po-lan/main
对缓存小优化
2024-07-05 16:49:30 +08:00
手瓜一十雪
0a1fc2dc12 feat: 1.6.5 2024-07-05 16:49:16 +08:00
手瓜一十雪
9857f6e437 feat: 优化载入流程 2024-07-05 16:47:08 +08:00
手瓜一十雪
56d6ebe916 refactor: 迁移到新库 2024-07-05 15:48:03 +08:00
po-lan
81134ea2d4 Update LRUCache.ts 2024-07-05 12:13:24 +08:00
po-lan
a9f3e7fc54 Update db.ts
通过读取缓存修复刚说话缺无法获取发言时间的问题
2024-07-05 12:12:40 +08:00
po-lan
eb84e2f8c9 Update LRUCache.ts
Add a get function to the cache
2024-07-05 12:09:59 +08:00
20 changed files with 134 additions and 76 deletions

View File

@@ -5,7 +5,7 @@ root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf|crlf
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation

View File

@@ -0,0 +1,18 @@
# v1.6.5
QQ Version: Windows 9.9.12-26000 / Linux 3.2.9-26000
## 使用前警告
1. 在最近版本由于QQ本体大幅变动为了保证NapCat可用性NapCat近期启动与安装方式将将大幅变动请关注文档和社群获取。
2. 在Core上完全执行开源请不要用于违法用途如此可能造成NapCat完全停止更新。
3. 针对原启动方式的围堵NapCat研发了多种方式除此其余理论与扩展的分析和思路将部分展示于Docs以便各位参与开发与维护NapCat。
## 其余·备注
启动方式: WayBoot.03 Electron Main进程为Node 直接注入代码 同理项目: LiteLoader
## 修复与优化
1. 优化了WrapperNative载入代码
2. 优化缓存
## 新增与调整
没有哦
新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)

View File

@@ -2,7 +2,7 @@
"name": "napcat",
"private": true,
"type": "module",
"version": "1.6.4",
"version": "1.6.5",
"scripts": {
"watch:dev": "vite --mode development",
"watch:prod": "vite --mode production",

28
script/NapCat.164.bat Normal file
View File

@@ -0,0 +1,28 @@
@echo off
chcp 65001
:: 检查是否有管理员权限
net session >nul 2>&1
if %errorlevel% neq 0 (
echo 请求管理员权限...
powershell -Command "Start-Process '%~f0' -Verb runAs"
exit /b
)
:: 如果有管理员权限,继续执行
setlocal enabledelayedexpansion
:loop_read
for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" /v "UninstallString"') do (
set "RetString=%%b"
goto :napcat_boot
)
:napcat_boot
for %%a in ("!RetString!") do (
set "pathWithoutUninstall=%%~dpa"
)
set "QQPath=!pathWithoutUninstall!QQ.exe"
echo !QQPath!
"!QQPath!" --enable-logging %*
pause

View File

@@ -1,4 +1,3 @@
import { NodeIKernelMsgListener } from '@/core';
import { NodeIQQNTWrapperSession } from '@/core/wrapper';
import { randomUUID } from 'crypto';

View File

@@ -1,4 +1,4 @@
import { logError, logDebug } from '@/common/utils/log';
import { logError, logDebug } from "@/common/utils/log";
type group_id = number;
type user_id = number;
@@ -31,7 +31,7 @@ class LRU<T> {
private tail: cacheNode<T> | null = null;
private onFuncs: ((node: cacheNode<T>) => void)[] = [];
constructor(maxAge: number = 2e4, maxSize: number = 5e3) {
constructor(maxAge: number = 6e4, maxSize: number = 5e3) {
this.maxAge = maxAge;
this.maxSize = maxSize;
this.cache = Object.create(null);
@@ -44,7 +44,7 @@ class LRU<T> {
// 移除LRU节点
private removeLRUNode(node: cacheNode<T>) {
logDebug(
'removeLRUNode',
"removeLRUNode",
node.groupId,
node.userId,
node.value,
@@ -140,6 +140,26 @@ class LRU<T> {
}
}
}
public get(groupId: group_id): { userId: user_id; value: T }[];
public get(groupId: group_id, userId: user_id): null | { userId: user_id; value: T };
public get(groupId: group_id, userId?: user_id): any {
const groupObject = this.cache[groupId];
if(!groupObject) return userId === undefined ? [] : null;
if (userId === undefined) {
return Object.entries(groupObject).map(([userId, { value }]) => ({
userId: Number(userId),
value,
}));
}
if (groupObject[userId]) {
return { userId, value: groupObject[userId].value };
}
return null;
}
}
export default LRU;

View File

@@ -408,10 +408,12 @@ class DBUtil extends DBUtilBase {
logDebug('读取发言时间', groupId);
return new Promise<IRember[]>((resolve, reject) => {
this.db!.all(`SELECT * FROM "${groupId}" `, (err, rows: IRember[]) => {
const cache = this.LURCache.get(groupId).map(e=>({user_id:e.userId, last_sent_time:e.value}));
if (err) {
logError('查询发言时间失败', groupId);
return resolve([]);
return resolve(cache.map(e=>({...e, join_time:0})));
}
Object.assign(rows, cache)
logDebug('查询发言时间成功', groupId, rows);
resolve(rows);
});

View File

@@ -160,7 +160,12 @@ export async function httpDownload(options: string | HttpDownloadOptions): Promi
}
}
}
const fetchRes = await fetch(url, { headers });
const fetchRes = await fetch(url, { headers }).catch((err) => {
if (err.cause) {
throw err.cause;
}
throw err;
});
if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`);
const blob = await fetchRes.blob();

View File

@@ -1,7 +1,7 @@
import { ModifyProfileParams, SelfInfo, User, UserDetailInfoByUin } from '@/core/entities';
import { selfInfo } from '@/core/data';
import { friends, selfInfo } from '@/core/data';
import { CacheClassFuncAsync } from '@/common/utils/helper';
import { GeneralCallResult, napCatCore } from '@/core';
import { GeneralCallResult, napCatCore, NTQQFriendApi } from '@/core';
import { ProfileListener } from '@/core/listeners';
import { rejects } from 'assert';
import { randomUUID } from 'crypto';
@@ -170,7 +170,30 @@ export class NTQQUserApi {
5000,
[Uin]
);
return ret.uidInfo.get(Uin);
let uid = ret.uidInfo.get(Uin); //通过QQ默认方式转换
if (!uid) {
Array.from(friends.values()).forEach((t) => {
if (t.uin == Uin) {
//logDebug('getUidByUin', t.uid, t.uin, Uin);
uid = t.uid;
}
//console.log(t.uid, t.uin, Uin);
});
//uid = Array.from(friends.values()).find((t) => { t.uin == Uin })?.uid; // 从NC维护的QQ Buddy缓存 转换
}
if (!uid) {
uid = (await NTQQFriendApi.getFriends(false)).find((t) => { t.uin == Uin })?.uid; //从QQ Native 缓存转换 方法一
}
if (!uid) {
uid = (await NTQQFriendApi.getFriends(true)).find((t) => { t.uin == Uin })?.uid; //从QQ Native 非缓存转换 方法二
}
if (!uid) {
let unveifyUid = (await NTQQUserApi.getUserDetailInfoByUin(Uin)).info.uid;//从QQ Native 特殊转换 方法三
if (unveifyUid.indexOf("*") == -1) {
uid = unveifyUid;
}
}
return uid;
}
static async getUinByUid(Uid: string | undefined) {
if (!Uid) {

View File

@@ -286,11 +286,7 @@ let wrapperNodePath = path.resolve(path.dirname(process.execPath), './resources/
if (!fs.existsSync(wrapperNodePath)) {
wrapperNodePath = path.join(path.dirname(process.execPath), `resources/app/versions/${qqVersionConfigInfo.curVersion}/wrapper.node`);
}
let WrapperLoader = path.join(__dirname, "WrapperLoader.cjs");
//此处待优化
fs.writeFileSync(WrapperLoader, `
module.exports = require("${wrapperNodePath.replace(/\\/g, "\\\\")}");
exports = module.exports;
`)
const QQWrapper: WrapperNodeApi = (await import("file://" + WrapperLoader)).default;
const nativemodule: any = { exports: {} };
process.dlopen(nativemodule, wrapperNodePath);
const QQWrapper: WrapperNodeApi = nativemodule.exports;
export default QQWrapper;

View File

@@ -1,2 +0,0 @@
//统一到处入口
export * from './main';

View File

@@ -1,29 +0,0 @@
enum NapCatCorePlatform {
Node = 'Node',//命令行模式加载
LiteLoader = 'LiteLoader',//LL插件模式加载
}
class NewNapCatCore {
platform: NapCatCorePlatform; // 平台
constructor(platform: NapCatCorePlatform) {
this.platform = platform;
}
}
export class NapCatCoreManger {
static core: NewNapCatCore | undefined = undefined;
static defaultPlatform: NapCatCorePlatform = NapCatCorePlatform.Node;
static SetDefaultCore(platform: NapCatCorePlatform) {
if (this.core !== undefined) {
return;
}
this.defaultPlatform = platform;
}
static GetPlatform(): NapCatCorePlatform {
return NapCatCoreManger.defaultPlatform;
}
static GetInstance(): NewNapCatCore {
if (this.core === undefined) {
this.core = new NewNapCatCore(NapCatCoreManger.defaultPlatform);
}
return this.core;
}
}

View File

@@ -1 +0,0 @@
//拦截proxy到会话

View File

@@ -1 +0,0 @@
//初始化跟之前一样

View File

@@ -1 +0,0 @@
//proxy封装工具类

View File

@@ -102,6 +102,7 @@ async function createContext(payload: OB11PostSendMsg, contextMode: ContextMode)
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
const Uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
return {
peer: {
chatType: isBuddy ? ChatType.friend : ChatType.temp,

View File

@@ -1 +1 @@
export const version = '1.6.4';
export const version = '1.6.5';

View File

@@ -29,7 +29,7 @@ async function onSettingWindowCreated(view: Element) {
SettingItem(
'<span id="napcat-update-title">Napcat</span>',
undefined,
SettingButton('V1.6.4', 'napcat-update-button', 'secondary')
SettingButton('V1.6.5', 'napcat-update-button', 'secondary')
),
]),
SettingList([

View File

@@ -167,7 +167,7 @@ async function onSettingWindowCreated(view) {
SettingItem(
'<span id="napcat-update-title">Napcat</span>',
void 0,
SettingButton("V1.6.4", "napcat-update-button", "secondary")
SettingButton("V1.6.5", "napcat-update-button", "secondary")
)
]),
SettingList([