mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
58 Commits
refactor-u
...
v4.7.19
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a5e53a713b | ||
![]() |
e3f965a9d6 | ||
![]() |
dd00d4c8a5 | ||
![]() |
4d292a75fa | ||
![]() |
50b6733f57 | ||
![]() |
19479b4b3c | ||
![]() |
540f58d8ec | ||
![]() |
749f1dfcf9 | ||
![]() |
176691bb96 | ||
![]() |
b9ec8ac9b1 | ||
![]() |
28d973b9cb | ||
![]() |
a6be54937c | ||
![]() |
0664b9af84 | ||
![]() |
407d8d1fd2 | ||
![]() |
108897f6ad | ||
![]() |
3d2decb0ec | ||
![]() |
386b884f1b | ||
![]() |
ace4da2297 | ||
![]() |
a8fb48fb50 | ||
![]() |
61f065c0c6 | ||
![]() |
d6cf6d120a | ||
![]() |
c20c19d8e0 | ||
![]() |
bd8bbf76ab | ||
![]() |
faccff1834 | ||
![]() |
99d3c5a117 | ||
![]() |
31eb09edef | ||
![]() |
4180c2d754 | ||
![]() |
68f5deedff | ||
![]() |
9f72196414 | ||
![]() |
b32efa9131 | ||
![]() |
3cf502fea3 | ||
![]() |
863a953ae1 | ||
![]() |
a44104d8f7 | ||
![]() |
f602bbb0cf | ||
![]() |
2807ff5927 | ||
![]() |
4fb8e6a4da | ||
![]() |
7ec61f089d | ||
![]() |
f7a500a8cf | ||
![]() |
2b319bd694 | ||
![]() |
24cf7c01f8 | ||
![]() |
aa50e73909 | ||
![]() |
d9b33b5439 | ||
![]() |
da58c6bec0 | ||
![]() |
c4cbac4331 | ||
![]() |
ac26a99143 | ||
![]() |
640252d391 | ||
![]() |
258a1dda5e | ||
![]() |
53a7ce2e46 | ||
![]() |
291e2fd8fd | ||
![]() |
f180c7698f | ||
![]() |
183d6f3011 | ||
![]() |
ba71d7ad03 | ||
![]() |
26cfaac3bd | ||
![]() |
556c8b24c0 | ||
![]() |
31f0f527b7 | ||
![]() |
b2e0cab702 | ||
![]() |
3e3609e0f2 | ||
![]() |
83e73d9842 |
@@ -37,7 +37,7 @@ _Modern protocol-side framework implemented based on NTQQ._
|
|||||||
| Docs | [](https://napneko.github.io/) | [](https://doc.napneko.icu/) | [](https://napcat.napneko.icu/) |
|
| Docs | [](https://napneko.github.io/) | [](https://doc.napneko.icu/) | [](https://napcat.napneko.icu/) |
|
||||||
|:-:|:-:|:-:|:-:|
|
|:-:|:-:|:-:|:-:|
|
||||||
|
|
||||||
| Docs | [](https://napneko.pages.dev/) | [](https://docs.napcat.cyou/) | [](https://www.napcat.wiki) |
|
| Docs | [](https://napneko.pages.dev/) | [](https://napcat.cyou/) | [](https://www.napcat.wiki) |
|
||||||
|:-:|:-:|:-:|:-:|
|
|:-:|:-:|:-:|:-:|
|
||||||
|
|
||||||
| Contact | [](https://qm.qq.com/q/I6LU87a0Yq) | [](https://qm.qq.com/q/HaRcfrHpUk) | [](https://t.me/MelodicMoonlight) |
|
| Contact | [](https://qm.qq.com/q/I6LU87a0Yq) | [](https://qm.qq.com/q/HaRcfrHpUk) | [](https://t.me/MelodicMoonlight) |
|
||||||
|
BIN
external/LiteLoaderWrapper.zip
vendored
BIN
external/LiteLoaderWrapper.zip
vendored
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "qq-chat",
|
"name": "qq-chat",
|
||||||
"version": "9.9.18-32793",
|
"version": "9.9.18-32869",
|
||||||
"verHash": "d43f097e",
|
"verHash": "e735296c",
|
||||||
"linuxVersion": "3.2.16-32793",
|
"linuxVersion": "3.2.16-32869",
|
||||||
"linuxVerHash": "ee4bd910",
|
"linuxVerHash": "4c192ba9",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "QQ",
|
"description": "QQ",
|
||||||
"productName": "QQ",
|
"productName": "QQ",
|
||||||
@@ -34,9 +34,9 @@
|
|||||||
"vuex@4.1.0": "patches/vuex@4.1.0.patch"
|
"vuex@4.1.0": "patches/vuex@4.1.0.patch"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buildVersion": "32793",
|
"buildVersion": "32869",
|
||||||
"isPureShell": true,
|
"isPureShell": true,
|
||||||
"isByteCodeShell": true,
|
"isByteCodeShell": true,
|
||||||
"platform": "win32",
|
"platform": "win32",
|
||||||
"eleArch": "x64"
|
"eleArch": "x64"
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.7.8",
|
"version": "4.7.18",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -79,6 +79,7 @@ export default function WebLoginPage() {
|
|||||||
<CardBody className="flex gap-5 py-5 px-5 md:px-10">
|
<CardBody className="flex gap-5 py-5 px-5 md:px-10">
|
||||||
<Input
|
<Input
|
||||||
isClearable
|
isClearable
|
||||||
|
type="password"
|
||||||
classNames={{
|
classNames={{
|
||||||
label: 'text-black/50 dark:text-white/90',
|
label: 'text-black/50 dark:text-white/90',
|
||||||
input: [
|
input: [
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.7.8",
|
"version": "4.7.18",
|
||||||
"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",
|
||||||
@@ -57,9 +57,9 @@
|
|||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"typescript-eslint": "^8.13.0",
|
"typescript-eslint": "^8.13.0",
|
||||||
"vite": "^6.0.1",
|
"vite": "^6.0.1",
|
||||||
"vite-plugin-cp": "^4.0.8",
|
"vite-plugin-cp": "^6.0.0",
|
||||||
"vite-tsconfig-paths": "^5.1.0",
|
"vite-tsconfig-paths": "^5.1.0",
|
||||||
"napcat.protobuf": "^1.1.3",
|
"napcat.protobuf": "^1.1.4",
|
||||||
"winston": "^3.17.0",
|
"winston": "^3.17.0",
|
||||||
"compressing": "^1.10.1"
|
"compressing": "^1.10.1"
|
||||||
},
|
},
|
||||||
|
229
src/common/clean-task.ts
Normal file
229
src/common/clean-task.ts
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
// generate Claude 3.7 Sonet Thinking
|
||||||
|
|
||||||
|
interface FileRecord {
|
||||||
|
filePath: string;
|
||||||
|
addedTime: number;
|
||||||
|
retries: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CleanupTask {
|
||||||
|
fileRecord: FileRecord;
|
||||||
|
timer: NodeJS.Timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CleanupQueue {
|
||||||
|
private tasks: Map<string, CleanupTask> = new Map();
|
||||||
|
private readonly MAX_RETRIES = 3;
|
||||||
|
private isProcessing: boolean = false;
|
||||||
|
private pendingOperations: Array<() => void> = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行队列中的待处理操作,确保异步安全
|
||||||
|
*/
|
||||||
|
private executeNextOperation(): void {
|
||||||
|
if (this.pendingOperations.length === 0) {
|
||||||
|
this.isProcessing = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isProcessing = true;
|
||||||
|
const operation = this.pendingOperations.shift();
|
||||||
|
operation?.();
|
||||||
|
|
||||||
|
// 使用 setImmediate 允许事件循环继续,防止阻塞
|
||||||
|
setImmediate(() => this.executeNextOperation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全执行操作,防止竞态条件
|
||||||
|
* @param operation 要执行的操作
|
||||||
|
*/
|
||||||
|
private safeExecute(operation: () => void): void {
|
||||||
|
this.pendingOperations.push(operation);
|
||||||
|
if (!this.isProcessing) {
|
||||||
|
this.executeNextOperation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查文件是否存在
|
||||||
|
* @param filePath 文件路径
|
||||||
|
* @returns 文件是否存在
|
||||||
|
*/
|
||||||
|
private fileExists(filePath: string): boolean {
|
||||||
|
try {
|
||||||
|
return fs.existsSync(filePath);
|
||||||
|
} catch (error) {
|
||||||
|
//console.log(`检查文件存在出错: ${filePath}`, error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加文件到清理队列
|
||||||
|
* @param filePath 文件路径
|
||||||
|
* @param cleanupDelay 清理延迟时间(毫秒)
|
||||||
|
*/
|
||||||
|
addFile(filePath: string, cleanupDelay: number): void {
|
||||||
|
this.safeExecute(() => {
|
||||||
|
// 如果文件已在队列中,取消原来的计时器
|
||||||
|
if (this.tasks.has(filePath)) {
|
||||||
|
this.cancelCleanup(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新的文件记录
|
||||||
|
const fileRecord: FileRecord = {
|
||||||
|
filePath,
|
||||||
|
addedTime: Date.now(),
|
||||||
|
retries: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置计时器
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
this.cleanupFile(fileRecord, cleanupDelay);
|
||||||
|
}, cleanupDelay);
|
||||||
|
|
||||||
|
// 添加到任务队列
|
||||||
|
this.tasks.set(filePath, { fileRecord, timer });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量添加文件到清理队列
|
||||||
|
* @param filePaths 文件路径数组
|
||||||
|
* @param cleanupDelay 清理延迟时间(毫秒)
|
||||||
|
*/
|
||||||
|
addFiles(filePaths: string[], cleanupDelay: number): void {
|
||||||
|
this.safeExecute(() => {
|
||||||
|
for (const filePath of filePaths) {
|
||||||
|
// 内部直接处理,不通过 safeExecute 以保证批量操作的原子性
|
||||||
|
if (this.tasks.has(filePath)) {
|
||||||
|
// 取消已有的计时器,但不使用 cancelCleanup 方法以避免重复的安全检查
|
||||||
|
const existingTask = this.tasks.get(filePath);
|
||||||
|
if (existingTask) {
|
||||||
|
clearTimeout(existingTask.timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileRecord: FileRecord = {
|
||||||
|
filePath,
|
||||||
|
addedTime: Date.now(),
|
||||||
|
retries: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
this.cleanupFile(fileRecord, cleanupDelay);
|
||||||
|
}, cleanupDelay);
|
||||||
|
|
||||||
|
this.tasks.set(filePath, { fileRecord, timer });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理文件
|
||||||
|
* @param record 文件记录
|
||||||
|
* @param delay 延迟时间,用于重试
|
||||||
|
*/
|
||||||
|
private cleanupFile(record: FileRecord, delay: number): void {
|
||||||
|
this.safeExecute(() => {
|
||||||
|
// 首先检查文件是否存在,不存在则视为清理成功
|
||||||
|
if (!this.fileExists(record.filePath)) {
|
||||||
|
//console.log(`文件已不存在,跳过清理: ${record.filePath}`);
|
||||||
|
this.tasks.delete(record.filePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 尝试删除文件
|
||||||
|
fs.unlinkSync(record.filePath);
|
||||||
|
// 删除成功,从队列中移除任务
|
||||||
|
this.tasks.delete(record.filePath);
|
||||||
|
} catch (error) {
|
||||||
|
const err = error as NodeJS.ErrnoException;
|
||||||
|
|
||||||
|
// 明确处理文件不存在的情况
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
//console.log(`文件在删除时不存在,视为清理成功: ${record.filePath}`);
|
||||||
|
this.tasks.delete(record.filePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件没有访问权限等情况
|
||||||
|
if (err.code === 'EACCES' || err.code === 'EPERM') {
|
||||||
|
//console.error(`没有权限删除文件: ${record.filePath}`, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他删除失败情况,考虑重试
|
||||||
|
if (record.retries < this.MAX_RETRIES - 1) {
|
||||||
|
// 还有重试机会,增加重试次数
|
||||||
|
record.retries++;
|
||||||
|
//console.log(`清理文件失败,将重试(${record.retries}/${this.MAX_RETRIES}): ${record.filePath}`);
|
||||||
|
|
||||||
|
// 设置相同的延迟时间再次尝试
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
this.cleanupFile(record, delay);
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
// 更新任务
|
||||||
|
this.tasks.set(record.filePath, { fileRecord: record, timer });
|
||||||
|
} else {
|
||||||
|
// 已达到最大重试次数,从队列中移除任务
|
||||||
|
this.tasks.delete(record.filePath);
|
||||||
|
//console.error(`清理文件失败,已达最大重试次数(${this.MAX_RETRIES}): ${record.filePath}`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消文件的清理任务
|
||||||
|
* @param filePath 文件路径
|
||||||
|
* @returns 是否成功取消
|
||||||
|
*/
|
||||||
|
cancelCleanup(filePath: string): boolean {
|
||||||
|
let cancelled = false;
|
||||||
|
this.safeExecute(() => {
|
||||||
|
const task = this.tasks.get(filePath);
|
||||||
|
if (task) {
|
||||||
|
clearTimeout(task.timer);
|
||||||
|
this.tasks.delete(filePath);
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取队列中的文件数量
|
||||||
|
* @returns 文件数量
|
||||||
|
*/
|
||||||
|
getQueueSize(): number {
|
||||||
|
return this.tasks.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有待清理的文件
|
||||||
|
* @returns 文件路径数组
|
||||||
|
*/
|
||||||
|
getPendingFiles(): string[] {
|
||||||
|
return Array.from(this.tasks.keys());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空所有清理任务
|
||||||
|
*/
|
||||||
|
clearAll(): void {
|
||||||
|
this.safeExecute(() => {
|
||||||
|
// 取消所有定时器
|
||||||
|
for (const task of this.tasks.values()) {
|
||||||
|
clearTimeout(task.timer);
|
||||||
|
}
|
||||||
|
this.tasks.clear();
|
||||||
|
//console.log('已清空所有清理任务');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const cleanTaskQueue = new CleanupQueue();
|
@@ -16,6 +16,9 @@ export function recvTask<T>(cb: (taskData: T) => Promise<unknown>) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export function sendLog(_log: string) {
|
||||||
|
//parentPort?.postMessage({ log });
|
||||||
|
}
|
||||||
class FFmpegService {
|
class FFmpegService {
|
||||||
public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise<void> {
|
public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise<void> {
|
||||||
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
||||||
@@ -107,35 +110,175 @@ class FFmpegService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
||||||
await FFmpegService.extractThumbnail(videoPath, thumbnailPath);
|
const startTime = Date.now();
|
||||||
const fileType = (await fileTypeFromFile(videoPath))?.ext ?? 'mp4';
|
sendLog(`开始获取视频信息: ${videoPath}`);
|
||||||
const inputFileName = `${randomUUID()}.${fileType}`;
|
|
||||||
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
// 创建一个超时包装函数
|
||||||
ffmpegInstance.fs.writeFile(inputFileName, readFileSync(videoPath));
|
const withTimeout = <T>(promise: Promise<T>, timeoutMs: number, taskName: string): Promise<T> => {
|
||||||
ffmpegInstance.setLogging(true);
|
return Promise.race([
|
||||||
let duration = 60;
|
promise,
|
||||||
ffmpegInstance.setLogger((_level, ...msg) => {
|
new Promise<T>((_, reject) => {
|
||||||
const message = msg.join(' ');
|
setTimeout(() => reject(new Error(`任务超时: ${taskName} (${timeoutMs}ms)`)), timeoutMs);
|
||||||
const durationMatch = message.match(/Duration: (\d+):(\d+):(\d+\.\d+)/);
|
})
|
||||||
if (durationMatch) {
|
]);
|
||||||
const hours = parseInt(durationMatch[1] ?? '0', 10);
|
};
|
||||||
const minutes = parseInt(durationMatch[2] ?? '0', 10);
|
|
||||||
const seconds = parseFloat(durationMatch[3] ?? '0');
|
// 并行执行多个任务
|
||||||
duration = hours * 3600 + minutes * 60 + seconds;
|
const [fileInfo, durationInfo] = await Promise.all([
|
||||||
}
|
// 任务1: 获取文件信息和提取缩略图
|
||||||
});
|
(async () => {
|
||||||
await ffmpegInstance.run('-i', inputFileName);
|
sendLog(`开始任务1: 获取文件信息和提取缩略图`);
|
||||||
const image = imageSize(thumbnailPath);
|
|
||||||
ffmpegInstance.fs.unlink(inputFileName);
|
// 获取文件信息 (并行)
|
||||||
const fileSize = statSync(videoPath).size;
|
const fileInfoStartTime = Date.now();
|
||||||
|
const [fileType, fileSize] = await Promise.all([
|
||||||
|
withTimeout(fileTypeFromFile(videoPath), 10000, '获取文件类型')
|
||||||
|
.then(result => {
|
||||||
|
sendLog(`获取文件类型完成,耗时: ${Date.now() - fileInfoStartTime}ms`);
|
||||||
|
return result;
|
||||||
|
}),
|
||||||
|
(async () => {
|
||||||
|
const result = statSync(videoPath).size;
|
||||||
|
sendLog(`获取文件大小完成,耗时: ${Date.now() - fileInfoStartTime}ms`);
|
||||||
|
return result;
|
||||||
|
})()
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 直接实现缩略图提取 (不调用extractThumbnail方法)
|
||||||
|
const thumbStartTime = Date.now();
|
||||||
|
sendLog(`开始提取缩略图`);
|
||||||
|
|
||||||
|
const ffmpegInstance = await withTimeout(
|
||||||
|
FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }),
|
||||||
|
15000,
|
||||||
|
'创建FFmpeg实例(缩略图)'
|
||||||
|
);
|
||||||
|
|
||||||
|
const videoFileName = `${randomUUID()}.mp4`;
|
||||||
|
const outputFileName = `${randomUUID()}.jpg`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 写入视频文件到FFmpeg
|
||||||
|
const writeFileStartTime = Date.now();
|
||||||
|
ffmpegInstance.fs.writeFile(videoFileName, readFileSync(videoPath));
|
||||||
|
sendLog(`写入视频文件到FFmpeg完成,耗时: ${Date.now() - writeFileStartTime}ms`);
|
||||||
|
|
||||||
|
// 提取缩略图
|
||||||
|
const extractStartTime = Date.now();
|
||||||
|
const code = await withTimeout(
|
||||||
|
ffmpegInstance.run('-i', videoFileName, '-ss', '00:00:01.000', '-vframes', '1', outputFileName),
|
||||||
|
30000,
|
||||||
|
'提取缩略图'
|
||||||
|
);
|
||||||
|
sendLog(`FFmpeg提取缩略图命令执行完成,耗时: ${Date.now() - extractStartTime}ms`);
|
||||||
|
|
||||||
|
if (code !== 0) {
|
||||||
|
throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取并保存缩略图
|
||||||
|
const saveStartTime = Date.now();
|
||||||
|
const thumbnail = ffmpegInstance.fs.readFile(outputFileName);
|
||||||
|
writeFileSync(thumbnailPath, thumbnail);
|
||||||
|
sendLog(`读取并保存缩略图完成,耗时: ${Date.now() - saveStartTime}ms`);
|
||||||
|
|
||||||
|
// 获取缩略图尺寸
|
||||||
|
const imageSizeStartTime = Date.now();
|
||||||
|
const image = imageSize(thumbnailPath);
|
||||||
|
sendLog(`获取缩略图尺寸完成,耗时: ${Date.now() - imageSizeStartTime}ms`);
|
||||||
|
|
||||||
|
sendLog(`提取缩略图完成,总耗时: ${Date.now() - thumbStartTime}ms`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
format: fileType?.ext ?? 'mp4',
|
||||||
|
size: fileSize,
|
||||||
|
width: image.width ?? 100,
|
||||||
|
height: image.height ?? 100
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
// 清理资源
|
||||||
|
try {
|
||||||
|
ffmpegInstance.fs.unlink(outputFileName);
|
||||||
|
} catch (error) {
|
||||||
|
sendLog(`清理输出文件失败: ${(error as Error).message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ffmpegInstance.fs.unlink(videoFileName);
|
||||||
|
} catch (error) {
|
||||||
|
sendLog(`清理视频文件失败: ${(error as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(),
|
||||||
|
|
||||||
|
// 任务2: 获取视频时长
|
||||||
|
(async () => {
|
||||||
|
const task2StartTime = Date.now();
|
||||||
|
sendLog(`开始任务2: 获取视频时长`);
|
||||||
|
|
||||||
|
// 创建FFmpeg实例
|
||||||
|
const ffmpegCreateStartTime = Date.now();
|
||||||
|
const ffmpegInstance = await withTimeout(
|
||||||
|
FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }),
|
||||||
|
15000,
|
||||||
|
'创建FFmpeg实例(时长)'
|
||||||
|
);
|
||||||
|
sendLog(`创建FFmpeg实例完成,耗时: ${Date.now() - ffmpegCreateStartTime}ms`);
|
||||||
|
|
||||||
|
const inputFileName = `${randomUUID()}.mp4`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 写入文件
|
||||||
|
const writeStartTime = Date.now();
|
||||||
|
ffmpegInstance.fs.writeFile(inputFileName, readFileSync(videoPath));
|
||||||
|
sendLog(`写入文件到FFmpeg完成,耗时: ${Date.now() - writeStartTime}ms`);
|
||||||
|
|
||||||
|
ffmpegInstance.setLogging(true);
|
||||||
|
let duration = 60; // 默认值
|
||||||
|
|
||||||
|
ffmpegInstance.setLogger((_level, ...msg) => {
|
||||||
|
const message = msg.join(' ');
|
||||||
|
const durationMatch = message.match(/Duration: (\d+):(\d+):(\d+\.\d+)/);
|
||||||
|
if (durationMatch) {
|
||||||
|
const hours = parseInt(durationMatch[1] ?? '0', 10);
|
||||||
|
const minutes = parseInt(durationMatch[2] ?? '0', 10);
|
||||||
|
const seconds = parseFloat(durationMatch[3] ?? '0');
|
||||||
|
duration = hours * 3600 + minutes * 60 + seconds;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 执行FFmpeg
|
||||||
|
const runStartTime = Date.now();
|
||||||
|
await withTimeout(
|
||||||
|
ffmpegInstance.run('-i', inputFileName),
|
||||||
|
20000,
|
||||||
|
'获取视频时长'
|
||||||
|
);
|
||||||
|
sendLog(`执行FFmpeg命令完成,耗时: ${Date.now() - runStartTime}ms`);
|
||||||
|
|
||||||
|
sendLog(`任务2(获取视频时长)完成,总耗时: ${Date.now() - task2StartTime}ms`);
|
||||||
|
return { time: duration };
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
ffmpegInstance.fs.unlink(inputFileName);
|
||||||
|
} catch (error) {
|
||||||
|
sendLog(`清理输入文件失败: ${(error as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 合并结果并返回
|
||||||
|
const totalDuration = Date.now() - startTime;
|
||||||
|
sendLog(`获取视频信息完成,总耗时: ${totalDuration}ms`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
width: image.width ?? 100,
|
width: fileInfo.width,
|
||||||
height: image.height ?? 100,
|
height: fileInfo.height,
|
||||||
time: duration,
|
time: durationInfo.time,
|
||||||
format: fileType,
|
format: fileInfo.format,
|
||||||
size: fileSize,
|
size: fileInfo.size,
|
||||||
filePath: videoPath
|
filePath: videoPath
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ export class FFmpegService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
||||||
const result = await await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'getVideoInfo', args: [videoPath, thumbnailPath] });
|
const result = await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'getVideoInfo', args: [videoPath, thumbnailPath] });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ export function calculateFileMD5(filePath: string): Promise<string> {
|
|||||||
const stream = fs.createReadStream(filePath);
|
const stream = fs.createReadStream(filePath);
|
||||||
const hash = crypto.createHash('md5');
|
const hash = crypto.createHash('md5');
|
||||||
|
|
||||||
stream.on('data', (data: Buffer) => {
|
stream.on('data', (data) => {
|
||||||
// 当读取到数据时,更新哈希对象的状态
|
// 当读取到数据时,更新哈希对象的状态
|
||||||
hash.update(data);
|
hash.update(data);
|
||||||
});
|
});
|
||||||
@@ -182,28 +182,28 @@ export async function uriToLocalFile(dir: string, uri: string, filename: string
|
|||||||
const filePath = path.join(dir, filename);
|
const filePath = path.join(dir, filename);
|
||||||
|
|
||||||
switch (UriType) {
|
switch (UriType) {
|
||||||
case FileUriType.Local: {
|
case FileUriType.Local: {
|
||||||
const fileExt = path.extname(HandledUri);
|
const fileExt = path.extname(HandledUri);
|
||||||
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
|
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
|
||||||
const tempFilePath = path.join(dir, filename + fileExt);
|
const tempFilePath = path.join(dir, filename + fileExt);
|
||||||
fs.copyFileSync(HandledUri, tempFilePath);
|
fs.copyFileSync(HandledUri, tempFilePath);
|
||||||
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
|
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
|
||||||
}
|
}
|
||||||
|
|
||||||
case FileUriType.Remote: {
|
case FileUriType.Remote: {
|
||||||
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
|
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
|
||||||
fs.writeFileSync(filePath, buffer);
|
fs.writeFileSync(filePath, buffer);
|
||||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||||
}
|
}
|
||||||
|
|
||||||
case FileUriType.Base64: {
|
case FileUriType.Base64: {
|
||||||
const base64 = HandledUri.replace(/^base64:\/\//, '');
|
const base64 = HandledUri.replace(/^base64:\/\//, '');
|
||||||
const base64Buffer = Buffer.from(base64, 'base64');
|
const base64Buffer = Buffer.from(base64, 'base64');
|
||||||
fs.writeFileSync(filePath, base64Buffer);
|
fs.writeFileSync(filePath, base64Buffer);
|
||||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.7.8';
|
export const napCatVersion = '4.7.18';
|
||||||
|
@@ -5,8 +5,11 @@ 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)?.log) {
|
||||||
|
console.error('Worker Log--->:', (result as { log: string }).log);
|
||||||
|
}
|
||||||
if ((result as any)?.error) {
|
if ((result as any)?.error) {
|
||||||
reject(new Error((result as { error: string }).error));
|
reject(new Error("Worker error: " + (result as { error: string }).error));
|
||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
@@ -41,10 +41,10 @@ export class NTQQFileApi {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.rkeyManager = new RkeyManager([
|
this.rkeyManager = new RkeyManager([
|
||||||
'https://ss.xingzhige.com/music_card/rkey', // 国内
|
'https://secret-service.bietiaop.com/rkeys',
|
||||||
'https://secret-service.bietiaop.com/rkeys',//国内
|
'http://ss.xingzhige.com/music_card/rkey',
|
||||||
],
|
],
|
||||||
this.context.logger
|
this.context.logger
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,23 +182,30 @@ export class NTQQFileApi {
|
|||||||
filePath = newFilePath;
|
filePath = newFilePath;
|
||||||
|
|
||||||
const { fileName: _fileName, path, fileSize, md5 } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.VIDEO);
|
const { fileName: _fileName, path, fileSize, md5 } = await this.core.apis.FileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||||
|
context.deleteAfterSentFiles.push(path);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw new Error('文件异常,大小为0');
|
throw new Error('文件异常,大小为0');
|
||||||
}
|
}
|
||||||
const thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`);
|
const thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`);
|
||||||
fs.mkdirSync(pathLib.dirname(thumbDir), { recursive: true });
|
fs.mkdirSync(pathLib.dirname(thumbDir), { recursive: true });
|
||||||
const thumbPath = pathLib.join(pathLib.dirname(thumbDir), `${md5}_0.png`);
|
const thumbPath = pathLib.join(pathLib.dirname(thumbDir), `${md5}_0.png`);
|
||||||
try {
|
|
||||||
videoInfo = await FFmpegService.getVideoInfo(filePath, thumbPath);
|
|
||||||
} catch {
|
|
||||||
fs.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64'));
|
|
||||||
}
|
|
||||||
if (_diyThumbPath) {
|
if (_diyThumbPath) {
|
||||||
try {
|
try {
|
||||||
await this.copyFile(_diyThumbPath, thumbPath);
|
await this.copyFile(_diyThumbPath, thumbPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.context.logger.logError('复制自定义缩略图失败', e);
|
this.context.logger.logError('复制自定义缩略图失败', e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
videoInfo = await FFmpegService.getVideoInfo(filePath, thumbPath);
|
||||||
|
if (!fs.existsSync(thumbPath)) {
|
||||||
|
this.context.logger.logError('获取视频缩略图失败', new Error('缩略图不存在'));
|
||||||
|
throw new Error('获取视频缩略图失败');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.context.logger.logError('获取视频信息失败', e);
|
||||||
|
fs.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.deleteAfterSentFiles.push(thumbPath);
|
context.deleteAfterSentFiles.push(thumbPath);
|
||||||
const thumbSize = (await fsPromises.stat(thumbPath)).size;
|
const thumbSize = (await fsPromises.stat(thumbPath)).size;
|
||||||
@@ -224,7 +231,7 @@ export class NTQQFileApi {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async createValidSendPttElement(pttPath: string): Promise<SendPttElement> {
|
async createValidSendPttElement(_context: SendMessageContext, pttPath: string): Promise<SendPttElement> {
|
||||||
|
|
||||||
const { converted, path: silkPath, duration } = await encodeSilk(pttPath, this.core.NapCatTempPath, this.core.context.logger);
|
const { converted, path: silkPath, duration } = await encodeSilk(pttPath, this.core.NapCatTempPath, this.core.context.logger);
|
||||||
if (!silkPath) {
|
if (!silkPath) {
|
||||||
@@ -301,18 +308,18 @@ export class NTQQFileApi {
|
|||||||
element.elementType === ElementType.FILE
|
element.elementType === ElementType.FILE
|
||||||
) {
|
) {
|
||||||
switch (element.elementType) {
|
switch (element.elementType) {
|
||||||
case ElementType.PIC:
|
case ElementType.PIC:
|
||||||
element.picElement!.sourcePath = elementResults?.[elementIndex] ?? '';
|
element.picElement!.sourcePath = elementResults?.[elementIndex] ?? '';
|
||||||
break;
|
break;
|
||||||
case ElementType.VIDEO:
|
case ElementType.VIDEO:
|
||||||
element.videoElement!.filePath = elementResults?.[elementIndex] ?? '';
|
element.videoElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||||
break;
|
break;
|
||||||
case ElementType.PTT:
|
case ElementType.PTT:
|
||||||
element.pttElement!.filePath = elementResults?.[elementIndex] ?? '';
|
element.pttElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||||
break;
|
break;
|
||||||
case ElementType.FILE:
|
case ElementType.FILE:
|
||||||
element.fileElement!.filePath = elementResults?.[elementIndex] ?? '';
|
element.fileElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
elementIndex++;
|
elementIndex++;
|
||||||
}
|
}
|
||||||
|
@@ -44,22 +44,13 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initApi() {
|
async initApi() {
|
||||||
await this.initCache().then().catch(e => this.context.logger.logError(e));
|
this.initCache().then().catch(e => this.context.logger.logError(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
async initCache() {
|
async initCache() {
|
||||||
let promises: Promise<void>[] = [];
|
|
||||||
for (const group of await this.getGroups(true)) {
|
for (const group of await this.getGroups(true)) {
|
||||||
let user = await this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e));
|
this.refreshGroupMemberCache(group.groupCode, false).then().catch(e => this.context.logger.logError(e));
|
||||||
if (user) {
|
|
||||||
for (const member of user) {
|
|
||||||
let promise = this.core.apis.UserApi.fetchUserDetailInfoV3(member[1].uid).then(_ => void 0).catch(e => this.context.logger.logError(e));
|
|
||||||
promises.push(promise);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await Promise.all(promises);
|
|
||||||
this.context.logger.logDebug('[NapCat] [Mark] 群成员缓存初始化完成');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchGroupEssenceList(groupCode: string) {
|
async fetchGroupEssenceList(groupCode: string) {
|
||||||
@@ -227,6 +218,10 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getRichMediaService().deleteGroupFolder(groupCode, folderId);
|
return this.context.session.getRichMediaService().deleteGroupFolder(groupCode, folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async transGroupFile(groupCode: string, fileId: string) {
|
||||||
|
return this.context.session.getRichMediaService().transGroupFile(groupCode, fileId);
|
||||||
|
}
|
||||||
|
|
||||||
async addGroupEssence(groupCode: string, msgId: string) {
|
async addGroupEssence(groupCode: string, msgId: string) {
|
||||||
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
||||||
chatType: 2,
|
chatType: 2,
|
||||||
|
@@ -12,7 +12,7 @@ export class NTQQMsgApi {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
async clickInlineKeyboardButton(...params: Parameters<NodeIKernelMsgService['clickInlineKeyboardButton']>) {
|
async clickInlineKeyboardButton(...params: Parameters<NodeIKernelMsgService['clickInlineKeyboardButton']>) {
|
||||||
return this.context.session.getMsgService().clickInlineKeyboardButton(...params);
|
return this.context.session.getMsgService().clickInlineKeyboardButton(...params);
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { ModifyProfileParams, UserDetailSource } from '@/core/types';
|
import { ModifyProfileParams, User, UserDetailSource } from '@/core/types';
|
||||||
import { RequestUtil } from '@/common/request';
|
import { RequestUtil } from '@/common/request';
|
||||||
import { InstanceContext, NapCatCore, ProfileBizType } from '..';
|
import { InstanceContext, NapCatCore, ProfileBizType } from '..';
|
||||||
import { solveAsyncProblem } from '@/common/helper';
|
import { solveAsyncProblem } from '@/common/helper';
|
||||||
@@ -77,7 +77,7 @@ export class NTQQUserApi {
|
|||||||
return this.context.session.getGroupService().setHeader(gc, filePath);
|
return this.context.session.getGroupService().setHeader(gc, filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchUserDetailInfoV2(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
|
async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
|
||||||
const [, profile] = await this.core.eventWrapper.callNormalEventV2(
|
const [, profile] = await this.core.eventWrapper.callNormalEventV2(
|
||||||
'NodeIKernelProfileService/fetchUserDetailInfo',
|
'NodeIKernelProfileService/fetchUserDetailInfo',
|
||||||
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||||
@@ -93,26 +93,37 @@ export class NTQQUserApi {
|
|||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchUserDetailInfoV3(uid: string) {
|
async getUserDetailInfo(uid: string, no_cache: boolean = false): Promise<User> {
|
||||||
let cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB);
|
let profile = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, no_cache ? UserDetailSource.KSERVER : UserDetailSource.KDB), uid);
|
||||||
if (!cache.commonExt) {
|
if (profile && profile.uin !== '0' && profile.commonExt) {
|
||||||
cache = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KSERVER);
|
return {
|
||||||
}
|
...profile.simpleInfo.status,
|
||||||
return cache;
|
...profile.simpleInfo.vasInfo,
|
||||||
}
|
...profile.commonExt,
|
||||||
|
...profile.simpleInfo.baseInfo,
|
||||||
|
...profile.simpleInfo.coreInfo,
|
||||||
async getUserDetailInfoV2(uid: string) {
|
qqLevel: profile.commonExt?.qqLevel,
|
||||||
let retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfoV2(uid, UserDetailSource.KDB), uid);
|
age: profile.simpleInfo.baseInfo.age,
|
||||||
if (retUser && retUser.uin !== '0') {
|
pendantId: '',
|
||||||
return retUser;
|
nick: profile.simpleInfo.coreInfo.nick || '',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
||||||
retUser = await this.fetchUserDetailInfoV2(uid, UserDetailSource.KSERVER);
|
profile = await this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
||||||
if (retUser && retUser.uin === '0') {
|
if (profile && profile.uin === '0') {
|
||||||
retUser.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
profile.uin = await this.core.apis.UserApi.getUidByUinV2(uid) ?? '0';
|
||||||
}
|
}
|
||||||
return retUser;
|
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 || '',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async modifySelfProfile(param: ModifyProfileParams) {
|
async modifySelfProfile(param: ModifyProfileParams) {
|
||||||
@@ -201,7 +212,7 @@ export class NTQQUserApi {
|
|||||||
.add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid)))
|
.add(() => this.context.session.getUixConvertService().getUin([uid]).then((data) => data.uinInfo.get(uid)))
|
||||||
.add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid))
|
.add(() => this.context.session.getProfileService().getUinByUid('FriendsServiceImpl', [uid]).get(uid))
|
||||||
.add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid)))
|
.add(() => this.context.session.getGroupService().getUinByUids([uid]).then((data) => data.uins.get(uid)))
|
||||||
.add(() => this.fetchUserDetailInfoV2(uid).then((data) => data.uin));
|
.add(() => this.getUserDetailInfo(uid).then((data) => data.uin));
|
||||||
|
|
||||||
const uin = await fallback.run().catch(() => '0');
|
const uin = await fallback.run().catch(() => '0');
|
||||||
return uin ?? '0';
|
return uin ?? '0';
|
||||||
|
16
src/core/external/appid.json
vendored
16
src/core/external/appid.json
vendored
@@ -226,5 +226,21 @@
|
|||||||
"9.9.18-33139": {
|
"9.9.18-33139": {
|
||||||
"appid": 537273874,
|
"appid": 537273874,
|
||||||
"qua": "V1_WIN_NQ_9.9.18_33139_GW_B"
|
"qua": "V1_WIN_NQ_9.9.18_33139_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.18-33800": {
|
||||||
|
"appid": 537273974,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.18_33800_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.16-33800": {
|
||||||
|
"appid": 537274009,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.16_33800_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.19-34231": {
|
||||||
|
"appid": 537279209,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.19_34231_GW_B"
|
||||||
|
},
|
||||||
|
"3.2.17-34231": {
|
||||||
|
"appid": 537279245,
|
||||||
|
"qua": "V1_LNX_NQ_3.2.17_34231_GW_B"
|
||||||
}
|
}
|
||||||
}
|
}
|
24
src/core/external/offset.json
vendored
24
src/core/external/offset.json
vendored
@@ -302,5 +302,29 @@
|
|||||||
"3.2.16-33139-arm64": {
|
"3.2.16-33139-arm64": {
|
||||||
"send": "7262BB0",
|
"send": "7262BB0",
|
||||||
"recv": "72664E0"
|
"recv": "72664E0"
|
||||||
|
},
|
||||||
|
"9.9.18-33800-x64": {
|
||||||
|
"send": "39F5870",
|
||||||
|
"recv": "39FA070"
|
||||||
|
},
|
||||||
|
"3.2.16-33800-x64": {
|
||||||
|
"send": "A634F60",
|
||||||
|
"recv": "A638980"
|
||||||
|
},
|
||||||
|
"3.2.16-33800-arm64": {
|
||||||
|
"send": "7262BB0",
|
||||||
|
"recv": "72664E0"
|
||||||
|
},
|
||||||
|
"9.9.19-34231-x64": {
|
||||||
|
"send": "3BD73D0",
|
||||||
|
"recv": "3BDBBD0"
|
||||||
|
},
|
||||||
|
"3.2.17-34231-x64": {
|
||||||
|
"send": "AD787E0",
|
||||||
|
"recv": "AD7C200"
|
||||||
|
},
|
||||||
|
"3.2.17-34231-arm64": {
|
||||||
|
"send": "770CDC0",
|
||||||
|
"recv": "77106F0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -6,6 +6,17 @@ interface ServerRkeyData {
|
|||||||
private_rkey: string;
|
private_rkey: string;
|
||||||
expired_time: number;
|
expired_time: number;
|
||||||
}
|
}
|
||||||
|
interface OneBotApiRet {
|
||||||
|
status: string,
|
||||||
|
retcode: number,
|
||||||
|
data: ServerRkeyData,
|
||||||
|
message: string,
|
||||||
|
wording: string,
|
||||||
|
}
|
||||||
|
interface UrlFailureInfo {
|
||||||
|
count: number;
|
||||||
|
lastTimestamp: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class RkeyManager {
|
export class RkeyManager {
|
||||||
serverUrl: string[] = [];
|
serverUrl: string[] = [];
|
||||||
@@ -15,9 +26,8 @@ export class RkeyManager {
|
|||||||
private_rkey: '',
|
private_rkey: '',
|
||||||
expired_time: 0,
|
expired_time: 0,
|
||||||
};
|
};
|
||||||
private failureCount: number = 0;
|
private urlFailures: Map<string, UrlFailureInfo> = new Map();
|
||||||
private lastFailureTimestamp: number = 0;
|
private readonly FAILURE_LIMIT: number = 4;
|
||||||
private readonly FAILURE_LIMIT: number = 8;
|
|
||||||
private readonly ONE_DAY: number = 24 * 60 * 60 * 1000;
|
private readonly ONE_DAY: number = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
constructor(serverUrl: string[], logger: LogWrapper) {
|
constructor(serverUrl: string[], logger: LogWrapper) {
|
||||||
@@ -26,50 +36,92 @@ export class RkeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getRkey() {
|
async getRkey() {
|
||||||
const now = new Date().getTime();
|
const availableUrls = this.getAvailableUrls();
|
||||||
if (now - this.lastFailureTimestamp > this.ONE_DAY) {
|
if (availableUrls.length === 0) {
|
||||||
this.failureCount = 0; // 重置失败计数器
|
this.logger.logError('[Rkey] 所有服务均已禁用, 图片使用FallBack机制');
|
||||||
}
|
throw new Error('获取rkey失败:所有服务URL均已被禁用');
|
||||||
|
|
||||||
if (this.failureCount >= this.FAILURE_LIMIT) {
|
|
||||||
this.logger.logError('[Rkey] 服务存在异常, 图片使用FallBack机制');
|
|
||||||
throw new Error('获取rkey失败次数过多,请稍后再试');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isExpired()) {
|
if (this.isExpired()) {
|
||||||
try {
|
try {
|
||||||
await this.refreshRkey();
|
await this.refreshRkey();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`${e}`);//外抛
|
throw new Error(`${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.rkeyData;
|
return this.rkeyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getAvailableUrls(): string[] {
|
||||||
|
return this.serverUrl.filter(url => !this.isUrlDisabled(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
private isUrlDisabled(url: string): boolean {
|
||||||
|
const failureInfo = this.urlFailures.get(url);
|
||||||
|
if (!failureInfo) return false;
|
||||||
|
|
||||||
|
const now = new Date().getTime();
|
||||||
|
// 如果已经过了一天,重置失败计数
|
||||||
|
if (now - failureInfo.lastTimestamp > this.ONE_DAY) {
|
||||||
|
failureInfo.count = 0;
|
||||||
|
this.urlFailures.set(url, failureInfo);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return failureInfo.count >= this.FAILURE_LIMIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateUrlFailure(url: string) {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
const failureInfo = this.urlFailures.get(url) || { count: 0, lastTimestamp: 0 };
|
||||||
|
|
||||||
|
// 如果已经过了一天,重置失败计数
|
||||||
|
if (now - failureInfo.lastTimestamp > this.ONE_DAY) {
|
||||||
|
failureInfo.count = 1;
|
||||||
|
} else {
|
||||||
|
failureInfo.count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
failureInfo.lastTimestamp = now;
|
||||||
|
this.urlFailures.set(url, failureInfo);
|
||||||
|
|
||||||
|
if (failureInfo.count >= this.FAILURE_LIMIT) {
|
||||||
|
this.logger.logError(`[Rkey] URL ${url} 已被禁用,失败次数达到 ${this.FAILURE_LIMIT} 次`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isExpired(): boolean {
|
isExpired(): boolean {
|
||||||
const now = new Date().getTime() / 1000;
|
const now = new Date().getTime() / 1000;
|
||||||
return now > this.rkeyData.expired_time;
|
return now > this.rkeyData.expired_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshRkey() {
|
async refreshRkey() {
|
||||||
//刷新rkey
|
const availableUrls = this.getAvailableUrls();
|
||||||
for (const url of this.serverUrl) {
|
|
||||||
|
if (availableUrls.length === 0) {
|
||||||
|
this.logger.logError('[Rkey] 所有服务均已禁用');
|
||||||
|
throw new Error('获取rkey失败:所有服务URL均已被禁用');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const url of availableUrls) {
|
||||||
try {
|
try {
|
||||||
const temp = await RequestUtil.HttpGetJson<ServerRkeyData>(url, 'GET');
|
let temp = await RequestUtil.HttpGetJson<ServerRkeyData>(url, 'GET');
|
||||||
|
if ('retcode' in temp) {
|
||||||
|
// 支持Onebot Ret风格
|
||||||
|
temp = (temp as unknown as OneBotApiRet).data;
|
||||||
|
}
|
||||||
this.rkeyData = {
|
this.rkeyData = {
|
||||||
group_rkey: temp.group_rkey.slice(6),
|
group_rkey: temp.group_rkey.slice(6),
|
||||||
private_rkey: temp.private_rkey.slice(6),
|
private_rkey: temp.private_rkey.slice(6),
|
||||||
expired_time: temp.expired_time
|
expired_time: temp.expired_time
|
||||||
};
|
};
|
||||||
this.failureCount = 0;
|
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.logError(`[Rkey] 异常服务 ${url} 异常 / `, e);
|
this.logger.logError(`[Rkey] 异常服务 ${url} 异常 / `, e);
|
||||||
this.failureCount++;
|
this.updateUrlFailure(url);
|
||||||
this.lastFailureTimestamp = new Date().getTime();
|
|
||||||
//是否为最后一个url
|
if (url === availableUrls[availableUrls.length - 1]) {
|
||||||
if (url === this.serverUrl[this.serverUrl.length - 1]) {
|
throw new Error(`获取rkey失败: ${e}`);
|
||||||
throw new Error(`获取rkey失败: ${e}`);//外抛
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,71 +1,71 @@
|
|||||||
import { User, UserDetailInfoListenerArg } from '@/core/types';
|
import { User, UserDetailInfoListenerArg } from '@/core/types';
|
||||||
|
|
||||||
export class NodeIKernelProfileListener {
|
export class NodeIKernelProfileListener {
|
||||||
onUserDetailInfoChanged(_arg: UserDetailInfoListenerArg): void {
|
onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onProfileSimpleChanged(..._args: unknown[]): any {
|
onProfileSimpleChanged(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onProfileDetailInfoChanged(_profile: User): any {
|
onProfileDetailInfoChanged(profile: User): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onStatusUpdate(..._args: unknown[]): any {
|
onStatusUpdate(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelfStatusChanged(..._args: unknown[]): any {
|
onSelfStatusChanged(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onStrangerRemarkChanged(..._args: unknown[]): any {
|
onStrangerRemarkChanged(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMemberListChange(..._args: unknown[]): any {
|
onMemberListChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMemberInfoChange(..._args: unknown[]): any {
|
onMemberInfoChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupListUpdate(..._args: unknown[]): any {
|
onGroupListUpdate(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupAllInfoChange(..._args: unknown[]): any {
|
onGroupAllInfoChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupDetailInfoChange(..._args: unknown[]): any {
|
onGroupDetailInfoChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupConfMemberChange(..._args: unknown[]): any {
|
onGroupConfMemberChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupExtListUpdate(..._args: unknown[]): any {
|
onGroupExtListUpdate(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupNotifiesUpdated(..._args: unknown[]): any {
|
onGroupNotifiesUpdated(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupNotifiesUnreadCountUpdated(..._args: unknown[]): any {
|
onGroupNotifiesUnreadCountUpdated(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupMemberLevelInfoChange(..._args: unknown[]): any {
|
onGroupMemberLevelInfoChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onGroupBulletinChange(..._args: unknown[]): any {
|
onGroupBulletinChange(...args: unknown[]): any {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -68,8 +68,8 @@ export class PacketOperationContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async SetGroupSpecialTitle(groupUin: number, uid: string, tittle: string) {
|
async SetGroupSpecialTitle(groupUin: number, uid: string, title: string) {
|
||||||
const req = trans.SetSpecialTitle.build(groupUin, uid, tittle);
|
const req = trans.SetSpecialTitle.build(groupUin, uid, title);
|
||||||
await this.context.client.sendOidbPacket(req);
|
await this.context.client.sendOidbPacket(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +154,20 @@ export class PacketOperationContext {
|
|||||||
return res.result.resId;
|
return res.result.resId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async MoveGroupFile(groupUin: number, fileUUID: string, currentParentDirectory: string, targetParentDirectory: string) {
|
||||||
|
const req = trans.MoveGroupFile.build(groupUin, fileUUID, currentParentDirectory, targetParentDirectory);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.MoveGroupFile.parse(resp);
|
||||||
|
return res.move.retCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
async RenameGroupFile(groupUin: number, fileUUID: string, currentParentDirectory: string, newName: string) {
|
||||||
|
const req = trans.RenameGroupFile.build(groupUin, fileUUID, currentParentDirectory, newName);
|
||||||
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
const res = trans.RenameGroupFile.parse(resp);
|
||||||
|
return res.rename.retCode;
|
||||||
|
}
|
||||||
|
|
||||||
async GetGroupFileUrl(groupUin: number, fileUUID: string) {
|
async GetGroupFileUrl(groupUin: number, fileUUID: string) {
|
||||||
const req = trans.DownloadGroupFile.build(groupUin, fileUUID);
|
const req = trans.DownloadGroupFile.build(groupUin, fileUUID);
|
||||||
const resp = await this.context.client.sendOidbPacket(req, true);
|
const resp = await this.context.client.sendOidbPacket(req, true);
|
||||||
|
35
src/core/packet/transformer/action/MoveGroupFile.ts
Normal file
35
src/core/packet/transformer/action/MoveGroupFile.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import * as proto from '@/core/packet/transformer/proto';
|
||||||
|
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
|
import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base';
|
||||||
|
import OidbBase from '@/core/packet/transformer/oidb/oidbBase';
|
||||||
|
|
||||||
|
class MoveGroupFile extends PacketTransformer<typeof proto.OidbSvcTrpcTcp0x6D6Response> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(groupUin: number, fileUUID: string, currentParentDirectory: string, targetParentDirectory: string): OidbPacket {
|
||||||
|
const body = new NapProtoMsg(proto.OidbSvcTrpcTcp0x6D6).encode({
|
||||||
|
move: {
|
||||||
|
groupUin: groupUin,
|
||||||
|
appId: 5,
|
||||||
|
busId: 102,
|
||||||
|
fileId: fileUUID,
|
||||||
|
parentDirectory: currentParentDirectory,
|
||||||
|
targetDirectory: targetParentDirectory,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return OidbBase.build(0x6D6, 5, body, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
const oidbBody = OidbBase.parse(data).body;
|
||||||
|
const res = new NapProtoMsg(proto.OidbSvcTrpcTcp0x6D6Response).decode(oidbBody);
|
||||||
|
if (res.move.retCode !== 0) {
|
||||||
|
throw new Error(`sendGroupFileMoveReq error: ${res.move.clientWording} (code=${res.move.retCode})`);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new MoveGroupFile();
|
34
src/core/packet/transformer/action/RenameGroupFile.ts
Normal file
34
src/core/packet/transformer/action/RenameGroupFile.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import * as proto from '@/core/packet/transformer/proto';
|
||||||
|
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
|
import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base';
|
||||||
|
import OidbBase from '@/core/packet/transformer/oidb/oidbBase';
|
||||||
|
|
||||||
|
class RenameGroupFile extends PacketTransformer<typeof proto.OidbSvcTrpcTcp0x6D6Response> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
build(groupUin: number, fileUUID: string, currentParentDirectory: string, newName: string): OidbPacket {
|
||||||
|
const body = new NapProtoMsg(proto.OidbSvcTrpcTcp0x6D6).encode({
|
||||||
|
rename: {
|
||||||
|
groupUin: groupUin,
|
||||||
|
busId: 102,
|
||||||
|
fileId: fileUUID,
|
||||||
|
parentFolder: currentParentDirectory,
|
||||||
|
newFileName: newName,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return OidbBase.build(0x6D6, 4, body, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(data: Buffer) {
|
||||||
|
const oidbBody = OidbBase.parse(data).body;
|
||||||
|
const res = new NapProtoMsg(proto.OidbSvcTrpcTcp0x6D6Response).decode(oidbBody);
|
||||||
|
if (res.rename.retCode !== 0) {
|
||||||
|
throw new Error(`sendGroupFileRenameReq error: ${res.rename.clientWording} (code=${res.rename.retCode})`);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new RenameGroupFile();
|
@@ -8,14 +8,14 @@ class SetSpecialTitle extends PacketTransformer<typeof proto.OidbSvcTrpcTcpBase>
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
build(groupCode: number, uid: string, tittle: string): OidbPacket {
|
build(groupCode: number, uid: string, title: string): OidbPacket {
|
||||||
const oidb_0x8FC_2 = new NapProtoMsg(proto.OidbSvcTrpcTcp0X8FC_2).encode({
|
const oidb_0x8FC_2 = new NapProtoMsg(proto.OidbSvcTrpcTcp0X8FC_2).encode({
|
||||||
groupUin: +groupCode,
|
groupUin: +groupCode,
|
||||||
body: {
|
body: {
|
||||||
targetUid: uid,
|
targetUid: uid,
|
||||||
specialTitle: tittle,
|
specialTitle: title,
|
||||||
expiredTime: -1,
|
expiredTime: -1,
|
||||||
uinName: tittle
|
uinName: title
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return OidbBase.build(0x8FC, 2, oidb_0x8FC_2, false, false);
|
return OidbBase.build(0x8FC, 2, oidb_0x8FC_2, false, false);
|
||||||
|
@@ -6,3 +6,5 @@ export { default as GetStrangerInfo } from './GetStrangerInfo';
|
|||||||
export { default as SendPoke } from './SendPoke';
|
export { default as SendPoke } from './SendPoke';
|
||||||
export { default as SetSpecialTitle } from './SetSpecialTitle';
|
export { default as SetSpecialTitle } from './SetSpecialTitle';
|
||||||
export { default as ImageOCR } from './ImageOCR';
|
export { default as ImageOCR } from './ImageOCR';
|
||||||
|
export { default as MoveGroupFile } from './MoveGroupFile';
|
||||||
|
export { default as RenameGroupFile } from './RenameGroupFile';
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { AnyCnameRecord } from 'node:dns';
|
import { AnyCnameRecord } from 'node:dns';
|
||||||
import { BizKey, ModifyProfileParams, NodeIKernelProfileListener, ProfileBizType, SimpleInfo, UserDetailInfoByUin, UserDetailSource } from '@/core';
|
import { BizKey, ModifyProfileParams, NodeIKernelProfileListener, ProfileBizType, SimpleInfo, UserDetailInfoByUin, UserDetailInfoListenerArg, UserDetailSource } from '@/core';
|
||||||
import { GeneralCallResult } from '@/core/services/common';
|
import { GeneralCallResult } from '@/core/services/common';
|
||||||
|
|
||||||
export interface NodeIKernelProfileService {
|
export interface NodeIKernelProfileService {
|
||||||
@@ -15,7 +15,13 @@ export interface NodeIKernelProfileService {
|
|||||||
|
|
||||||
getCoreAndBaseInfo(callfrom: string, uids: string[]): Promise<Map<string, SimpleInfo>>;
|
getCoreAndBaseInfo(callfrom: string, uids: string[]): Promise<Map<string, SimpleInfo>>;
|
||||||
|
|
||||||
fetchUserDetailInfo(trace: string, uids: string[], source: UserDetailSource, bizType: ProfileBizType[]): Promise<GeneralCallResult>;
|
fetchUserDetailInfo(trace: string, uids: string[], source: UserDetailSource, bizType: ProfileBizType[]): Promise<GeneralCallResult &
|
||||||
|
{
|
||||||
|
source: UserDetailSource,
|
||||||
|
// uid -> detail
|
||||||
|
detail: Map<string, UserDetailInfoListenerArg>,
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
addKernelProfileListener(listener: NodeIKernelProfileListener): number;
|
addKernelProfileListener(listener: NodeIKernelProfileListener): number;
|
||||||
|
|
||||||
|
@@ -198,9 +198,29 @@ export interface NodeIKernelRichMediaService {
|
|||||||
|
|
||||||
renameGroupFile(arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown, arg5: unknown): unknown;
|
renameGroupFile(arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown, arg5: unknown): unknown;
|
||||||
|
|
||||||
moveGroupFile(arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown, arg5: unknown): unknown;
|
moveGroupFile(groupCode: string, busId: Array<number>, fileList: Array<string>, currentParentDirectory: string, targetParentDirectory: string): Promise<GeneralCallResult & {
|
||||||
|
moveGroupFileResult: {
|
||||||
|
result: {
|
||||||
|
retCode: number,
|
||||||
|
retMsg: symbol,
|
||||||
|
clientWording: string
|
||||||
|
},
|
||||||
|
successFileIdList: Array<string>,
|
||||||
|
failFileIdList: Array<string>
|
||||||
|
}
|
||||||
|
}>;
|
||||||
|
|
||||||
transGroupFile(arg1: unknown, arg2: unknown): unknown;
|
transGroupFile(groupCode: string, fileId: string): Promise<GeneralCallResult & {
|
||||||
|
transGroupFileResult: {
|
||||||
|
result: {
|
||||||
|
retCode: number
|
||||||
|
retMsg: string
|
||||||
|
clientWording: string
|
||||||
|
}
|
||||||
|
saveBusId: number
|
||||||
|
saveFilePath: string
|
||||||
|
}
|
||||||
|
}>;
|
||||||
|
|
||||||
searchGroupFile(
|
searchGroupFile(
|
||||||
keywords: Array<string>,
|
keywords: Array<string>,
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { QQLevel, NTSex } from './user';
|
||||||
|
|
||||||
export interface KickMemberInfo {
|
export interface KickMemberInfo {
|
||||||
optFlag: number;
|
optFlag: number;
|
||||||
optOperate: number;
|
optOperate: number;
|
||||||
@@ -272,42 +274,24 @@ export enum NTGroupMemberRole {
|
|||||||
KOWNER = 4
|
KOWNER = 4
|
||||||
}
|
}
|
||||||
export interface GroupMember {
|
export interface GroupMember {
|
||||||
uid: string;
|
memberRealLevel: number | undefined;
|
||||||
qid: string;
|
memberSpecialTitle?: string;
|
||||||
uin: string;
|
|
||||||
nick: string;
|
|
||||||
remark: string;
|
|
||||||
cardType: number;
|
|
||||||
cardName: string;
|
|
||||||
role: NTGroupMemberRole;
|
|
||||||
avatarPath: string;
|
avatarPath: string;
|
||||||
shutUpTime: number;
|
cardName: string;
|
||||||
|
cardType: number;
|
||||||
isDelete: boolean;
|
isDelete: boolean;
|
||||||
isSpecialConcerned: boolean;
|
nick: string;
|
||||||
isSpecialShield: boolean;
|
qid: string;
|
||||||
|
remark: string;
|
||||||
|
role: NTGroupMemberRole;
|
||||||
|
shutUpTime: number; // 禁言时间(S)
|
||||||
|
uid: string;
|
||||||
|
uin: string;
|
||||||
isRobot: boolean;
|
isRobot: boolean;
|
||||||
groupHonor: Uint8Array;
|
sex?: NTSex;
|
||||||
memberRealLevel: number;
|
age?: number;
|
||||||
memberLevel: number;
|
qqLevel?: QQLevel;
|
||||||
globalGroupLevel: number;
|
isChangeRole: boolean;
|
||||||
globalGroupPoint: number;
|
joinTime: string;
|
||||||
memberTitleId: number;
|
lastSpeakTime: string;
|
||||||
memberSpecialTitle: string;
|
|
||||||
specialTitleExpireTime: string;
|
|
||||||
userShowFlag: number;
|
|
||||||
userShowFlagNew: number;
|
|
||||||
richFlag: number;
|
|
||||||
mssVipType: number;
|
|
||||||
bigClubLevel: number;
|
|
||||||
bigClubFlag: number;
|
|
||||||
autoRemark: string;
|
|
||||||
creditLevel: number;
|
|
||||||
joinTime: number;
|
|
||||||
lastSpeakTime: number;
|
|
||||||
memberFlag: number;
|
|
||||||
memberFlagExt: number;
|
|
||||||
memberMobileFlag: number;
|
|
||||||
memberFlagExt2: number;
|
|
||||||
isSpecialShielded: boolean;
|
|
||||||
cardNameId: number;
|
|
||||||
}
|
}
|
@@ -207,8 +207,9 @@ interface PhotoWall {
|
|||||||
|
|
||||||
// 简单信息
|
// 简单信息
|
||||||
export interface SimpleInfo {
|
export interface SimpleInfo {
|
||||||
uid: string;
|
qqLevel?: QQLevel;//临时添加
|
||||||
uin: string;
|
uid?: string;
|
||||||
|
uin?: string;
|
||||||
coreInfo: CoreInfo;
|
coreInfo: CoreInfo;
|
||||||
baseInfo: BaseInfo;
|
baseInfo: BaseInfo;
|
||||||
status: UserStatus | null;
|
status: UserStatus | null;
|
||||||
@@ -233,15 +234,13 @@ export interface SelfStatusInfo {
|
|||||||
setTime: string;
|
setTime: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserV2 = UserDetailInfoListenerArg;
|
|
||||||
|
|
||||||
// 用户详细信息监听参数
|
// 用户详细信息监听参数
|
||||||
export interface UserDetailInfoListenerArg {
|
export interface UserDetailInfoListenerArg {
|
||||||
uid: string;
|
uid: string;
|
||||||
uin: string;
|
uin: string;
|
||||||
simpleInfo?: SimpleInfo;
|
simpleInfo: SimpleInfo;
|
||||||
commonExt?: CommonExt;
|
commonExt: CommonExt;
|
||||||
photoWall?: PhotoWall;
|
photoWall: PhotoWall;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改个人资料参数
|
// 修改个人资料参数
|
||||||
@@ -334,12 +333,13 @@ export interface User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自身信息
|
// 自身信息
|
||||||
export interface SelfInfo extends Partial<UserV2> {
|
export interface SelfInfo extends User {
|
||||||
uid: string;
|
online?: boolean;
|
||||||
uin: string;
|
|
||||||
online: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 好友类型
|
||||||
|
export type Friend = User;
|
||||||
|
|
||||||
// 业务键枚举
|
// 业务键枚举
|
||||||
export enum BizKey {
|
export enum BizKey {
|
||||||
KPRIVILEGEICON = 0,
|
KPRIVILEGEICON = 0,
|
||||||
|
@@ -46,6 +46,7 @@ export async function NCoreInitFramework(
|
|||||||
resolveSelfInfo({
|
resolveSelfInfo({
|
||||||
uid: loginResult.uid,
|
uid: loginResult.uid,
|
||||||
uin: loginResult.uin,
|
uin: loginResult.uin,
|
||||||
|
nick: '', // 获取不到
|
||||||
online: true,
|
online: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@@ -3,6 +3,7 @@ import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
|||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { NapCatOneBot11Adapter, OB11Return } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Return } from '@/onebot';
|
||||||
import { NetworkAdapterConfig } from '../config/config';
|
import { NetworkAdapterConfig } from '../config/config';
|
||||||
|
import { TSchema } from '@sinclair/typebox';
|
||||||
|
|
||||||
export class OB11Response {
|
export class OB11Response {
|
||||||
private static createResponse<T>(data: T, status: string, retcode: number, message: string = '', echo: unknown = null): OB11Return<T> {
|
private static createResponse<T>(data: T, status: string, retcode: number, message: string = '', echo: unknown = null): OB11Return<T> {
|
||||||
@@ -33,7 +34,7 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
|||||||
actionName: typeof ActionName[keyof typeof ActionName] = ActionName.Unknown;
|
actionName: typeof ActionName[keyof typeof ActionName] = ActionName.Unknown;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
private validate?: ValidateFunction<unknown> = undefined;
|
private validate?: ValidateFunction<unknown> = undefined;
|
||||||
payloadSchema?: unknown = undefined;
|
payloadSchema?: TSchema = undefined;
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
|
|
||||||
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
@@ -43,7 +44,7 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
|||||||
|
|
||||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||||
if (this.payloadSchema) {
|
if (this.payloadSchema) {
|
||||||
this.validate = new Ajv({ allowUnionTypes: true, useDefaults: true }).compile(this.payloadSchema);
|
this.validate = new Ajv({ allowUnionTypes: true, useDefaults: true, coerceTypes: true }).compile(this.payloadSchema);
|
||||||
}
|
}
|
||||||
if (this.validate && !this.validate(payload)) {
|
if (this.validate && !this.validate(payload)) {
|
||||||
const errors = this.validate.errors as ErrorObject[];
|
const errors = this.validate.errors as ErrorObject[];
|
||||||
|
33
src/onebot/action/extends/MoveGroupFile.ts
Normal file
33
src/onebot/action/extends/MoveGroupFile.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
file_id: Type.String(),
|
||||||
|
current_parent_directory: Type.String(),
|
||||||
|
target_parent_directory: Type.String(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
interface MoveGroupFileResponse {
|
||||||
|
ok: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MoveGroupFile extends GetPacketStatusDepends<Payload, MoveGroupFileResponse> {
|
||||||
|
override actionName = ActionName.MoveGroupFile;
|
||||||
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
|
if (contextMsgFile?.fileUUID) {
|
||||||
|
await this.core.apis.PacketApi.pkt.operation.MoveGroupFile(+payload.group_id, contextMsgFile.fileUUID, payload.current_parent_directory, payload.target_parent_directory);
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error('real fileUUID not found!');
|
||||||
|
}
|
||||||
|
}
|
33
src/onebot/action/extends/RenameGroupFile.ts
Normal file
33
src/onebot/action/extends/RenameGroupFile.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
file_id: Type.String(),
|
||||||
|
current_parent_directory: Type.String(),
|
||||||
|
new_name: Type.String(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
interface RenameGroupFileResponse {
|
||||||
|
ok: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RenameGroupFile extends GetPacketStatusDepends<Payload, RenameGroupFileResponse> {
|
||||||
|
override actionName = ActionName.RenameGroupFile;
|
||||||
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
|
if (contextMsgFile?.fileUUID) {
|
||||||
|
await this.core.apis.PacketApi.pkt.operation.RenameGroupFile(+payload.group_id, contextMsgFile.fileUUID, payload.current_parent_directory, payload.new_name);
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error('real fileUUID not found!');
|
||||||
|
}
|
||||||
|
}
|
@@ -10,8 +10,8 @@ const SchemaData = Type.Object({
|
|||||||
|
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, void> {
|
export class SetSpecialTitle extends GetPacketStatusDepends<Payload, void> {
|
||||||
override actionName = ActionName.SetSpecialTittle;
|
override actionName = ActionName.SetSpecialTitle;
|
||||||
override payloadSchema = SchemaData;
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
34
src/onebot/action/extends/TransGroupFile.ts
Normal file
34
src/onebot/action/extends/TransGroupFile.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
file_id: Type.String(),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
interface TransGroupFileResponse {
|
||||||
|
ok: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TransGroupFile extends GetPacketStatusDepends<Payload, TransGroupFileResponse> {
|
||||||
|
override actionName = ActionName.TransGroupFile;
|
||||||
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
|
if (contextMsgFile?.fileUUID) {
|
||||||
|
const result = await this.core.apis.GroupApi.transGroupFile(payload.group_id.toString(), contextMsgFile.fileUUID);
|
||||||
|
if (result.transGroupFileResult.result.retCode === 0) {
|
||||||
|
return {
|
||||||
|
ok: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error(result.transGroupFileResult.result.retMsg);
|
||||||
|
}
|
||||||
|
throw new Error('real fileUUID not found!');
|
||||||
|
}
|
||||||
|
}
|
@@ -7,6 +7,7 @@ import { Static, Type } from '@sinclair/typebox';
|
|||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
no_cache: Type.Union([Type.Boolean(), Type.String()], { default: false }),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
@@ -16,10 +17,11 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
|
|||||||
override payloadSchema = SchemaData;
|
override payloadSchema = SchemaData;
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const user_id = payload.user_id.toString();
|
const user_id = payload.user_id.toString();
|
||||||
|
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
|
||||||
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
|
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
|
||||||
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
|
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
|
||||||
if (!uid) uid = extendData.detail.uid;
|
if (!uid) uid = extendData.detail.uid;
|
||||||
const info = (await this.core.apis.UserApi.fetchUserDetailInfoV2(uid));
|
const info = (await this.core.apis.UserApi.getUserDetailInfo(uid, isNocache));
|
||||||
return {
|
return {
|
||||||
...extendData.detail.simpleInfo.coreInfo,
|
...extendData.detail.simpleInfo.coreInfo,
|
||||||
...extendData.detail.commonExt ?? {},
|
...extendData.detail.commonExt ?? {},
|
||||||
@@ -29,17 +31,17 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
|
|||||||
user_id: parseInt(extendData.detail.uin) ?? 0,
|
user_id: parseInt(extendData.detail.uin) ?? 0,
|
||||||
uid: info.uid ?? uid,
|
uid: info.uid ?? uid,
|
||||||
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
|
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
|
||||||
age: extendData.detail.simpleInfo.baseInfo.age ?? info.simpleInfo?.baseInfo.age,
|
age: extendData.detail.simpleInfo.baseInfo.age ?? info.age,
|
||||||
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
||||||
qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.commonExt?.qqLevel),
|
qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.qqLevel),
|
||||||
sex: OB11Construct.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown,
|
sex: OB11Construct.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown,
|
||||||
long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.simpleInfo?.baseInfo.longNick,
|
long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.longNick,
|
||||||
reg_time: extendData.detail.commonExt?.regTime ?? info.commonExt?.regTime,
|
reg_time: extendData.detail.commonExt?.regTime ?? info.regTime,
|
||||||
is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag,
|
is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag,
|
||||||
is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag,
|
is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag,
|
||||||
vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel,
|
vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel,
|
||||||
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.simpleInfo?.coreInfo.remark,
|
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.remark,
|
||||||
status: extendData.detail.simpleInfo.status?.status ?? info.simpleInfo?.status?.status,
|
status: extendData.detail.simpleInfo.status?.status ?? info.status,
|
||||||
login_days: 0,//失效
|
login_days: 0,//失效
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -16,15 +16,15 @@ export class SetQQProfile extends OneBotAction<Payload, Awaited<ReturnType<NTQQU
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const self = this.core.selfInfo;
|
const self = this.core.selfInfo;
|
||||||
const OldProfile = await this.core.apis.UserApi.fetchUserDetailInfoV2(self.uid);
|
const OldProfile = await this.core.apis.UserApi.getUserDetailInfo(self.uid);
|
||||||
return await this.core.apis.UserApi.modifySelfProfile({
|
return await this.core.apis.UserApi.modifySelfProfile({
|
||||||
nick: payload.nickname,
|
nick: payload.nickname,
|
||||||
longNick: (payload?.personal_note ?? OldProfile?.simpleInfo!.baseInfo.longNick) || '',
|
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
|
||||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.simpleInfo!.baseInfo.sex!.toString()),
|
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
||||||
birthday: {
|
birthday: {
|
||||||
birthday_year: OldProfile?.simpleInfo!.baseInfo.birthday_year!.toString(),
|
birthday_year: OldProfile?.birthday_year!.toString(),
|
||||||
birthday_month: OldProfile?.simpleInfo!.baseInfo.birthday_month!.toString(),
|
birthday_month: OldProfile?.birthday_month!.toString(),
|
||||||
birthday_day: OldProfile?.simpleInfo!.baseInfo.birthday_day!.toString(),
|
birthday_day: OldProfile?.birthday_day!.toString(),
|
||||||
},
|
},
|
||||||
location: undefined,
|
location: undefined,
|
||||||
});
|
});
|
||||||
|
@@ -20,6 +20,7 @@ class GetGroupInfo extends OneBotAction<Payload, OB11Group> {
|
|||||||
const data = await this.core.apis.GroupApi.fetchGroupDetail(payload.group_id.toString());
|
const data = await this.core.apis.GroupApi.fetchGroupDetail(payload.group_id.toString());
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
|
group_all_shut: data.shutUpAllTimestamp > 0 ? -1 : 0,
|
||||||
group_remark: '',
|
group_remark: '',
|
||||||
group_id: +payload.group_id,
|
group_id: +payload.group_id,
|
||||||
group_name: data.groupName,
|
group_name: data.groupName,
|
||||||
|
@@ -32,20 +32,24 @@ class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
|
|||||||
|
|
||||||
const [member, info] = await Promise.all([
|
const [member, info] = await Promise.all([
|
||||||
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
|
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
|
||||||
this.core.apis.UserApi.fetchUserDetailInfoV2(uid),
|
this.core.apis.UserApi.getUserDetailInfo(uid, isNocache),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||||
|
|
||||||
return { member, info, groupMember };
|
return info ? { ...groupMember, ...member, ...info } : member;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const isNocache = this.parseBoolean(payload.no_cache ?? true);
|
const isNocache = this.parseBoolean(payload.no_cache ?? true);
|
||||||
const uid = await this.getUid(payload.user_id);
|
const uid = await this.getUid(payload.user_id);
|
||||||
const { member, info } = await this.getGroupMemberInfo(payload, uid, isNocache);
|
const member = await this.getGroupMemberInfo(payload, uid, isNocache);
|
||||||
console.log('member', JSON.stringify(member, null, 2), 'info', JSON.stringify(info, null, 2));
|
|
||||||
return OB11Construct.groupMember(payload.group_id.toString(), member, info);
|
if (!member) {
|
||||||
|
this.core.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
return OB11Construct.groupMember(payload.group_id.toString(), member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,35 +16,16 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
|
|||||||
override actionName = ActionName.GetGroupMemberList;
|
override actionName = ActionName.GetGroupMemberList;
|
||||||
override payloadSchema = SchemaData;
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理获取群成员列表请求
|
|
||||||
*/
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const groupIdStr = payload.group_id.toString();
|
const groupIdStr = payload.group_id.toString();
|
||||||
const noCache = this.parseBoolean(payload.no_cache ?? false);
|
const noCache = this.parseBoolean(payload.no_cache ?? false);
|
||||||
|
|
||||||
// 获取群成员基本信息
|
|
||||||
const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
|
const groupMembers = await this.getGroupMembers(groupIdStr, noCache);
|
||||||
const memberArray = Array.from(groupMembers.values());
|
const _groupMembers = await Promise.all(
|
||||||
|
Array.from(groupMembers.values()).map(item =>
|
||||||
// 批量并行获取用户详情
|
OB11Construct.groupMember(groupIdStr, item)
|
||||||
const userDetailsPromises = memberArray.map(member =>
|
)
|
||||||
this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid)
|
|
||||||
.catch(_ => {
|
|
||||||
return { uin: member.uin, uid: member.uid };
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
const userDetails = await Promise.all(userDetailsPromises);
|
return Array.from(new Map(_groupMembers.map(member => [member.user_id, member])).values());
|
||||||
|
|
||||||
// 并行构建 OneBot 格式的群成员数据
|
|
||||||
const groupMembersList = memberArray.map((member, index) => {
|
|
||||||
// 确保用户详情不会是undefined
|
|
||||||
const userDetail = userDetails[index] || { uin: member.uin, uid: member.uid };
|
|
||||||
return OB11Construct.groupMember(groupIdStr, member, userDetail);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 直接返回处理后的成员列表,不进行去重
|
|
||||||
return groupMembersList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseBoolean(value: boolean | string): boolean {
|
private parseBoolean(value: boolean | string): boolean {
|
||||||
@@ -56,18 +37,13 @@ export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]>
|
|||||||
let groupMembers = memberCache.get(groupIdStr);
|
let groupMembers = memberCache.get(groupIdStr);
|
||||||
|
|
||||||
if (noCache || !groupMembers) {
|
if (noCache || !groupMembers) {
|
||||||
try {
|
const data = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true).then().catch();
|
||||||
const refreshPromise = this.core.apis.GroupApi.refreshGroupMemberCache(groupIdStr, true);
|
groupMembers = memberCache.get(groupIdStr) || (await data);
|
||||||
|
if (!groupMembers) {
|
||||||
groupMembers = memberCache.get(groupIdStr) || (await refreshPromise);
|
throw new Error(`Failed to get group member list for group ${groupIdStr}`);
|
||||||
|
|
||||||
if (!groupMembers) {
|
|
||||||
throw new Error(`无法获取群 ${groupIdStr} 的成员列表`);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`获取群 ${groupIdStr} 成员列表失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupMembers;
|
return groupMembers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -81,7 +81,7 @@ import { GetGroupSystemMsg } from './system/GetSystemMsg';
|
|||||||
import { GroupPoke } from './group/GroupPoke';
|
import { GroupPoke } from './group/GroupPoke';
|
||||||
import { GetUserStatus } from './extends/GetUserStatus';
|
import { GetUserStatus } from './extends/GetUserStatus';
|
||||||
import { GetRkey } from './extends/GetRkey';
|
import { GetRkey } from './extends/GetRkey';
|
||||||
import { SetSpecialTittle } from './extends/SetSpecialTittle';
|
import { SetSpecialTitle } from './extends/SetSpecialTitle';
|
||||||
import { GetGroupShutList } from './group/GetGroupShutList';
|
import { GetGroupShutList } from './group/GetGroupShutList';
|
||||||
import { GetGroupMemberList } from './group/GetGroupMemberList';
|
import { GetGroupMemberList } from './group/GetGroupMemberList';
|
||||||
import { GetGroupFileUrl } from '@/onebot/action/file/GetGroupFileUrl';
|
import { GetGroupFileUrl } from '@/onebot/action/file/GetGroupFileUrl';
|
||||||
@@ -109,10 +109,17 @@ import { ClickInlineKeyboardButton } from './extends/ClickInlineKeyboardButton';
|
|||||||
import { GetPrivateFileUrl } from './file/GetPrivateFileUrl';
|
import { GetPrivateFileUrl } from './file/GetPrivateFileUrl';
|
||||||
import { GetUnidirectionalFriendList } from './extends/GetUnidirectionalFriendList';
|
import { GetUnidirectionalFriendList } from './extends/GetUnidirectionalFriendList';
|
||||||
import SetGroupRemark from './extends/SetGroupRemark';
|
import SetGroupRemark from './extends/SetGroupRemark';
|
||||||
|
import { MoveGroupFile } from './extends/MoveGroupFile';
|
||||||
|
import { TransGroupFile } from './extends/TransGroupFile';
|
||||||
|
import { RenameGroupFile } from './extends/RenameGroupFile';
|
||||||
|
import { GetRkeyServer } from './packet/GetRkeyServer';
|
||||||
|
import { GetRkeyEx } from './packet/GetRkeyEx';
|
||||||
|
|
||||||
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
|
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
|
new GetRkeyEx(obContext, core),
|
||||||
|
new GetRkeyServer(obContext, core),
|
||||||
new SetGroupRemark(obContext, core),
|
new SetGroupRemark(obContext, core),
|
||||||
new GetGroupInfoEx(obContext, core),
|
new GetGroupInfoEx(obContext, core),
|
||||||
new FetchEmojiLike(obContext, core),
|
new FetchEmojiLike(obContext, core),
|
||||||
@@ -132,6 +139,9 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new SetGroupSign(obContext, core),
|
new SetGroupSign(obContext, core),
|
||||||
new SendGroupSign(obContext, core),
|
new SendGroupSign(obContext, core),
|
||||||
new GetClientkey(obContext, core),
|
new GetClientkey(obContext, core),
|
||||||
|
new MoveGroupFile(obContext, core),
|
||||||
|
new RenameGroupFile(obContext, core),
|
||||||
|
new TransGroupFile(obContext, core),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(obContext, core),
|
new SendLike(obContext, core),
|
||||||
new GetMsg(obContext, core),
|
new GetMsg(obContext, core),
|
||||||
@@ -215,7 +225,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new FriendPoke(obContext, core),
|
new FriendPoke(obContext, core),
|
||||||
new GetUserStatus(obContext, core),
|
new GetUserStatus(obContext, core),
|
||||||
new GetRkey(obContext, core),
|
new GetRkey(obContext, core),
|
||||||
new SetSpecialTittle(obContext, core),
|
new SetSpecialTitle(obContext, core),
|
||||||
new SetDiyOnlineStatus(obContext, core),
|
new SetDiyOnlineStatus(obContext, core),
|
||||||
// new UploadForwardMsg(obContext, core),
|
// new UploadForwardMsg(obContext, core),
|
||||||
new GetGroupShutList(obContext, core),
|
new GetGroupShutList(obContext, core),
|
||||||
|
18
src/onebot/action/packet/GetRkeyEx.ts
Normal file
18
src/onebot/action/packet/GetRkeyEx.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
|
||||||
|
export class GetRkeyEx extends GetPacketStatusDepends<void, unknown> {
|
||||||
|
override actionName = ActionName.GetRkeyEx;
|
||||||
|
|
||||||
|
async _handle() {
|
||||||
|
let rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||||
|
return rkeys.map(rkey => {
|
||||||
|
return {
|
||||||
|
type: rkey.type === 10 ? "private" : "group",
|
||||||
|
rkey: rkey.rkey,
|
||||||
|
created_at: rkey.time,
|
||||||
|
ttl: rkey.ttl,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
38
src/onebot/action/packet/GetRkeyServer.ts
Normal file
38
src/onebot/action/packet/GetRkeyServer.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||||
|
|
||||||
|
export class GetRkeyServer extends GetPacketStatusDepends<void, { private_rkey?: string; group_rkey?: string; expired_time?: number; name: string }> {
|
||||||
|
override actionName = ActionName.GetRkeyServer;
|
||||||
|
|
||||||
|
private rkeyCache: {
|
||||||
|
private_rkey?: string;
|
||||||
|
group_rkey?: string;
|
||||||
|
expired_time?: number;
|
||||||
|
name: string;
|
||||||
|
} | null = null;
|
||||||
|
private expiryTime: number | null = null;
|
||||||
|
|
||||||
|
async _handle() {
|
||||||
|
// 检查缓存是否有效
|
||||||
|
if (this.expiryTime && this.expiryTime > Math.floor(Date.now() / 1000) && this.rkeyCache) {
|
||||||
|
return this.rkeyCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取新的 Rkey
|
||||||
|
let rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||||
|
let privateRkeyItem = rkeys.filter(rkey => rkey.type === 10)[0];
|
||||||
|
let groupRkeyItem = rkeys.filter(rkey => rkey.type === 20)[0];
|
||||||
|
|
||||||
|
this.expiryTime = Math.floor(Date.now() / 1000) + Math.min(+groupRkeyItem!.ttl.toString(),+privateRkeyItem!.ttl.toString());
|
||||||
|
|
||||||
|
// 更新缓存
|
||||||
|
this.rkeyCache = {
|
||||||
|
private_rkey: privateRkeyItem ? privateRkeyItem.rkey : undefined,
|
||||||
|
group_rkey: groupRkeyItem ? groupRkeyItem.rkey : undefined,
|
||||||
|
expired_time: this.expiryTime,
|
||||||
|
name: "NapCat 4"
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.rkeyCache;
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,8 @@ export interface InvalidCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ActionName = {
|
export const ActionName = {
|
||||||
|
GetRkeyEx: 'get_rkey',
|
||||||
|
GetRkeyServer: 'get_rkey_server',
|
||||||
SetGroupRemark: 'set_group_remark',
|
SetGroupRemark: 'set_group_remark',
|
||||||
NapCat_GetPrivateFileUrl: 'get_private_file_url',
|
NapCat_GetPrivateFileUrl: 'get_private_file_url',
|
||||||
ClickInlineKeyboardButton: 'click_inline_keyboard_button',
|
ClickInlineKeyboardButton: 'click_inline_keyboard_button',
|
||||||
@@ -31,7 +33,7 @@ export const ActionName = {
|
|||||||
SetGroupCard: 'set_group_card',
|
SetGroupCard: 'set_group_card',
|
||||||
SetGroupName: 'set_group_name',
|
SetGroupName: 'set_group_name',
|
||||||
SetGroupLeave: 'set_group_leave',
|
SetGroupLeave: 'set_group_leave',
|
||||||
SetSpecialTittle: 'set_group_special_title',
|
SetSpecialTitle: 'set_group_special_title',
|
||||||
SetFriendAddRequest: 'set_friend_add_request',
|
SetFriendAddRequest: 'set_friend_add_request',
|
||||||
SetGroupAddRequest: 'set_group_add_request',
|
SetGroupAddRequest: 'set_group_add_request',
|
||||||
GetLoginInfo: 'get_login_info',
|
GetLoginInfo: 'get_login_info',
|
||||||
@@ -130,6 +132,10 @@ export const ActionName = {
|
|||||||
GetRkey: 'nc_get_rkey',
|
GetRkey: 'nc_get_rkey',
|
||||||
GetGroupShutList: 'get_group_shut_list',
|
GetGroupShutList: 'get_group_shut_list',
|
||||||
|
|
||||||
|
MoveGroupFile: 'move_group_file',
|
||||||
|
TransGroupFile: 'trans_group_file',
|
||||||
|
RenameGroupFile: 'rename_group_file',
|
||||||
|
|
||||||
GetGuildList: 'get_guild_list',
|
GetGuildList: 'get_guild_list',
|
||||||
GetGuildProfile: 'get_guild_service_profile',
|
GetGuildProfile: 'get_guild_service_profile',
|
||||||
|
|
||||||
|
@@ -15,24 +15,21 @@ export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
|
|||||||
override payloadSchema = SchemaData;
|
override payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(_payload: Payload) {
|
async _handle(_payload: Payload) {
|
||||||
// 获取好友列表
|
const buddyMap = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
|
||||||
let buddyList = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
|
const isNocache = typeof _payload.no_cache === 'string' ? _payload.no_cache === 'true' : !!_payload.no_cache;
|
||||||
const buddyArray = Array.from(buddyList.values());
|
await Promise.all(
|
||||||
|
Array.from(buddyMap.values()).map(async (buddyInfo) => {
|
||||||
// 批量并行获取用户详情
|
try {
|
||||||
const userDetailsPromises = buddyArray.map(member =>
|
const userDetail = await this.core.apis.UserApi.getUserDetailInfo(buddyInfo.coreInfo.uid, isNocache);
|
||||||
this.core.apis.UserApi.fetchUserDetailInfoV2(member.uid)
|
const data = buddyMap.get(buddyInfo.coreInfo.uid);
|
||||||
.catch(_ => {
|
if (data) {
|
||||||
return { uin: member.uin, uid: member.uid };
|
data.qqLevel = userDetail.qqLevel;
|
||||||
})
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.core.context.logger.logError('获取好友详细信息失败', error);
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
const userDetails = await Promise.all(userDetailsPromises);
|
return OB11Construct.friends(Array.from(buddyMap.values()));
|
||||||
|
|
||||||
const friendList = buddyArray.map((friend, index) => {
|
|
||||||
const userDetail = userDetails[index] || { uin: friend.uin, uid: friend.uid };
|
|
||||||
return OB11Construct.friend(friend, userDetail);
|
|
||||||
});
|
|
||||||
|
|
||||||
return friendList;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -114,7 +114,6 @@ export class OneBotGroupApi {
|
|||||||
async parseCardChangedEvent(msg: RawMessage) {
|
async parseCardChangedEvent(msg: RawMessage) {
|
||||||
if (msg.senderUin && msg.senderUin !== '0') {
|
if (msg.senderUin && msg.senderUin !== '0') {
|
||||||
const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUid, msg.senderUin);
|
const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
await this.core.apis.GroupApi.refreshGroupMemberCachePartial(msg.peerUid, msg.senderUid);
|
|
||||||
if (member && member.cardName !== msg.sendMemberName) {
|
if (member && member.cardName !== msg.sendMemberName) {
|
||||||
const newCardName = msg.sendMemberName ?? '';
|
const newCardName = msg.sendMemberName ?? '';
|
||||||
const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
||||||
@@ -130,7 +129,6 @@ export class OneBotGroupApi {
|
|||||||
|
|
||||||
async parsePaiYiPai(msg: RawMessage, jsonStr: string) {
|
async parsePaiYiPai(msg: RawMessage, jsonStr: string) {
|
||||||
const json = JSON.parse(jsonStr);
|
const json = JSON.parse(jsonStr);
|
||||||
|
|
||||||
//判断业务类型
|
//判断业务类型
|
||||||
//Poke事件
|
//Poke事件
|
||||||
const pokedetail: Array<{ uid: string }> = json.items;
|
const pokedetail: Array<{ uid: string }> = json.items;
|
||||||
@@ -151,14 +149,15 @@ export class OneBotGroupApi {
|
|||||||
async parseOtherJsonEvent(msg: RawMessage, jsonStr: string, context: InstanceContext) {
|
async parseOtherJsonEvent(msg: RawMessage, jsonStr: string, context: InstanceContext) {
|
||||||
const json = JSON.parse(jsonStr);
|
const json = JSON.parse(jsonStr);
|
||||||
const type = json.items[json.items.length - 1]?.txt;
|
const type = json.items[json.items.length - 1]?.txt;
|
||||||
|
await this.core.apis.GroupApi.refreshGroupMemberCachePartial(msg.peerUid, msg.senderUid);
|
||||||
if (type === '头衔') {
|
if (type === '头衔') {
|
||||||
const memberUin = json.items[1].param[0];
|
const memberUin = json.items[1].param[0];
|
||||||
const title = json.items[3].txt;
|
const title = json.items[3].txt;
|
||||||
context.logger.logDebug('收到群成员新头衔消息', json);
|
context.logger.logDebug('收到群成员新头衔消息', json);
|
||||||
return new OB11GroupTitleEvent(
|
return new OB11GroupTitleEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt(msg.peerUid),
|
+msg.peerUid,
|
||||||
parseInt(memberUin),
|
+memberUin,
|
||||||
title,
|
title,
|
||||||
);
|
);
|
||||||
} else if (type === '移出') {
|
} else if (type === '移出') {
|
||||||
|
@@ -34,7 +34,7 @@ import { EventType } from '@/onebot/event/OneBotEvent';
|
|||||||
import { encodeCQCode } from '@/onebot/helper/cqcode';
|
import { encodeCQCode } from '@/onebot/helper/cqcode';
|
||||||
import { uriToLocalFile } from '@/common/file';
|
import { uriToLocalFile } from '@/common/file';
|
||||||
import { RequestUtil } from '@/common/request';
|
import { RequestUtil } from '@/common/request';
|
||||||
import fsPromise, { constants } from 'node:fs/promises';
|
import fsPromise from 'node:fs/promises';
|
||||||
import { OB11FriendAddNoticeEvent } from '@/onebot/event/notice/OB11FriendAddNoticeEvent';
|
import { OB11FriendAddNoticeEvent } from '@/onebot/event/notice/OB11FriendAddNoticeEvent';
|
||||||
import { ForwardMsgBuilder } from '@/common/forward-msg-builder';
|
import { ForwardMsgBuilder } from '@/common/forward-msg-builder';
|
||||||
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
@@ -45,6 +45,7 @@ import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeE
|
|||||||
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from '@/core/packet/transformer/proto';
|
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from '@/core/packet/transformer/proto';
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||||
import { LRUCache } from '@/common/lru-cache';
|
import { LRUCache } from '@/common/lru-cache';
|
||||||
|
import { cleanTaskQueue } from '@/common/clean-task';
|
||||||
|
|
||||||
type RawToOb11Converters = {
|
type RawToOb11Converters = {
|
||||||
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
||||||
@@ -372,7 +373,8 @@ export class OneBotMsgApi {
|
|||||||
try {
|
try {
|
||||||
multiMsgs = await this.core.apis.PacketApi.pkt.operation.FetchForwardMsg(element.resId);
|
multiMsgs = await this.core.apis.PacketApi.pkt.operation.FetchForwardMsg(element.resId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.core.context.logger.logError('Protocol FetchForwardMsg fallback failed!', e);
|
this.core.context.logger.logError(`Protocol FetchForwardMsg fallback failed!
|
||||||
|
element = ${JSON.stringify(element)} , error=${e})`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,8 +446,8 @@ export class OneBotMsgApi {
|
|||||||
}
|
}
|
||||||
const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
||||||
if (!uid) throw new Error('Get Uid Error');
|
if (!uid) throw new Error('Get Uid Error');
|
||||||
const info = await this.core.apis.UserApi.fetchUserDetailInfoV2(uid);
|
const info = await this.core.apis.UserApi.getUserDetailInfo(uid);
|
||||||
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.simpleInfo?.coreInfo.nick || '');
|
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.nick || '');
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
||||||
@@ -554,7 +556,7 @@ export class OneBotMsgApi {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.voice]: async (sendMsg, context) =>
|
[OB11MessageDataType.voice]: async (sendMsg, context) =>
|
||||||
this.core.apis.FileApi.createValidSendPttElement(
|
this.core.apis.FileApi.createValidSendPttElement(context,
|
||||||
(await this.handleOb11FileLikeMessage(sendMsg, context)).path),
|
(await this.handleOb11FileLikeMessage(sendMsg, context)).path),
|
||||||
|
|
||||||
[OB11MessageDataType.json]: async ({ data: { data } }) => ({
|
[OB11MessageDataType.json]: async ({ data: { data } }) => ({
|
||||||
@@ -712,6 +714,56 @@ export class OneBotMsgApi {
|
|||||||
this.obContext = obContext;
|
this.obContext = obContext;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 解析带有JSON标记的文本
|
||||||
|
* @param text 要解析的文本
|
||||||
|
* @returns 解析后的结果数组,每个元素包含类型(text或json)和内容
|
||||||
|
*/
|
||||||
|
parseTextWithJson(text: string) {
|
||||||
|
// 匹配<{...}>格式的JSON
|
||||||
|
const regex = /<(\{.*?\})>/g;
|
||||||
|
const parts: Array<{ type: 'text' | 'json', content: string | object }> = [];
|
||||||
|
let lastIndex = 0;
|
||||||
|
let match;
|
||||||
|
|
||||||
|
// 查找所有匹配项
|
||||||
|
while ((match = regex.exec(text)) !== null) {
|
||||||
|
// 添加匹配前的文本
|
||||||
|
if (match.index > lastIndex) {
|
||||||
|
parts.push({
|
||||||
|
type: 'text',
|
||||||
|
content: text.substring(lastIndex, match.index)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加JSON部分
|
||||||
|
try {
|
||||||
|
const jsonContent = JSON.parse(match[1] ?? '');
|
||||||
|
parts.push({
|
||||||
|
type: 'json',
|
||||||
|
content: jsonContent
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// 如果JSON解析失败,作为普通文本处理
|
||||||
|
parts.push({
|
||||||
|
type: 'text',
|
||||||
|
content: match[0]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
lastIndex = regex.lastIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加最后一部分文本
|
||||||
|
if (lastIndex < text.length) {
|
||||||
|
parts.push({
|
||||||
|
type: 'text',
|
||||||
|
content: text.substring(lastIndex)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
async parsePrivateMsgEvent(msg: RawMessage, grayTipElement: GrayTipElement) {
|
async parsePrivateMsgEvent(msg: RawMessage, grayTipElement: GrayTipElement) {
|
||||||
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
if (grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_JSON) {
|
||||||
@@ -845,7 +897,7 @@ export class OneBotMsgApi {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resMsg.sender.nickname = (await this.core.apis.UserApi.fetchUserDetailInfoV2(msg.senderUid)).simpleInfo?.coreInfo.nick || '';
|
resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) {
|
private async handleTempGroupMessage(resMsg: OB11Message, msg: RawMessage) {
|
||||||
@@ -970,7 +1022,6 @@ export class OneBotMsgApi {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const timeout = 10000 + (totalSize / 1024 / 256 * 1000);
|
const timeout = 10000 + (totalSize / 1024 / 256 * 1000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, timeout);
|
const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, timeout);
|
||||||
if (!returnMsg) throw new Error('发送消息失败');
|
if (!returnMsg) throw new Error('发送消息失败');
|
||||||
@@ -983,18 +1034,19 @@ export class OneBotMsgApi {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error((error as Error).message);
|
throw new Error((error as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
setTimeout(async () => {
|
cleanTaskQueue.addFiles(deleteAfterSentFiles, timeout);
|
||||||
const deletePromises = deleteAfterSentFiles.map(async file => {
|
// setTimeout(async () => {
|
||||||
try {
|
// const deletePromises = deleteAfterSentFiles.map(async file => {
|
||||||
if (await fsPromise.access(file, constants.W_OK).then(() => true).catch(() => false)) {
|
// try {
|
||||||
await fsPromise.unlink(file);
|
// if (await fsPromise.access(file, constants.W_OK).then(() => true).catch(() => false)) {
|
||||||
}
|
// await fsPromise.unlink(file);
|
||||||
} catch (e) {
|
// }
|
||||||
this.core.context.logger.logError('发送消息删除文件失败', e);
|
// } catch (e) {
|
||||||
}
|
// this.core.context.logger.logError('发送消息删除文件失败', e);
|
||||||
});
|
// }
|
||||||
await Promise.all(deletePromises);
|
// });
|
||||||
}, 60000);
|
// await Promise.all(deletePromises);
|
||||||
|
// }, 60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1213,6 +1265,41 @@ export class OneBotMsgApi {
|
|||||||
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
||||||
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
||||||
}
|
}
|
||||||
|
// else if (SysMessage.contentHead.type == 732 && SysMessage.contentHead.subType == 16 && SysMessage.body?.msgContent) {
|
||||||
|
// let data_wrap = PBString(2);
|
||||||
|
// let user_wrap = PBUint64(5);
|
||||||
|
// let group_wrap = PBUint64(4);
|
||||||
|
|
||||||
|
// ProtoBuf(class extends ProtoBufBase {
|
||||||
|
// group = group_wrap;
|
||||||
|
// content = ProtoBufIn(5, { data: data_wrap, user: user_wrap });
|
||||||
|
// }).decode(SysMessage.body?.msgContent.slice(7));
|
||||||
|
// let xml_data = UnWrap(data_wrap);
|
||||||
|
// let group = UnWrap(group_wrap).toString();
|
||||||
|
// //let user = UnWrap(user_wrap).toString();
|
||||||
|
// const parsedParts = this.parseTextWithJson(xml_data);
|
||||||
|
// //解析JSON
|
||||||
|
// if (parsedParts[1] && parsedParts[3]) {
|
||||||
|
// let set_user_id: string = (parsedParts[1].content as { data: string }).data;
|
||||||
|
// let uid = await this.core.apis.UserApi.getUidByUinV2(set_user_id);
|
||||||
|
// let new_title: string = (parsedParts[3].content as { text: string }).text;
|
||||||
|
// console.log(this.core.apis.GroupApi.groupMemberCache.get(group)?.get(uid)?.memberSpecialTitle, new_title)
|
||||||
|
// if (this.core.apis.GroupApi.groupMemberCache.get(group)?.get(uid)?.memberSpecialTitle == new_title) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// await this.core.apis.GroupApi.refreshGroupMemberCachePartial(group, uid);
|
||||||
|
// //let json_data_1_url_search = new URL((parsedParts[3].content as { url: string }).url).searchParams;
|
||||||
|
// //let is_new: boolean = json_data_1_url_search.get('isnew') === '1';
|
||||||
|
|
||||||
|
// //console.log(group, set_user_id, is_new, new_title);
|
||||||
|
// return new GroupMemberTitle(
|
||||||
|
// this.core,
|
||||||
|
// +group,
|
||||||
|
// +set_user_id,
|
||||||
|
// new_title
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { calcQQLevel } from '@/common/helper';
|
import { calcQQLevel } from '@/common/helper';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex, UserV2 } from '@/core';
|
import { FriendV2, Group, GroupFileInfoUpdateParamType, GroupMember, SelfInfo, NTSex } from '@/core';
|
||||||
import {
|
import {
|
||||||
OB11Group,
|
OB11Group,
|
||||||
OB11GroupFile,
|
OB11GroupFile,
|
||||||
@@ -14,7 +14,7 @@ export class OB11Construct {
|
|||||||
static selfInfo(selfInfo: SelfInfo): OB11User {
|
static selfInfo(selfInfo: SelfInfo): OB11User {
|
||||||
return {
|
return {
|
||||||
user_id: +selfInfo.uin,
|
user_id: +selfInfo.uin,
|
||||||
nickname: selfInfo.simpleInfo?.coreInfo.nick ?? '',
|
nickname: selfInfo.nick,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ export class OB11Construct {
|
|||||||
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,info:UserV2): OB11User {
|
static friend(friends: FriendV2): OB11User {
|
||||||
return {
|
return {
|
||||||
birthday_year: friends.baseInfo.birthday_year,
|
birthday_year: friends.baseInfo.birthday_year,
|
||||||
birthday_month: friends.baseInfo.birthday_month,
|
birthday_month: friends.baseInfo.birthday_month,
|
||||||
@@ -47,8 +47,7 @@ export class OB11Construct {
|
|||||||
nickname: friends.coreInfo.nick ?? '',
|
nickname: friends.coreInfo.nick ?? '',
|
||||||
remark: friends.coreInfo.remark ?? friends.coreInfo.nick,
|
remark: friends.coreInfo.remark ?? friends.coreInfo.nick,
|
||||||
sex: this.sex(friends.baseInfo.sex),
|
sex: this.sex(friends.baseInfo.sex),
|
||||||
level: calcQQLevel(info?.commonExt?.qqLevel) || 0,
|
level: 0,
|
||||||
qid: friends.baseInfo.qid,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
static groupMemberRole(role: number): OB11GroupMemberRole | undefined {
|
static groupMemberRole(role: number): OB11GroupMemberRole | undefined {
|
||||||
@@ -69,20 +68,20 @@ export class OB11Construct {
|
|||||||
}[sex] || OB11UserSex.unknown;
|
}[sex] || OB11UserSex.unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
static groupMember(group_id: string, member: GroupMember, info: UserV2): OB11GroupMember {
|
static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
|
||||||
return {
|
return {
|
||||||
group_id: +group_id,
|
group_id: +group_id,
|
||||||
user_id: +member.uin,
|
user_id: +member.uin,
|
||||||
nickname: member.nick,
|
nickname: member.nick,
|
||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
sex: this.sex(info?.simpleInfo?.baseInfo.sex),
|
sex: this.sex(member.sex),
|
||||||
age: info?.simpleInfo?.baseInfo.age ?? 0,
|
age: member.age ?? 0,
|
||||||
area: info?.commonExt?.address,
|
area: '',
|
||||||
level: member.memberRealLevel?.toString() ?? '0',
|
level: member.memberRealLevel?.toString() ?? '0',
|
||||||
qq_level: info?.commonExt?.qqLevel && calcQQLevel(info.commonExt.qqLevel) || 0,
|
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
||||||
join_time: +member.joinTime,
|
join_time: +member.joinTime,
|
||||||
last_sent_time: +member.lastSpeakTime,
|
last_sent_time: +member.lastSpeakTime,
|
||||||
title_expire_time: +member.specialTitleExpireTime,
|
title_expire_time: 0,
|
||||||
unfriendly: false,
|
unfriendly: false,
|
||||||
card_changeable: true,
|
card_changeable: true,
|
||||||
is_robot: member.isRobot,
|
is_robot: member.isRobot,
|
||||||
@@ -94,6 +93,7 @@ export class OB11Construct {
|
|||||||
|
|
||||||
static group(group: Group): OB11Group {
|
static group(group: Group): OB11Group {
|
||||||
return {
|
return {
|
||||||
|
group_all_shut: (+group.groupShutupExpireTime > 0 )? -1 : 0,
|
||||||
group_remark: group.remarkName,
|
group_remark: group.remarkName,
|
||||||
group_id: +group.groupCode,
|
group_id: +group.groupCode,
|
||||||
group_name: group.groupName,
|
group_name: group.groupName,
|
||||||
|
@@ -97,13 +97,13 @@ export class NapCatOneBot11Adapter {
|
|||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
async InitOneBot() {
|
async InitOneBot() {
|
||||||
|
const selfInfo = this.core.selfInfo;
|
||||||
const ob11Config = this.configLoader.configData;
|
const ob11Config = this.configLoader.configData;
|
||||||
|
|
||||||
this.core.apis.UserApi.fetchUserDetailInfoV2(this.core.selfInfo.uid)
|
this.core.apis.UserApi.getUserDetailInfo(selfInfo.uid, false)
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
this.core.selfInfo = { ...user, online: this.core.selfInfo.online };
|
selfInfo.nick = user.nick;
|
||||||
this.context.logger.setLogSelfInfo({ nick: this.core.selfInfo.simpleInfo?.coreInfo.nick ?? '', uid: this.core.selfInfo.uid });
|
this.context.logger.setLogSelfInfo(selfInfo);
|
||||||
})
|
})
|
||||||
.catch(e => this.context.logger.logError(e));
|
.catch(e => this.context.logger.logError(e));
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.initGroupListener();
|
this.initGroupListener();
|
||||||
|
|
||||||
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
|
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVesion());
|
||||||
WebUiDataRuntime.setQQLoginInfo(this.core.selfInfo);
|
WebUiDataRuntime.setQQLoginInfo(selfInfo);
|
||||||
WebUiDataRuntime.setQQLoginStatus(true);
|
WebUiDataRuntime.setQQLoginStatus(true);
|
||||||
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
|
||||||
const prev = this.configLoader.configData;
|
const prev = this.configLoader.configData;
|
||||||
|
@@ -37,7 +37,13 @@ export class OB11WebSocketClientAdapter extends IOB11NetworkAdapter<WebsocketCli
|
|||||||
}, this.config.heartInterval);
|
}, this.config.heartInterval);
|
||||||
}
|
}
|
||||||
this.isEnable = true;
|
this.isEnable = true;
|
||||||
await this.tryConnect();
|
try {
|
||||||
|
await this.tryConnect();
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.logError('[OneBot] [WebSocket Client] TryConnect Error , info -> ', error);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
export interface OB11User {
|
export interface OB11User {
|
||||||
birthday_year?: number;
|
birthday_year?: number; // 生日
|
||||||
birthday_month?: number;
|
birthday_month?: number; // 生日
|
||||||
birthday_day?: number;
|
birthday_day?: number; // 生日
|
||||||
phone_num?: string; // 手机号
|
phone_num?: string; // 手机号
|
||||||
email?: string; // 邮箱
|
email?: string; // 邮箱
|
||||||
category_id?: number; // 分组ID
|
category_id?: number; // 分组ID
|
||||||
@@ -63,6 +63,7 @@ export interface OB11GroupMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11Group {
|
export interface OB11Group {
|
||||||
|
group_all_shut: number; // 群全员禁言
|
||||||
group_remark: string; // 群备注
|
group_remark: string; // 群备注
|
||||||
group_id: number; // 群ID
|
group_id: number; // 群ID
|
||||||
group_name: string; // 群名称
|
group_name: string; // 群名称
|
||||||
|
@@ -131,6 +131,7 @@ async function handleLogin(
|
|||||||
inner_resolve({
|
inner_resolve({
|
||||||
uid: loginResult.uid,
|
uid: loginResult.uid,
|
||||||
uin: loginResult.uin,
|
uin: loginResult.uin,
|
||||||
|
nick: '',
|
||||||
online: true,
|
online: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -138,6 +139,7 @@ async function handleLogin(
|
|||||||
loginListener.onLoginConnected = () => {
|
loginListener.onLoginConnected = () => {
|
||||||
waitForNetworkConnection(loginService, logger).then(() => {
|
waitForNetworkConnection(loginService, logger).then(() => {
|
||||||
handleLoginInner(context, logger, loginService, quickLoginUin, historyLoginList).then().catch(e => logger.logError(e));
|
handleLoginInner(context, logger, loginService, quickLoginUin, historyLoginList).then().catch(e => logger.logError(e));
|
||||||
|
loginListener.onLoginConnected = () => { };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
|
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
|
||||||
@@ -221,6 +223,11 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
|
|||||||
}`);
|
}`);
|
||||||
}
|
}
|
||||||
loginService.getQRCodePicture();
|
loginService.getQRCodePicture();
|
||||||
|
try {
|
||||||
|
await WebUiDataRuntime.runWebUiConfigQuickFunction();
|
||||||
|
} catch (error) {
|
||||||
|
logger.logError('WebUi 快速登录失败 执行失败', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loginService.getLoginList().then((res) => {
|
loginService.getLoginList().then((res) => {
|
||||||
@@ -345,8 +352,8 @@ export async function NCoreInitShell() {
|
|||||||
guid,
|
guid,
|
||||||
basicInfoWrapper.QQVersionAppid,
|
basicInfoWrapper.QQVersionAppid,
|
||||||
basicInfoWrapper.getFullQQVesion(),
|
basicInfoWrapper.getFullQQVesion(),
|
||||||
selfInfo.uin ?? '',
|
selfInfo.uin,
|
||||||
selfInfo.uid ?? '',
|
selfInfo.uid,
|
||||||
dataPath,
|
dataPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -379,6 +386,7 @@ export async function NCoreInitShell() {
|
|||||||
export class NapCatShell {
|
export class NapCatShell {
|
||||||
readonly core: NapCatCore;
|
readonly core: NapCatCore;
|
||||||
readonly context: InstanceContext;
|
readonly context: InstanceContext;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
wrapper: WrapperNodeApi,
|
wrapper: WrapperNodeApi,
|
||||||
session: NodeIQQNTWrapperSession,
|
session: NodeIQQNTWrapperSession,
|
||||||
|
@@ -1,2 +1,37 @@
|
|||||||
import { NCoreInitShell } from './base';
|
import { NCoreInitShell } from './base';
|
||||||
|
import * as net from 'net'; // 引入 net 模块
|
||||||
|
import * as process from 'process';
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const pid = process.pid;
|
||||||
|
const pipePath = `\\\\.\\pipe\\NapCat_${pid}`;
|
||||||
|
try {
|
||||||
|
const pipeSocket = net.connect(pipePath, () => {
|
||||||
|
console.log(`已连接到命名管道: ${pipePath}`);
|
||||||
|
process.stdout.write = (
|
||||||
|
chunk: any,
|
||||||
|
encoding?: BufferEncoding | (() => void),
|
||||||
|
cb?: () => void
|
||||||
|
): boolean => {
|
||||||
|
if (typeof encoding === 'function') {
|
||||||
|
cb = encoding;
|
||||||
|
encoding = undefined;
|
||||||
|
}
|
||||||
|
return pipeSocket.write(chunk, encoding as BufferEncoding, cb);
|
||||||
|
};
|
||||||
|
console.log(`stdout 已重定向到命名管道: ${pipePath}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
pipeSocket.on('error', (err) => {
|
||||||
|
console.log(`连接命名管道 ${pipePath} 时出错:`, err);
|
||||||
|
});
|
||||||
|
|
||||||
|
pipeSocket.on('end', () => {
|
||||||
|
console.log('命名管道连接已关闭');
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`尝试连接命名管道 ${pipePath} 时发生异常:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
NCoreInitShell();
|
NCoreInitShell();
|
@@ -50,20 +50,21 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp
|
|||||||
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
|
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(async () => {
|
WebUiDataRuntime.setWebUiConfigQuickFunction(
|
||||||
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
async () => {
|
||||||
if (autoLoginAccount) {
|
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
||||||
try {
|
if (autoLoginAccount) {
|
||||||
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
try {
|
||||||
if (!result) {
|
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
||||||
throw new Error(message);
|
if (!result) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
||||||
}
|
}
|
||||||
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, 30000);
|
|
||||||
// ------------注册中间件------------
|
// ------------注册中间件------------
|
||||||
// 使用express的json中间件
|
// 使用express的json中间件
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
@@ -25,6 +25,9 @@ const LoginRuntime: LoginRuntimeType = {
|
|||||||
NewQQLoginList: [],
|
NewQQLoginList: [],
|
||||||
},
|
},
|
||||||
packageJson: packageJson,
|
packageJson: packageJson,
|
||||||
|
WebUiConfigQuickFunction: async () => {
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WebUiDataRuntime = {
|
export const WebUiDataRuntime = {
|
||||||
@@ -118,4 +121,11 @@ export const WebUiDataRuntime = {
|
|||||||
getQQVersion() {
|
getQQVersion() {
|
||||||
return LoginRuntime.QQVersion;
|
return LoginRuntime.QQVersion;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setWebUiConfigQuickFunction(func: LoginRuntimeType['WebUiConfigQuickFunction']): void {
|
||||||
|
LoginRuntime.WebUiConfigQuickFunction = func;
|
||||||
|
},
|
||||||
|
runWebUiConfigQuickFunction: async function () {
|
||||||
|
await LoginRuntime.WebUiConfigQuickFunction();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
1
src/webui/src/types/data.d.ts
vendored
1
src/webui/src/types/data.d.ts
vendored
@@ -9,6 +9,7 @@ interface LoginRuntimeType {
|
|||||||
QQLoginUin: string;
|
QQLoginUin: string;
|
||||||
QQLoginInfo: SelfInfo;
|
QQLoginInfo: SelfInfo;
|
||||||
QQVersion: string;
|
QQVersion: string;
|
||||||
|
WebUiConfigQuickFunction: () => Promise<void>;
|
||||||
NapCatHelper: {
|
NapCatHelper: {
|
||||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
||||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||||
|
Reference in New Issue
Block a user