mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
81a8115c56 | ||
![]() |
0ddd26bd51 | ||
![]() |
69e2133a27 | ||
![]() |
b04f85949b | ||
![]() |
667dba01ae | ||
![]() |
85a8cef628 | ||
![]() |
3099acfd00 | ||
![]() |
b00fe0b5f8 | ||
![]() |
9a64b8bdb6 | ||
![]() |
c01e493bd2 | ||
![]() |
890236af23 | ||
![]() |
ea678d805d | ||
![]() |
29699418ff | ||
![]() |
87bb36c39f | ||
![]() |
7cb85ed73c | ||
![]() |
c647771a6d | ||
![]() |
6c3d737219 | ||
![]() |
a1f38fed7a | ||
![]() |
c36bb77286 | ||
![]() |
1a1acdc3c9 | ||
![]() |
ef8e60c405 | ||
![]() |
31c1cc47bf | ||
![]() |
351fed7359 | ||
![]() |
f49e7cbe57 | ||
![]() |
7da8ea5e99 | ||
![]() |
8fa6a12a7c | ||
![]() |
1070278eaf |
@@ -1,21 +0,0 @@
|
|||||||
# v1.7.9
|
|
||||||
|
|
||||||
QQ Version: Windows 9.9.15-26702 / Linux 3.2.12-26702
|
|
||||||
|
|
||||||
## 启动的方式
|
|
||||||
Way03/Way05
|
|
||||||
|
|
||||||
## 新增与调整
|
|
||||||
1. 消息ID映射到UINT32空间
|
|
||||||
2. 回复ID验证与修复
|
|
||||||
3. 新API /fetch_emoji_like
|
|
||||||
|
|
||||||
```json5
|
|
||||||
{
|
|
||||||
"message_id": 1557274996,//消息ID
|
|
||||||
"emojiType": "1",//可以从event事件获取 一般为1或者2
|
|
||||||
"emojiId": "76"//可以从event事件获取 一个表情对应一个ID
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)
|
|
13
docs/changelogs/CHANGELOG.v1.8.3.md
Normal file
13
docs/changelogs/CHANGELOG.v1.8.3.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# v1.8.3
|
||||||
|
|
||||||
|
QQ Version: Windows 9.9.15-26702 / Linux 3.2.12-26702
|
||||||
|
|
||||||
|
## 启动的方式
|
||||||
|
Way03/Way05
|
||||||
|
|
||||||
|
## 新增与调整
|
||||||
|
1. 输入状态变更事件加入
|
||||||
|
2. Way05 支持Bat启动
|
||||||
|
|
||||||
|
|
||||||
|
新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api)
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.7.9",
|
"version": "1.8.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch:dev": "vite --mode development",
|
"watch:dev": "vite --mode development",
|
||||||
"watch:prod": "vite --mode production",
|
"watch:prod": "vite --mode production",
|
||||||
|
90
script/BootWay05.bat
Normal file
90
script/BootWay05.bat
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
@echo off
|
||||||
|
REM 检查当前会话是否具有管理员权限
|
||||||
|
openfiles >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
REM 如果不是管理员,则重新启动脚本以管理员模式运行
|
||||||
|
echo 请求管理员权限...
|
||||||
|
powershell -Command "Start-Process cmd -ArgumentList '/c %~f0 %*' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 设置当前工作目录
|
||||||
|
cd /d %~dp0
|
||||||
|
|
||||||
|
REM 获取当前目录路径
|
||||||
|
set currentPath=%cd%
|
||||||
|
set currentPath=%currentPath:\=/%
|
||||||
|
|
||||||
|
REM 生成JavaScript代码
|
||||||
|
set "jsCode=(async () =^>await import('file:///%currentPath%/napcat.mjs'))();"
|
||||||
|
|
||||||
|
REM 将JavaScript代码保存到文件中
|
||||||
|
echo %jsCode% > loadScript.js
|
||||||
|
echo JavaScript code has been generated and saved to loadScript.js
|
||||||
|
|
||||||
|
REM 设置NAPCAT_PATH环境变量为 当前目录的loadScript.js地址
|
||||||
|
set NAPCAT_PATH=%cd%\loadScript.js
|
||||||
|
|
||||||
|
REM 获取QQ路径
|
||||||
|
|
||||||
|
|
||||||
|
:loop_read
|
||||||
|
for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" /v "UninstallString"') do (
|
||||||
|
set RetString=%%b
|
||||||
|
goto :napcat_boot
|
||||||
|
)
|
||||||
|
|
||||||
|
:napcat_boot
|
||||||
|
for %%a in (%RetString%) do (
|
||||||
|
set "pathWithoutUninstall=%%~dpa"
|
||||||
|
)
|
||||||
|
|
||||||
|
SET QQPath=%pathWithoutUninstall%QQ.exe
|
||||||
|
|
||||||
|
REM 拿不到QQ路径则退出
|
||||||
|
if not exist "%QQpath%" (
|
||||||
|
echo provided QQ path is invalid: %QQpath%
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 收集dbghelp.dll路径和HASH信息
|
||||||
|
set QQdir=%~dp0
|
||||||
|
set oldDllPath=%QQdir%dbghelp.dll
|
||||||
|
set newDllPath=%currentPath%\dbghelp.dll
|
||||||
|
|
||||||
|
for /f "tokens=*" %%A in ('certutil -hashfile "%oldDllPath%" MD5') do (
|
||||||
|
if not defined oldDllHash set oldDllHash=%%A
|
||||||
|
)
|
||||||
|
for /f "tokens=*" %%A in ('certutil -hashfile "%newDllPath%" MD5') do (
|
||||||
|
if not defined newDllHash set newDllHash=%%A
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 如果文件一致则跳过
|
||||||
|
if "%oldDllHash%" neq "%newDllHash%" (
|
||||||
|
tasklist /fi "imagename eq QQ.exe" 2>nul | find /i "QQ.exe" >nul
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
REM 文件占用则退出
|
||||||
|
echo dbghelp.dll is in use, cannot continue.
|
||||||
|
) else (
|
||||||
|
REM 文件未占用则尝试覆盖
|
||||||
|
copy /y "%newDllPath%" "%oldDllPath%"
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to copy dbghelp.dll
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
) else (
|
||||||
|
echo dbghelp.dll has been copied to %QQdir%
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 带参数启动QQ
|
||||||
|
REM 判断wt是否存在,存在则通过wt启动,不存在则通过cmd启动
|
||||||
|
REM %QQPath% --enable-logging %*
|
||||||
|
where wt >nul 2>nul
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
wt "cmd" /c "%QQPath%" --enable-logging %*
|
||||||
|
) else (
|
||||||
|
%QQPath%" --enable-logging %*
|
||||||
|
)
|
93
script/BootWay05.utf8.bat
Normal file
93
script/BootWay05.utf8.bat
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
@echo off
|
||||||
|
REM 检查当前会话是否具有管理员权限
|
||||||
|
openfiles >nul 2>&1
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
REM 如果不是管理员,则重新启动脚本以管理员模式运行
|
||||||
|
echo 请求管理员权限...
|
||||||
|
where wt >nul 2>nul
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
powershell -Command "Start-Process cmd -ArgumentList ' /c %~f0 %*' -Verb RunAs"
|
||||||
|
) else (
|
||||||
|
powershell -Command "Start-Process wt -ArgumentList 'cmd /c %~f0 %*' -Verb RunAs"
|
||||||
|
)
|
||||||
|
|
||||||
|
REM wt "cmd" /c "%~f0 %*"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 设置当前工作目录
|
||||||
|
cd /d %~dp0
|
||||||
|
|
||||||
|
REM 获取当前目录路径
|
||||||
|
set currentPath=%cd%
|
||||||
|
set currentPath=%currentPath:\=/%
|
||||||
|
|
||||||
|
REM 生成JavaScript代码
|
||||||
|
set "jsCode=(async () =^>await import('file:///%currentPath%/napcat.mjs'))();"
|
||||||
|
|
||||||
|
REM 将JavaScript代码保存到文件中
|
||||||
|
echo %jsCode% > loadScript.js
|
||||||
|
echo JavaScript code has been generated and saved to loadScript.js
|
||||||
|
|
||||||
|
REM 设置NAPCAT_PATH环境变量为 当前目录的loadScript.js地址
|
||||||
|
set NAPCAT_PATH=%cd%\loadScript.js
|
||||||
|
|
||||||
|
REM 获取QQ路径
|
||||||
|
|
||||||
|
|
||||||
|
:loop_read
|
||||||
|
for /f "tokens=2*" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" /v "UninstallString"') do (
|
||||||
|
set RetString=%%b
|
||||||
|
goto :napcat_boot
|
||||||
|
)
|
||||||
|
|
||||||
|
:napcat_boot
|
||||||
|
for %%a in (%RetString%) do (
|
||||||
|
set "pathWithoutUninstall=%%~dpa"
|
||||||
|
)
|
||||||
|
|
||||||
|
SET QQPath=%pathWithoutUninstall%QQ.exe
|
||||||
|
|
||||||
|
REM 拿不到QQ路径则退出
|
||||||
|
if not exist "%QQpath%" (
|
||||||
|
echo provided QQ path is invalid: %QQpath%
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 收集dbghelp.dll路径和HASH信息
|
||||||
|
set QQdir=%~dp0
|
||||||
|
set oldDllPath=%QQdir%dbghelp.dll
|
||||||
|
set newDllPath=%currentPath%\dbghelp.dll
|
||||||
|
|
||||||
|
for /f "tokens=*" %%A in ('certutil -hashfile "%oldDllPath%" MD5') do (
|
||||||
|
if not defined oldDllHash set oldDllHash=%%A
|
||||||
|
)
|
||||||
|
for /f "tokens=*" %%A in ('certutil -hashfile "%newDllPath%" MD5') do (
|
||||||
|
if not defined newDllHash set newDllHash=%%A
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 如果文件一致则跳过
|
||||||
|
if "%oldDllHash%" neq "%newDllHash%" (
|
||||||
|
tasklist /fi "imagename eq QQ.exe" 2>nul | find /i "QQ.exe" >nul
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
REM 文件占用则退出
|
||||||
|
echo dbghelp.dll is in use, cannot continue.
|
||||||
|
) else (
|
||||||
|
REM 文件未占用则尝试覆盖
|
||||||
|
copy /y "%newDllPath%" "%oldDllPath%"
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Failed to copy dbghelp.dll
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
) else (
|
||||||
|
echo dbghelp.dll has been copied to %QQdir%
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM 带参数启动QQ
|
||||||
|
REM 判断wt是否存在,存在则通过wt启动,不存在则通过cmd启动
|
||||||
|
REM %QQPath% --enable-logging %*
|
||||||
|
chcp 65001
|
||||||
|
"%QQPath%" --enable-logging %*
|
@@ -1,6 +1,6 @@
|
|||||||
// --------------------
|
// --------------------
|
||||||
// 2024.7.3 9.9.12 BootWay.03 其余方法暂不公开(此方案为临时方案 Win平台已验证)
|
// 2024.7.3 9.9.12 BootWay.03 其余方法暂不公开(此方案为临时方案 Win平台已验证)
|
||||||
// 缺陷 (已知)
|
|
||||||
// 1.与非入侵式不同 现在破坏本体代码
|
// 1.与非入侵式不同 现在破坏本体代码
|
||||||
// 2.重启代码与正常启动代码失效
|
// 2.重启代码与正常启动代码失效
|
||||||
// 3.Win需要补丁
|
// 3.Win需要补丁
|
||||||
|
@@ -99,8 +99,10 @@ class MessageUniqueWrapper {
|
|||||||
}
|
}
|
||||||
createMsg(peer: Peer, msgId: string): number | undefined {
|
createMsg(peer: Peer, msgId: string): number | undefined {
|
||||||
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
|
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`;
|
||||||
const hash = crypto.createHash('md5').update(key);
|
const hash = crypto.createHash('md5').update(key).digest();
|
||||||
const shortId = hash.digest().readUInt32BE(0);
|
//设置第一个bit为0 保证shortId为正数
|
||||||
|
hash[0] &= 0x7f;
|
||||||
|
const shortId = hash.readInt32BE(0);
|
||||||
//减少性能损耗
|
//减少性能损耗
|
||||||
// const isExist = this.msgIdMap.getKey(shortId);
|
// const isExist = this.msgIdMap.getKey(shortId);
|
||||||
// if (isExist && isExist === msgId) {
|
// if (isExist && isExist === msgId) {
|
||||||
|
@@ -6,15 +6,15 @@ import AppidTable from '@/core/external/appid.json';
|
|||||||
import { log } from './log';
|
import { log } from './log';
|
||||||
|
|
||||||
//基础目录获取
|
//基础目录获取
|
||||||
export let QQMainPath = process.execPath;
|
export const QQMainPath = process.execPath;
|
||||||
export let QQPackageInfoPath: string = path.join(path.dirname(QQMainPath), 'resources', 'app', 'package.json');
|
export const QQPackageInfoPath: string = path.join(path.dirname(QQMainPath), 'resources', 'app', 'package.json');
|
||||||
export let QQVersionConfigPath: string | undefined = getQQVersionConfigPath(QQMainPath);
|
export const QQVersionConfigPath: string | undefined = getQQVersionConfigPath(QQMainPath);
|
||||||
|
|
||||||
//基础信息获取 无快更则启用默认模板填充
|
//基础信息获取 无快更则启用默认模板填充
|
||||||
export let isQuickUpdate: boolean = !!QQVersionConfigPath;
|
export const isQuickUpdate: boolean = !!QQVersionConfigPath;
|
||||||
export let QQVersionConfig: QQVersionConfigType = isQuickUpdate ? JSON.parse(fs.readFileSync(QQVersionConfigPath!).toString()) : getDefaultQQVersionConfigInfo();
|
export const QQVersionConfig: QQVersionConfigType = isQuickUpdate ? JSON.parse(fs.readFileSync(QQVersionConfigPath!).toString()) : getDefaultQQVersionConfigInfo();
|
||||||
export let QQPackageInfo: QQPackageInfoType = JSON.parse(fs.readFileSync(QQPackageInfoPath).toString());
|
export const QQPackageInfo: QQPackageInfoType = JSON.parse(fs.readFileSync(QQPackageInfoPath).toString());
|
||||||
export let { appid: QQVersionAppid, qua: QQVersionQua } = getAppidV2();
|
export const { appid: QQVersionAppid, qua: QQVersionQua } = getAppidV2();
|
||||||
|
|
||||||
//基础函数
|
//基础函数
|
||||||
export function getQQBuildStr() {
|
export function getQQBuildStr() {
|
||||||
@@ -31,17 +31,18 @@ export function getQUAInternal() {
|
|||||||
return systemPlatform === 'linux' ? `V1_LNX_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B` : `V1_WIN_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B`;
|
return systemPlatform === 'linux' ? `V1_LNX_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B` : `V1_WIN_NQ_${getFullQQVesion()}_${getQQBuildStr()}_GW_B`;
|
||||||
}
|
}
|
||||||
export function getAppidV2(): { appid: string, qua: string } {
|
export function getAppidV2(): { appid: string, qua: string } {
|
||||||
let appidTbale = AppidTable as unknown as QQAppidTableType;
|
const appidTbale = AppidTable as unknown as QQAppidTableType;
|
||||||
try {
|
try {
|
||||||
let data = appidTbale[getFullQQVesion()];
|
const data = appidTbale[getFullQQVesion()];
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
log('[QQ版本兼容性检测] 版本兼容性不佳,可能会导致一些功能无法正常使用', e);
|
log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
|
||||||
}
|
}
|
||||||
// 以下是兜底措施
|
// 以下是兜底措施
|
||||||
|
log(`[QQ版本兼容性检测] ${getFullQQVesion()} 版本兼容性不佳,可能会导致一些功能无法正常使用`);
|
||||||
return { appid: systemPlatform === 'linux' ? '537237950' : '537237765', qua: getQUAInternal() };
|
return { appid: systemPlatform === 'linux' ? '537237950' : '537237765', qua: getQUAInternal() };
|
||||||
}
|
}
|
||||||
// platform_type: 3,
|
// platform_type: 3,
|
||||||
|
@@ -181,7 +181,7 @@ type Uri2LocalRes = {
|
|||||||
isLocal: boolean
|
isLocal: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uri2local(uri: string, fileName: string | null = null): Promise<Uri2LocalRes> {
|
export async function uri2local(UriOrPath: string, fileName: string | null = null): Promise<Uri2LocalRes> {
|
||||||
const res = {
|
const res = {
|
||||||
success: false,
|
success: false,
|
||||||
errMsg: '',
|
errMsg: '',
|
||||||
@@ -190,26 +190,29 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr
|
|||||||
path: '',
|
path: '',
|
||||||
isLocal: false
|
isLocal: false
|
||||||
};
|
};
|
||||||
if (!fileName) {
|
if (!fileName) fileName = randomUUID();
|
||||||
fileName = randomUUID();
|
let filePath = path.join(getTempDir(), fileName);//临时目录
|
||||||
}
|
|
||||||
let filePath = path.join(getTempDir(), fileName);
|
|
||||||
let url = null;
|
let url = null;
|
||||||
|
//区分path和uri
|
||||||
try {
|
try {
|
||||||
url = new URL(uri);
|
if (fs.existsSync(UriOrPath)) url = new URL('file://' + UriOrPath);
|
||||||
} catch (e: any) {
|
} catch (error: any) { }
|
||||||
res.errMsg = `uri ${uri} 解析失败,` + e.toString() + ` 可能${uri}不存在`;
|
try {
|
||||||
|
url = new URL(UriOrPath);
|
||||||
|
} catch (error: any) { }
|
||||||
|
|
||||||
|
//验证url
|
||||||
|
if (!url) {
|
||||||
|
res.errMsg = `UriOrPath ${UriOrPath} 解析失败,可能${UriOrPath}不存在`;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log("uri protocol", url.protocol, uri);
|
|
||||||
if (url.protocol == 'base64:') {
|
if (url.protocol == 'base64:') {
|
||||||
// base64转成文件
|
// base64转成文件
|
||||||
const base64Data = uri.split('base64://')[1];
|
const base64Data = UriOrPath.split('base64://')[1];
|
||||||
try {
|
try {
|
||||||
const buffer = Buffer.from(base64Data, 'base64');
|
const buffer = Buffer.from(base64Data, 'base64');
|
||||||
fs.writeFileSync(filePath, buffer);
|
fs.writeFileSync(filePath, buffer);
|
||||||
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
res.errMsg = 'base64文件下载失败,' + e.toString();
|
res.errMsg = 'base64文件下载失败,' + e.toString();
|
||||||
return res;
|
return res;
|
||||||
@@ -218,7 +221,7 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr
|
|||||||
// 下载文件
|
// 下载文件
|
||||||
let buffer: Buffer | null = null;
|
let buffer: Buffer | null = null;
|
||||||
try {
|
try {
|
||||||
buffer = await httpDownload(uri);
|
buffer = await httpDownload(UriOrPath);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
res.errMsg = `${url}下载失败,` + e.toString();
|
res.errMsg = `${url}下载失败,` + e.toString();
|
||||||
return res;
|
return res;
|
||||||
@@ -252,6 +255,7 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// 26702执行forword file文件操作 不应该在这里乱来
|
||||||
// const cache = await dbUtil.getFileCacheByName(uri);
|
// const cache = await dbUtil.getFileCacheByName(uri);
|
||||||
// if (cache) {
|
// if (cache) {
|
||||||
// filePath = cache.path;
|
// filePath = cache.path;
|
||||||
@@ -259,7 +263,6 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr
|
|||||||
// filePath = uri;
|
// filePath = uri;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
res.isLocal = true;
|
res.isLocal = true;
|
||||||
}
|
}
|
||||||
// else{
|
// else{
|
||||||
|
@@ -360,12 +360,12 @@ export async function promisePipeline(promises: Promise<any>[], callback: (resul
|
|||||||
callbackCalled = callback(result);
|
callbackCalled = callback(result);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in promise pipeline:", error);
|
console.error('Error in promise pipeline:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getQQVersionConfigPath(exePath: string = ""): string | undefined {
|
export function getQQVersionConfigPath(exePath: string = ''): string | undefined {
|
||||||
let configVersionInfoPath;
|
let configVersionInfoPath;
|
||||||
if (os.platform() !== 'linux') {
|
if (os.platform() !== 'linux') {
|
||||||
configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json');
|
configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json');
|
||||||
|
@@ -43,6 +43,7 @@ setTimeout(() => {
|
|||||||
await sleep(100);
|
await sleep(100);
|
||||||
// NTQQMsgApi.CheckSendMode().then().catch();
|
// NTQQMsgApi.CheckSendMode().then().catch();
|
||||||
loadMessageUnique().then().catch();
|
loadMessageUnique().then().catch();
|
||||||
|
//下面的代码还没摸清 不要使用
|
||||||
//let data = await napCatCore.session.getMsgService().sendSsoCmdReqByContend("LightAppSvc.mini_app_growguard.ReportExecute","1124343");
|
//let data = await napCatCore.session.getMsgService().sendSsoCmdReqByContend("LightAppSvc.mini_app_growguard.ReportExecute","1124343");
|
||||||
//console.log(data);
|
//console.log(data);
|
||||||
});
|
});
|
||||||
@@ -67,8 +68,12 @@ setTimeout(() => {
|
|||||||
// }, 25000)
|
// }, 25000)
|
||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
|
static async FetchLongMsg(peer: Peer, msgId: string) {
|
||||||
|
return napCatCore.session.getMsgService().fetchLongMsg(peer, msgId);
|
||||||
|
}
|
||||||
static async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) {
|
static async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) {
|
||||||
//console.log(peer, msgSeq, emojiId, emojiType, count);
|
//console.log(peer, msgSeq, emojiId, emojiType, count);
|
||||||
|
//注意此处emojiType 可选值一般为1-2 2好像是unicode表情dec值 大部分情况 Taged M likiowa
|
||||||
return napCatCore.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, "", false, 20)
|
return napCatCore.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, "", false, 20)
|
||||||
}
|
}
|
||||||
// static napCatCore: NapCatCore | null = null;
|
// static napCatCore: NapCatCore | null = null;
|
||||||
@@ -91,20 +96,26 @@ export class NTQQMsgApi {
|
|||||||
} | undefined> {
|
} | undefined> {
|
||||||
return napCatCore.session.getMsgService().getMultiMsg(peer, rootMsgId, parentMsgId);
|
return napCatCore.session.getMsgService().getMultiMsg(peer, rootMsgId, parentMsgId);
|
||||||
}
|
}
|
||||||
static async getLastestMsgByUids(peer: Peer, count: number = 20) {
|
static async ForwardMsg(peer: Peer, msgIds: string[]) {
|
||||||
|
return napCatCore.session.getMsgService().forwardMsg(msgIds, peer, [peer], new Map());
|
||||||
|
}
|
||||||
|
static async getLastestMsgByUids(peer: Peer, count: number = 20, isReverseOrder: boolean = false) {
|
||||||
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
|
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
|
||||||
chatInfo: peer,
|
chatInfo: peer,
|
||||||
filterMsgType: [],
|
filterMsgType: [],
|
||||||
filterSendersUid: [],
|
filterSendersUid: [],
|
||||||
filterMsgToTime: '0',
|
filterMsgToTime: '0',
|
||||||
filterMsgFromTime: '0',
|
filterMsgFromTime: '0',
|
||||||
isReverseOrder: false,
|
isReverseOrder: isReverseOrder,//此参数有点离谱 注意不是本次查询的排序 而是全部消历史信息的排序 默认false 从新消息拉取到旧消息
|
||||||
isIncludeCurrent: true,
|
isIncludeCurrent: true,
|
||||||
pageLimit: 1,
|
pageLimit: count,
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static async getMsgsByMsgId(peer: Peer, msgIds: string[]) {
|
static async getMsgsByMsgId(peer: Peer | undefined, msgIds: string[] | undefined) {
|
||||||
|
if (!peer) throw new Error('peer is not allowed');
|
||||||
|
if (!msgIds) throw new Error('msgIds is not allowed');
|
||||||
|
//Mlikiowa: 参数不合规会导致NC异常崩溃 原因是TX未对进入参数判断 对应Android标记@NotNull AndroidJADX分析可得
|
||||||
return await napCatCore.session.getMsgService().getMsgsByMsgId(peer, msgIds);
|
return await napCatCore.session.getMsgService().getMsgsByMsgId(peer, msgIds);
|
||||||
}
|
}
|
||||||
static async getSingleMsg(peer: Peer, seq: string) {
|
static async getSingleMsg(peer: Peer, seq: string) {
|
||||||
@@ -115,7 +126,7 @@ export class NTQQMsgApi {
|
|||||||
}
|
}
|
||||||
static async queryMsgsWithFilterExWithSeq(peer: Peer, msgSeq: string) {
|
static async queryMsgsWithFilterExWithSeq(peer: Peer, msgSeq: string) {
|
||||||
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
let ret = await napCatCore.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
||||||
chatInfo: peer,
|
chatInfo: peer,//此处为Peer 为关键查询参数 没有啥也没有 by mlik iowa
|
||||||
filterMsgType: [],
|
filterMsgType: [],
|
||||||
filterSendersUid: [],
|
filterSendersUid: [],
|
||||||
filterMsgToTime: '0',
|
filterMsgToTime: '0',
|
||||||
@@ -142,6 +153,7 @@ export class NTQQMsgApi {
|
|||||||
1,
|
1,
|
||||||
5000,
|
5000,
|
||||||
(groupFileListResult: onGroupFileInfoUpdateParamType) => {
|
(groupFileListResult: onGroupFileInfoUpdateParamType) => {
|
||||||
|
//Developer Mlikiowa Todo: 此处有问题 无法判断是否成功
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
GroupCode,
|
GroupCode,
|
||||||
@@ -149,9 +161,9 @@ export class NTQQMsgApi {
|
|||||||
);
|
);
|
||||||
return data[1].item;
|
return data[1].item;
|
||||||
}
|
}
|
||||||
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
static async getMsgHistory(peer: Peer, msgId: string, count: number, isReverseOrder: boolean = false) {
|
||||||
// 消息时间从旧到新
|
// 消息时间从旧到新
|
||||||
return napCatCore.session.getMsgService().getMsgsIncludeSelf(peer, msgId, count, true);
|
return napCatCore.session.getMsgService().getMsgsIncludeSelf(peer, msgId, count, isReverseOrder);
|
||||||
}
|
}
|
||||||
static async recallMsg(peer: Peer, msgIds: string[]) {
|
static async recallMsg(peer: Peer, msgIds: string[]) {
|
||||||
await napCatCore.session.getMsgService().recallMsg({
|
await napCatCore.session.getMsgService().recallMsg({
|
||||||
@@ -160,19 +172,26 @@ export class NTQQMsgApi {
|
|||||||
}, msgIds);
|
}, msgIds);
|
||||||
}
|
}
|
||||||
static async sendMsgV2(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
static async sendMsgV2(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||||
// function generateMsgId() {
|
function generateMsgId() {
|
||||||
// const timestamp = Math.floor(Date.now() / 1000);
|
const timestamp = Math.floor(Date.now() / 1000);
|
||||||
// const random = Math.floor(Math.random() * Math.pow(2, 32));
|
const random = Math.floor(Math.random() * Math.pow(2, 32));
|
||||||
// const buffer = Buffer.alloc(8);
|
const buffer = Buffer.alloc(8);
|
||||||
// buffer.writeUInt32BE(timestamp, 0);
|
buffer.writeUInt32BE(timestamp, 0);
|
||||||
// buffer.writeUInt32BE(random, 4);
|
buffer.writeUInt32BE(random, 4);
|
||||||
// const msgId = BigInt("0x" + buffer.toString('hex')).toString();
|
const msgId = BigInt("0x" + buffer.toString('hex')).toString();
|
||||||
// return msgId;
|
return msgId;
|
||||||
// }
|
}
|
||||||
// 此处有采用Hack方法 利用数据返回正确得到对应消息
|
// 此处有采用Hack方法 利用数据返回正确得到对应消息
|
||||||
// 与之前 Peer队列 MsgSeq队列 真正的MsgId并发不同
|
// 与之前 Peer队列 MsgSeq队列 真正的MsgId并发不同
|
||||||
// 谨慎采用 目前测试暂无问题 Developer.Mlikiowa
|
// 谨慎采用 目前测试暂无问题 Developer.Mlikiowa
|
||||||
let msgId = await NTQQMsgApi.getMsgUnique(peer.chatType, await NTQQMsgApi.getServerTime());
|
let msgId: string;
|
||||||
|
try {
|
||||||
|
msgId = await NTQQMsgApi.getMsgUnique(peer.chatType, await NTQQMsgApi.getServerTime());
|
||||||
|
} catch (error) {
|
||||||
|
//if (!napCatCore.session.getMsgService()['generateMsgUniqueId'])
|
||||||
|
//兜底识别策略V2
|
||||||
|
msgId = generateMsgId().toString();
|
||||||
|
}
|
||||||
let data = await NTEventDispatch.CallNormalEvent<
|
let data = await NTEventDispatch.CallNormalEvent<
|
||||||
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
||||||
(msgList: RawMessage[]) => void
|
(msgList: RawMessage[]) => void
|
||||||
|
@@ -731,10 +731,12 @@ export interface MultiForwardMsgElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface RawMessage {
|
export interface RawMessage {
|
||||||
|
parentMsgPeer: Peer;
|
||||||
|
parentMsgIdList:string[];
|
||||||
|
id?: number;//扩展字段 用于处理OB11 ID
|
||||||
guildId: string;
|
guildId: string;
|
||||||
msgRandom: string;
|
msgRandom: string;
|
||||||
// int32, 自己维护的消息id
|
|
||||||
id?: number;
|
|
||||||
|
|
||||||
msgId: string;
|
msgId: string;
|
||||||
|
|
||||||
|
8
src/core/src/external/appid.json
vendored
8
src/core/src/external/appid.json
vendored
@@ -11,6 +11,10 @@
|
|||||||
"appid": 537237950,
|
"appid": 537237950,
|
||||||
"qua": "V1_LNX_NQ_3.2.12_26702_GW_B"
|
"qua": "V1_LNX_NQ_3.2.12_26702_GW_B"
|
||||||
},
|
},
|
||||||
|
"3.2.12-26740": {
|
||||||
|
"appid": 537237950,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.15_26740_GW_B"
|
||||||
|
},
|
||||||
"9.9.11-24815": {
|
"9.9.11-24815": {
|
||||||
"appid": 537226656,
|
"appid": 537226656,
|
||||||
"qua": "V1_WIN_NQ_9.9.11_24815_GW_B"
|
"qua": "V1_WIN_NQ_9.9.11_24815_GW_B"
|
||||||
@@ -38,5 +42,9 @@
|
|||||||
"9.9.15-26702": {
|
"9.9.15-26702": {
|
||||||
"appid": 537237765,
|
"appid": 537237765,
|
||||||
"qua": "V1_WIN_NQ_9.9.15_26702_GW_B"
|
"qua": "V1_WIN_NQ_9.9.15_26702_GW_B"
|
||||||
|
},
|
||||||
|
"9.9.15-26740": {
|
||||||
|
"appid": 537237765,
|
||||||
|
"qua": "V1_WIN_NQ_9.9.15_26702_GW_B"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -77,7 +77,7 @@ export const sessionConfig: WrapperSessionInitConfig | any = {};
|
|||||||
export async function genSessionConfig(selfUin: string, selfUid: string, account_path: string): Promise<WrapperSessionInitConfig> {
|
export async function genSessionConfig(selfUin: string, selfUid: string, account_path: string): Promise<WrapperSessionInitConfig> {
|
||||||
const downloadPath = path.join(account_path, 'NapCat', 'temp');
|
const downloadPath = path.join(account_path, 'NapCat', 'temp');
|
||||||
fs.mkdirSync(downloadPath, { recursive: true });
|
fs.mkdirSync(downloadPath, { recursive: true });
|
||||||
let guid: string = await getMachineId();
|
let guid: string = await getMachineId();//26702 支持JS获取guid值 在LoginService中获取 TODO mlikiow a
|
||||||
//console.log(guid);
|
//console.log(guid);
|
||||||
// guid = '52afb776-82f6-4e59-9d38-44705b112d0a';
|
// guid = '52afb776-82f6-4e59-9d38-44705b112d0a';
|
||||||
//let guid: string = await getMachineId();
|
//let guid: string = await getMachineId();
|
||||||
|
@@ -15,6 +15,7 @@ export class FetchCustomFace extends BaseAction<Payload, string[]> {
|
|||||||
actionName = ActionName.FetchCustomFace;
|
actionName = ActionName.FetchCustomFace;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
|
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
||||||
const ret = await NTQQMsgApi.fetchFavEmojiList(payload.count || 48);
|
const ret = await NTQQMsgApi.fetchFavEmojiList(payload.count || 48);
|
||||||
return ret.emojiInfoList.map(e => e.url);
|
return ret.emojiInfoList.map(e => e.url);
|
||||||
}
|
}
|
||||||
|
@@ -5,28 +5,28 @@ import { ActionName } from '../types';
|
|||||||
import { NTQQMsgApi } from '@/core/apis';
|
import { NTQQMsgApi } from '@/core/apis';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
user_id: { type: 'string' },
|
user_id: { type: 'string' },
|
||||||
group_id: { type: 'string' },
|
group_id: { type: 'string' },
|
||||||
emojiId: { type: 'string' },
|
emojiId: { type: 'string' },
|
||||||
emojiType: { type: 'string' },
|
emojiType: { type: 'string' },
|
||||||
message_id: { type: ['string', 'number'] },
|
message_id: { type: ['string', 'number'] },
|
||||||
count: { type: 'number' }
|
count: { type: 'number' }
|
||||||
},
|
},
|
||||||
required: ['emojiId', 'emojiType', 'message_id']
|
required: ['emojiId', 'emojiType', 'message_id']
|
||||||
} as const satisfies JSONSchema;
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export class FetchEmojioLike extends BaseAction<Payload, any> {
|
export class FetchEmojioLike extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.FetchEmojioLike;
|
actionName = ActionName.FetchEmojioLike;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||||
if(!msgIdPeer) throw new Error('消息不存在');
|
if(!msgIdPeer) throw new Error('消息不存在');
|
||||||
let msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||||
const ret = await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer,msg.msgSeq,payload.emojiId,payload.emojiType,payload.count);
|
const ret = await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer,msg.msgSeq,payload.emojiId,payload.emojiType,payload.count);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,8 @@ export class OCRImage extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.OCRImage;
|
actionName = ActionName.OCRImage;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const { path, isLocal, errMsg } = (await uri2local(payload.image));
|
const { path, isLocal, errMsg,success } = (await uri2local(payload.image));
|
||||||
if (errMsg) {
|
if (!success) {
|
||||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
|
@@ -26,8 +26,8 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
const { path, isLocal, errMsg } = (await uri2local(payload.file));
|
const { path, isLocal, errMsg,success } = (await uri2local(payload.file));
|
||||||
if (errMsg) {
|
if (!success) {
|
||||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
|
@@ -24,8 +24,8 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const { path, isLocal, errMsg } = (await uri2local(payload.file));
|
const { path, isLocal, errMsg,success } = (await uri2local(payload.file));
|
||||||
if (errMsg) {
|
if (!success) {
|
||||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
|
@@ -1,11 +1,7 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName, BaseCheckResult } from '../types';
|
import { ActionName, BaseCheckResult } from '../types';
|
||||||
import * as fs from 'node:fs';
|
|
||||||
import { NTQQUserApi } from '@/core/apis/user';
|
|
||||||
import { checkFileReceived, uri2local } from '@/common/utils/file';
|
|
||||||
import { napCatCore, NTQQGroupApi } from '@/core';
|
import { napCatCore, NTQQGroupApi } from '@/core';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
// import { log } from "../../../common/utils";
|
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@@ -10,9 +10,7 @@ const SchemaData = {
|
|||||||
properties: {
|
properties: {
|
||||||
words: {
|
words: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: {
|
items: { type: 'string' }
|
||||||
type: 'string',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
required: ['words'],
|
required: ['words'],
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { OB11Message, OB11User } from '../../types';
|
import { OB11Message, OB11User } from '../../types';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { ChatType } from '@/core/entities';
|
import { ChatType, RawMessage } from '@/core/entities';
|
||||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||||
import { OB11Constructor } from '../../constructor';
|
import { OB11Constructor } from '../../constructor';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
@@ -17,9 +17,10 @@ const SchemaData = {
|
|||||||
properties: {
|
properties: {
|
||||||
user_id: { type: ['number', 'string'] },
|
user_id: { type: ['number', 'string'] },
|
||||||
message_seq: { type: 'number' },
|
message_seq: { type: 'number' },
|
||||||
count: { type: 'number' }
|
count: { type: 'number' },
|
||||||
|
reverseOrder: { type: 'boolean' }
|
||||||
},
|
},
|
||||||
required: ['user_id', 'message_seq', 'count']
|
required: ['user_id']
|
||||||
} as const satisfies JSONSchema;
|
} as const satisfies JSONSchema;
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
@@ -28,21 +29,28 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
actionName = ActionName.GetFriendMsgHistory;
|
actionName = ActionName.GetFriendMsgHistory;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<Response> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
|
//处理参数
|
||||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||||
if (!uid) {
|
const MsgCount = payload.count || 20;
|
||||||
throw `记录${payload.user_id}不存在`;
|
const isReverseOrder = payload.reverseOrder || true;
|
||||||
}
|
if (!uid) throw `记录${payload.user_id}不存在`;
|
||||||
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq))?.MsgId || '0';
|
|
||||||
const friend = await NTQQFriendApi.isBuddy(uid);
|
const friend = await NTQQFriendApi.isBuddy(uid);
|
||||||
const historyResult = (await NTQQMsgApi.getMsgHistory({
|
const peer = { chatType: friend ? ChatType.friend : ChatType.temp, peerUid: uid };
|
||||||
chatType: friend ? ChatType.friend : ChatType.temp,
|
|
||||||
peerUid: uid
|
//拉取消息
|
||||||
}, startMsgId, parseInt(payload.count?.toString()) || 20));
|
let msgList: RawMessage[];
|
||||||
//logDebug(historyResult);
|
if (!payload.message_seq || payload.message_seq == 0) {
|
||||||
const msgList = historyResult.msgList;
|
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||||
|
} else {
|
||||||
|
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||||
|
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||||
|
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||||
|
}
|
||||||
|
if(isReverseOrder) msgList.reverse();
|
||||||
await Promise.all(msgList.map(async msg => {
|
await Promise.all(msgList.map(async msg => {
|
||||||
msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||||
}));
|
}));
|
||||||
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
|
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ import BaseAction from '../BaseAction';
|
|||||||
import { OB11Message, OB11User } from '../../types';
|
import { OB11Message, OB11User } from '../../types';
|
||||||
import { getGroup, groups } from '@/core/data';
|
import { getGroup, groups } from '@/core/data';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { ChatType, RawMessage } from '@/core/entities';
|
import { ChatType, Peer, RawMessage } from '@/core/entities';
|
||||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||||
import { OB11Constructor } from '../../constructor';
|
import { OB11Constructor } from '../../constructor';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
@@ -16,7 +16,8 @@ const SchemaData = {
|
|||||||
properties: {
|
properties: {
|
||||||
group_id: { type: ['number', 'string'] },
|
group_id: { type: ['number', 'string'] },
|
||||||
message_seq: { type: 'number' },
|
message_seq: { type: 'number' },
|
||||||
count: { type: 'number' }
|
count: { type: 'number' },
|
||||||
|
reverseOrder: { type: 'boolean' }
|
||||||
},
|
},
|
||||||
required: ['group_id']
|
required: ['group_id']
|
||||||
} as const satisfies JSONSchema;
|
} as const satisfies JSONSchema;
|
||||||
@@ -27,25 +28,28 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload): Promise<Response> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
|
//处理参数
|
||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (!group) {
|
const isReverseOrder = payload.reverseOrder || true;
|
||||||
throw `群${payload.group_id}不存在`;
|
const MsgCount = payload.count || 20;
|
||||||
}
|
const peer: Peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||||
let targetMsgShortId, count = parseInt(payload.count?.toString() ?? '20');
|
if (!group) throw `群${payload.group_id}不存在`;
|
||||||
const peer = {
|
|
||||||
chatType: ChatType.group,
|
//拉取消息
|
||||||
peerUid: group.groupCode
|
|
||||||
};
|
|
||||||
let msgList: RawMessage[];
|
let msgList: RawMessage[];
|
||||||
if (!payload.message_seq) {
|
if (!payload.message_seq || payload.message_seq == 0) {
|
||||||
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, count)).msgList;
|
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||||
} else {
|
} else {
|
||||||
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(targetMsgShortId ?? (payload.message_seq ?? 0)))?.MsgId || '0';
|
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||||
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, count)).msgList;
|
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||||
|
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||||
}
|
}
|
||||||
|
if(isReverseOrder) msgList.reverse();
|
||||||
await Promise.all(msgList.map(async msg => {
|
await Promise.all(msgList.map(async msg => {
|
||||||
msg.id = await MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
|
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
group_id: { type: [ 'number' , 'string' ] },
|
group_id: { type: ['number', 'string'] },
|
||||||
content: { type: 'string' },
|
content: { type: 'string' },
|
||||||
image: { type: 'string' },
|
image: { type: 'string' },
|
||||||
pinned: { type: 'number' },
|
pinned: { type: 'number' },
|
||||||
@@ -24,8 +24,8 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
|||||||
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
||||||
if (payload.image) {
|
if (payload.image) {
|
||||||
//公告图逻辑
|
//公告图逻辑
|
||||||
const { errMsg, path, isLocal } = (await uri2local(payload.image));
|
const { errMsg, path, isLocal, success } = (await uri2local(payload.image));
|
||||||
if (errMsg) {
|
if (!success) {
|
||||||
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (!path) {
|
if (!path) {
|
||||||
|
@@ -34,7 +34,7 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
|||||||
file = `file://${file}`;
|
file = `file://${file}`;
|
||||||
}
|
}
|
||||||
const downloadResult = await uri2local(file);
|
const downloadResult = await uri2local(file);
|
||||||
if (downloadResult.errMsg) {
|
if (!downloadResult.success) {
|
||||||
throw new Error(downloadResult.errMsg);
|
throw new Error(downloadResult.errMsg);
|
||||||
}
|
}
|
||||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name, payload.folder_id);
|
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name, payload.folder_id);
|
||||||
|
@@ -41,7 +41,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
|
|||||||
file = `file://${file}`;
|
file = `file://${file}`;
|
||||||
}
|
}
|
||||||
const downloadResult = await uri2local(file);
|
const downloadResult = await uri2local(file);
|
||||||
if (downloadResult.errMsg) {
|
if (!downloadResult.success) {
|
||||||
throw new Error(downloadResult.errMsg);
|
throw new Error(downloadResult.errMsg);
|
||||||
}
|
}
|
||||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
||||||
|
@@ -19,7 +19,7 @@ class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
|||||||
actionName = ActionName.GetGroupList;
|
actionName = ActionName.GetGroupList;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
|
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
|
||||||
return OB11Constructor.groups(groupList);
|
return OB11Constructor.groups(groupList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,11 +26,11 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
||||||
let uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
throw (`Uin2Uid Error ${payload.user_id}不存在`);
|
throw (`Uin2Uid Error ${payload.user_id}不存在`);
|
||||||
}
|
}
|
||||||
let member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache);
|
const member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache);
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw (`群(${payload.group_id})成员${payload.user_id}不存在`);
|
throw (`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
const date = Math.round(Date.now() / 1000);
|
const date = Math.round(Date.now() / 1000);
|
||||||
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
|
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
|
||||||
if (!requireMinNTQQBuild('26702')) {
|
if (!requireMinNTQQBuild('26702')) {
|
||||||
let SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), selfInfo.uid, isNocache);
|
const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), selfInfo.uid, isNocache);
|
||||||
let isPrivilege = false;
|
let isPrivilege = false;
|
||||||
if (SelfInfoInGroup) {
|
if (SelfInfoInGroup) {
|
||||||
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
|
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
|
||||||
|
@@ -28,7 +28,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
if (requireMinNTQQBuild('26702')) {
|
if (requireMinNTQQBuild('26702')) {
|
||||||
let V2Data = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), payload.user_id.toString(), payload.no_cache == true || payload.no_cache === 'true');
|
const V2Data = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), payload.user_id.toString(), payload.no_cache == true || payload.no_cache === 'true');
|
||||||
if (V2Data) {
|
if (V2Data) {
|
||||||
return OB11Constructor.groupMember(payload.group_id.toString(), V2Data);
|
return OB11Constructor.groupMember(payload.group_id.toString(), V2Data);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -30,7 +30,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
|||||||
if (!group) {
|
if (!group) {
|
||||||
throw (`群${payload.group_id}不存在`);
|
throw (`群${payload.group_id}不存在`);
|
||||||
}
|
}
|
||||||
let groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
const groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
||||||
let _groupMembers = Array.from(groupMembers.values())
|
let _groupMembers = Array.from(groupMembers.values())
|
||||||
.map(item => { return OB11Constructor.groupMember(group.groupCode, item); });
|
.map(item => { return OB11Constructor.groupMember(group.groupCode, item); });
|
||||||
|
|
||||||
|
@@ -3,12 +3,15 @@ import { ActionName } from '../types';
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
|
import { sleep } from '@/common/utils/helper';
|
||||||
|
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||||
|
import { NodeIKernelMsgListener } from '@/core';
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
message_id: {
|
message_id: {
|
||||||
oneOf:[
|
oneOf: [
|
||||||
{ type: 'number' },
|
{ type: 'number' },
|
||||||
{ type: 'string' }
|
{ type: 'string' }
|
||||||
]
|
]
|
||||||
@@ -23,9 +26,27 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
|||||||
actionName = ActionName.DeleteMsg;
|
actionName = ActionName.DeleteMsg;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
const msg = await MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
||||||
if (msg) {
|
if (msg) {
|
||||||
|
let ret = NTEventDispatch.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>
|
||||||
|
(
|
||||||
|
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||||
|
1,
|
||||||
|
5000,
|
||||||
|
(msgs) => {
|
||||||
|
if (msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
).catch(e => new Promise<undefined>((resolve, reject) => { resolve(undefined) }));
|
||||||
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
||||||
|
let data = await ret;
|
||||||
|
if (!data) {
|
||||||
|
throw new Error('Recall failed');
|
||||||
|
}
|
||||||
|
//await sleep(100);
|
||||||
|
//await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import {
|
|||||||
IdMusicSignPostData,
|
IdMusicSignPostData,
|
||||||
NTQQFileApi,
|
NTQQFileApi,
|
||||||
NTQQMsgApi,
|
NTQQMsgApi,
|
||||||
|
Peer,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendMessageElement,
|
SendMessageElement,
|
||||||
SendMsgElementConstructor,
|
SendMsgElementConstructor,
|
||||||
@@ -17,19 +18,19 @@ import { uri2local } from '@/common/utils/file';
|
|||||||
import { ob11Config } from '@/onebot11/config';
|
import { ob11Config } from '@/onebot11/config';
|
||||||
import { RequestUtil } from '@/common/utils/request';
|
import { RequestUtil } from '@/common/utils/request';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
|
console.log(process.pid)
|
||||||
export type MessageContext = {
|
export type MessageContext = {
|
||||||
group?: Group,
|
|
||||||
deleteAfterSentFiles: string[],
|
deleteAfterSentFiles: string[],
|
||||||
|
peer:Peer
|
||||||
}
|
}
|
||||||
async function handleOb11FileLikeMessage(
|
async function handleOb11FileLikeMessage(
|
||||||
{ data: inputdata }: OB11MessageFileBase,
|
{ data: inputdata }: OB11MessageFileBase,
|
||||||
{ deleteAfterSentFiles }: MessageContext
|
{ deleteAfterSentFiles }: MessageContext
|
||||||
) {
|
) {
|
||||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url
|
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||||
const { path, isLocal, fileName, errMsg } = (await uri2local(inputdata?.url || inputdata.file));
|
const { path, isLocal, fileName, errMsg,success } = (await uri2local(inputdata?.url || inputdata.file));
|
||||||
|
|
||||||
if (errMsg) {
|
if (!success) {
|
||||||
logError('文件下载失败', errMsg);
|
logError('文件下载失败', errMsg);
|
||||||
throw Error('文件下载失败' + errMsg);
|
throw Error('文件下载失败' + errMsg);
|
||||||
}
|
}
|
||||||
@@ -52,12 +53,12 @@ const _handlers: {
|
|||||||
[OB11MessageDataType.text]: async ({ data: { text } }) => SendMsgElementConstructor.text(text),
|
[OB11MessageDataType.text]: async ({ data: { text } }) => SendMsgElementConstructor.text(text),
|
||||||
|
|
||||||
[OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => {
|
[OB11MessageDataType.at]: async ({ data: { qq: atQQ } }, context) => {
|
||||||
if (!context.group) return undefined;
|
if (!context.peer) return undefined;
|
||||||
|
|
||||||
if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员');
|
if (atQQ === 'all') return SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员');
|
||||||
|
|
||||||
// then the qq is a group member
|
// then the qq is a group member
|
||||||
const atMember = await getGroupMember(context.group.groupCode, atQQ);
|
const atMember = await getGroupMember(context.peer.peerUid, atQQ);
|
||||||
return atMember ?
|
return atMember ?
|
||||||
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) :
|
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) :
|
||||||
undefined;
|
undefined;
|
||||||
@@ -206,7 +207,7 @@ const handlers = <{
|
|||||||
|
|
||||||
export default async function createSendElements(
|
export default async function createSendElements(
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
group?: Group,
|
peer: Peer,
|
||||||
ignoreTypes: OB11MessageDataType[] = []
|
ignoreTypes: OB11MessageDataType[] = []
|
||||||
) {
|
) {
|
||||||
const deleteAfterSentFiles: string[] = [];
|
const deleteAfterSentFiles: string[] = [];
|
||||||
@@ -217,7 +218,7 @@ export default async function createSendElements(
|
|||||||
}
|
}
|
||||||
const callResult = handlers[sendMsg.type](
|
const callResult = handlers[sendMsg.type](
|
||||||
sendMsg,
|
sendMsg,
|
||||||
{ group, deleteAfterSentFiles }
|
{ peer, deleteAfterSentFiles }
|
||||||
)?.catch(undefined);
|
)?.catch(undefined);
|
||||||
callResultList.push(callResult);
|
callResultList.push(callResult);
|
||||||
}
|
}
|
||||||
@@ -228,7 +229,7 @@ export default async function createSendElements(
|
|||||||
|
|
||||||
export async function createSendElementsParallel(
|
export async function createSendElementsParallel(
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
group?: Group,
|
peer: Peer,
|
||||||
ignoreTypes: OB11MessageDataType[] = []
|
ignoreTypes: OB11MessageDataType[] = []
|
||||||
) {
|
) {
|
||||||
const deleteAfterSentFiles: string[] = [];
|
const deleteAfterSentFiles: string[] = [];
|
||||||
@@ -236,7 +237,7 @@ export async function createSendElementsParallel(
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||||
undefined :
|
undefined :
|
||||||
handlers[sendMsg.type](sendMsg, { group, deleteAfterSentFiles }))
|
handlers[sendMsg.type](sendMsg, { peer, deleteAfterSentFiles }))
|
||||||
).then(
|
).then(
|
||||||
results => results.filter(
|
results => results.filter(
|
||||||
element => element !== undefined
|
element => element !== undefined
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { ChatType, ElementType, Group, NTQQMsgApi, Peer, RawMessage, SendMessageElement } from '@/core';
|
import { ChatType, ElementType, Group, NTQQMsgApi, Peer, RawMessage, SendMessageElement } from '@/core';
|
||||||
import { OB11MessageNode } from '@/onebot11/types';
|
import { OB11MessageDataType, OB11MessageNode } from '@/onebot11/types';
|
||||||
import { selfInfo } from '@/core/data';
|
import { selfInfo } from '@/core/data';
|
||||||
import createSendElements from '@/onebot11/action/msg/SendMsg/create-send-elements';
|
import createSendElements from '@/onebot11/action/msg/SendMsg/create-send-elements';
|
||||||
import { logDebug, logError } from '@/common/utils/log';
|
import { logDebug, logError } from '@/common/utils/log';
|
||||||
@@ -24,135 +24,92 @@ async function cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
|||||||
if (sendElements.length === 0) {
|
if (sendElements.length === 0) {
|
||||||
logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//logDebug('克隆消息', sendElements);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||||
await sleep(500); // 防止风控
|
|
||||||
return nodeMsg;
|
return nodeMsg;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[], group: Group | undefined): Promise<RawMessage | null> {
|
export async function handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
||||||
const selfPeer = {
|
const selfPeer = {
|
||||||
chatType: ChatType.friend,
|
chatType: ChatType.friend,
|
||||||
peerUid: selfInfo.uid
|
peerUid: selfInfo.uid
|
||||||
};
|
};
|
||||||
let nodeMsgIds: string[] = [];
|
let nodeMsgIds: string[] = [];
|
||||||
|
|
||||||
// 先判断一遍是不是id和自定义混用
|
|
||||||
const needClone =
|
|
||||||
messageNodes.filter(node => node.data.id).length &&
|
|
||||||
messageNodes.filter(node => !node.data.id).length;
|
|
||||||
|
|
||||||
for (const messageNode of messageNodes) {
|
for (const messageNode of messageNodes) {
|
||||||
// 一个node表示一个人的消息
|
|
||||||
const nodeId = messageNode.data.id;
|
const nodeId = messageNode.data.id;
|
||||||
// 有nodeId表示一个子转发消息卡片
|
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
const nodeMsg = MessageUnique.getPeerByMsgId(nodeId);
|
//对Mgsid和OB11ID混用情况兜底
|
||||||
if (!needClone) {
|
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||||
nodeMsgIds.push(nodeMsg!.MsgId);
|
if (!nodeMsg) {
|
||||||
} else {
|
logError('转发消息失败,未找到消息', nodeId);
|
||||||
if (nodeMsg!.Peer.peerUid !== selfInfo.uid) {
|
continue;
|
||||||
// need cloning
|
|
||||||
const rawClone = await NTQQMsgApi.getMsgsByMsgId(nodeMsg?.Peer!, [nodeMsg?.MsgId!]);
|
|
||||||
const clonedMsg = await cloneMsg(rawClone.msgList[0]);
|
|
||||||
if (clonedMsg) {
|
|
||||||
nodeMsgIds.push(clonedMsg.msgId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
nodeMsgIds.push(nodeMsg.MsgId);
|
||||||
} else {
|
} else {
|
||||||
// 自定义的消息
|
// 自定义的消息
|
||||||
// 提取消息段,发给自己生成消息id
|
|
||||||
try {
|
try {
|
||||||
const { sendElements } = await createSendElements(normalize(messageNode.data.content), group);
|
let OB11Data = normalize(messageNode.data.content);
|
||||||
//logDebug('开始生成转发节点', sendElements);
|
//筛选node消息
|
||||||
const sendElementsSplit: SendMessageElement[][] = [];
|
let isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||||
let splitIndex = 0;
|
if (isNodeMsg !== 0) {
|
||||||
for (const sendElement of sendElements) {
|
if (isNodeMsg !== OB11Data.length) { logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||||
if (!sendElementsSplit[splitIndex]) {
|
const nodeMsg = await handleForwardNode(selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||||
sendElementsSplit[splitIndex] = [];
|
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId) };
|
||||||
}
|
//完成子卡片生成跳过后续
|
||||||
|
continue;
|
||||||
if (sendElement.elementType === ElementType.FILE || sendElement.elementType === ElementType.VIDEO) {
|
|
||||||
if (sendElementsSplit[splitIndex].length > 0) {
|
|
||||||
splitIndex++;
|
|
||||||
}
|
|
||||||
sendElementsSplit[splitIndex] = [sendElement];
|
|
||||||
splitIndex++;
|
|
||||||
} else {
|
|
||||||
sendElementsSplit[splitIndex].push(sendElement);
|
|
||||||
}
|
|
||||||
//logDebug(sendElementsSplit);
|
|
||||||
}
|
}
|
||||||
// log("分割后的转发节点", sendElementsSplit)
|
const { sendElements } = await createSendElements(OB11Data, destPeer);
|
||||||
|
//拆分消息
|
||||||
|
let MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
||||||
|
let SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||||
|
let AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
|
||||||
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
||||||
for (const sendElementsSplitElement of sendElementsSplit) {
|
for (const sendElementsSplitElement of AllElement) {
|
||||||
MsgNodeList.push(sendMsg(selfPeer, sendElementsSplitElement, [], true));
|
MsgNodeList.push(sendMsg(selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined) })));
|
||||||
await sleep(Math.trunc(sendElementsSplit.length / 10) * 100);
|
|
||||||
//await sleep(10);
|
|
||||||
}
|
}
|
||||||
for (const msgNode of MsgNodeList) {
|
(await Promise.allSettled(MsgNodeList)).map((result) => {
|
||||||
const result = await msgNode;
|
if (result.status === 'fulfilled' && result.value) {
|
||||||
if (result) {
|
nodeMsgIds.push(result.value.msgId);
|
||||||
nodeMsgIds.push(result.msgId);
|
MessageUnique.createMsg(selfPeer, result.value.msgId);
|
||||||
}
|
}
|
||||||
//logDebug('转发节点生成成功', result.msgId);
|
});
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logDebug('生成转发消息节点失败', e);
|
logDebug('生成转发消息节点失败', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
|
||||||
const nodeMsgArray: Array<RawMessage> = [];
|
const nodeMsgArray: Array<RawMessage> = [];
|
||||||
|
|
||||||
let srcPeer: Peer | undefined = undefined;
|
let srcPeer: Peer | undefined = undefined;
|
||||||
let needSendSelf = false;
|
let needSendSelf = false;
|
||||||
for (const msgId of nodeMsgIds) {
|
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
|
||||||
const nodeMsgPeer = await MessageUnique.getPeerByMsgId(msgId);
|
for (let msgId of nodeMsgIds) {
|
||||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer?.Peer!, [msgId])).msgList[0];
|
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
|
||||||
if (nodeMsg) {
|
if (!nodeMsgPeer) {
|
||||||
nodeMsgArray.push(nodeMsg);
|
logError('转发消息失败,未找到消息', msgId);
|
||||||
if (!srcPeer) {
|
continue;
|
||||||
srcPeer = { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
|
||||||
} else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
|
||||||
needSendSelf = true;
|
|
||||||
srcPeer = selfPeer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||||
|
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||||
|
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
|
needSendSelf = true;
|
||||||
|
}
|
||||||
|
nodeMsgArray.push(nodeMsg);
|
||||||
}
|
}
|
||||||
// logDebug('nodeMsgArray', nodeMsgArray);
|
|
||||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||||
|
let retMsgIds: string[] = [];
|
||||||
if (needSendSelf) {
|
if (needSendSelf) {
|
||||||
//logDebug('需要克隆转发消息');
|
|
||||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||||
if (msg.peerUid !== selfInfo.uid) {
|
if (msg.peerUid === selfInfo.uid) continue;
|
||||||
const clonedMsg = await cloneMsg(msg);
|
const ClonedMsg = await cloneMsg(msg);
|
||||||
if (clonedMsg) {
|
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
|
||||||
nodeMsgIds[index] = clonedMsg.msgId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
retMsgIds = nodeMsgIds;
|
||||||
}
|
}
|
||||||
// elements之间用换行符分隔
|
if (nodeMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||||
// let _sendForwardElements: SendMessageElement[] = []
|
|
||||||
// for(let i = 0; i < sendForwardElements.length; i++){
|
|
||||||
// _sendForwardElements.push(sendForwardElements[i])
|
|
||||||
// _sendForwardElements.push(SendMsgElementConstructor.text("\n\n"))
|
|
||||||
// }
|
|
||||||
// const nodeMsg = await NTQQApi.sendMsg(selfPeer, _sendForwardElements, true);
|
|
||||||
// nodeIds.push(nodeMsg.msgId)
|
|
||||||
// await sleep(500);
|
|
||||||
// 开发转发
|
|
||||||
if (nodeMsgIds.length === 0) {
|
|
||||||
throw Error('转发消息失败,生成节点为空');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
||||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
||||||
|
@@ -76,9 +76,7 @@ export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], de
|
|||||||
return returnMsg;
|
return returnMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createContext(payload: OB11PostSendMsg, contextMode: ContextMode): Promise<{
|
async function createContext(payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> {
|
||||||
peer: Peer, group?: Group
|
|
||||||
}> {
|
|
||||||
// This function determines the type of message by the existence of user_id / group_id,
|
// This function determines the type of message by the existence of user_id / group_id,
|
||||||
// not message_type.
|
// not message_type.
|
||||||
// This redundant design of Ob11 here should be blamed.
|
// This redundant design of Ob11 here should be blamed.
|
||||||
@@ -86,11 +84,8 @@ async function createContext(payload: OB11PostSendMsg, contextMode: ContextMode)
|
|||||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||||
const group = (await getGroup(payload.group_id))!; // checked before
|
const group = (await getGroup(payload.group_id))!; // checked before
|
||||||
return {
|
return {
|
||||||
peer: {
|
chatType: ChatType.group,
|
||||||
chatType: ChatType.group,
|
peerUid: group.groupCode
|
||||||
peerUid: group.groupCode
|
|
||||||
},
|
|
||||||
group: group,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||||
@@ -98,10 +93,8 @@ async function createContext(payload: OB11PostSendMsg, contextMode: ContextMode)
|
|||||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
||||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||||
return {
|
return {
|
||||||
peer: {
|
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
peerUid: Uid!
|
||||||
peerUid: Uid!
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
throw '请指定 group_id 或 user_id';
|
throw '请指定 group_id 或 user_id';
|
||||||
@@ -139,7 +132,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
||||||
const { peer, group } = await createContext(payload, this.contextMode);
|
const peer = await createContext(payload, this.contextMode);
|
||||||
|
|
||||||
const messages = normalize(
|
const messages = normalize(
|
||||||
payload.message,
|
payload.message,
|
||||||
@@ -147,9 +140,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
const returnMsg = await handleForwardNode(peer, messages as OB11MessageNode[], group);
|
const returnMsg = await handleForwardNode(peer, messages as OB11MessageNode[]);
|
||||||
if (returnMsg) {
|
if (returnMsg) {
|
||||||
const msgShortId = await MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
||||||
return { message_id: msgShortId! };
|
return { message_id: msgShortId! };
|
||||||
} else {
|
} else {
|
||||||
throw Error('发送转发消息失败');
|
throw Error('发送转发消息失败');
|
||||||
@@ -163,7 +156,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
// log("send msg:", peer, sendElements)
|
// log("send msg:", peer, sendElements)
|
||||||
|
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, group);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(messages, peer);
|
||||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||||
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles);
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles);
|
||||||
return { message_id: returnMsg!.id! };
|
return { message_id: returnMsg!.id! };
|
||||||
|
@@ -103,5 +103,5 @@ export enum ActionName {
|
|||||||
FetchCustomFace = 'fetch_custom_face',
|
FetchCustomFace = 'fetch_custom_face',
|
||||||
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
|
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
|
||||||
TestApi01 = 'test_api_01',
|
TestApi01 = 'test_api_01',
|
||||||
FetchEmojioLike = "fetch_emoji_like"
|
FetchEmojioLike = 'fetch_emoji_like'
|
||||||
}
|
}
|
||||||
|
@@ -18,12 +18,12 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.GetRecentContact;
|
actionName = ActionName.GetRecentContact;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
|
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
|
||||||
let data = await Promise.all(ret.info.changedList.map(async (t) => {
|
const data = await Promise.all(ret.info.changedList.map(async (t) => {
|
||||||
let FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
||||||
if (FastMsg.msgList.length > 0) {
|
if (FastMsg.msgList.length > 0) {
|
||||||
//扩展ret.info.changedList
|
//扩展ret.info.changedList
|
||||||
let lastestMsg = await OB11Constructor.message(FastMsg.msgList[0]);
|
const lastestMsg = await OB11Constructor.message(FastMsg.msgList[0]);
|
||||||
return {
|
return {
|
||||||
lastestMsg: lastestMsg,
|
lastestMsg: lastestMsg,
|
||||||
peerUin: t.peerUin,
|
peerUin: t.peerUin,
|
||||||
|
@@ -65,7 +65,7 @@ export class OB11Constructor {
|
|||||||
real_id: msg.id!,
|
real_id: msg.id!,
|
||||||
message_type: msg.chatType == ChatType.group ? 'group' : 'private',
|
message_type: msg.chatType == ChatType.group ? 'group' : 'private',
|
||||||
sender: {
|
sender: {
|
||||||
user_id: parseInt(msg.senderUin!),
|
user_id: parseInt(msg.senderUin || '0'),
|
||||||
nickname: msg.sendNickName,
|
nickname: msg.sendNickName,
|
||||||
card: msg.sendMemberName || '',
|
card: msg.sendMemberName || '',
|
||||||
},
|
},
|
||||||
@@ -165,8 +165,10 @@ export class OB11Constructor {
|
|||||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||||
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0];
|
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0];
|
||||||
}
|
}
|
||||||
|
if (msg.peerUin == '284840486') {
|
||||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
//合并消息内侧 消息具体定位不到
|
||||||
|
}
|
||||||
|
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||||
throw new Error('回复消息消息验证失败');
|
throw new Error('回复消息消息验证失败');
|
||||||
}
|
}
|
||||||
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgId)?.toString();
|
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgId)?.toString();
|
||||||
@@ -221,7 +223,11 @@ export class OB11Constructor {
|
|||||||
const videoElement: VideoElement = element.videoElement;
|
const videoElement: VideoElement = element.videoElement;
|
||||||
//读取视频链接并兜底
|
//读取视频链接并兜底
|
||||||
let videoUrl;//Array
|
let videoUrl;//Array
|
||||||
|
if (msg.peerUin = '284840486') {
|
||||||
|
//合并消息内部 应该进行特殊处理 可能需要重写peer 待测试与研究 Mlikiowa Taged TODO
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
videoUrl = await NTQQFileApi.getVideoUrl({
|
videoUrl = await NTQQFileApi.getVideoUrl({
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
@@ -327,6 +333,27 @@ export class OB11Constructor {
|
|||||||
else if (element.multiForwardMsgElement) {
|
else if (element.multiForwardMsgElement) {
|
||||||
message_data['type'] = OB11MessageDataType.forward;
|
message_data['type'] = OB11MessageDataType.forward;
|
||||||
message_data['data']['id'] = msg.msgId;
|
message_data['data']['id'] = msg.msgId;
|
||||||
|
const ParentMsgPeer = msg.parentMsgPeer ?? { chatType: msg.chatType, guildId: '', peerUid: msg.peerUid };
|
||||||
|
//判断是否在合并消息内
|
||||||
|
msg.parentMsgIdList = msg.parentMsgIdList ?? [];
|
||||||
|
//首次列表不存在则开始创建
|
||||||
|
msg.parentMsgIdList.push(msg.msgId);
|
||||||
|
//let parentMsgId = msg.parentMsgIdList[msg.parentMsgIdList.length - 2 < 0 ? 0 : msg.parentMsgIdList.length - 2];
|
||||||
|
//加入自身MsgId
|
||||||
|
let MultiMsgs = (await NTQQMsgApi.getMultiMsg(ParentMsgPeer, msg.parentMsgIdList[0], msg.msgId))?.msgList;
|
||||||
|
//拉取下级消息
|
||||||
|
if (!MultiMsgs) continue;
|
||||||
|
//拉取失败则跳过
|
||||||
|
message_data['data']['content'] = [];
|
||||||
|
for (let MultiMsg of MultiMsgs) {
|
||||||
|
//对每条拉取的消息传递ParentMsgPeer修正Peer
|
||||||
|
MultiMsg.parentMsgPeer = ParentMsgPeer;
|
||||||
|
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
||||||
|
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
||||||
|
let msgList = await OB11Constructor.message(MultiMsg);
|
||||||
|
message_data['data']['content'].push(msgList);
|
||||||
|
//console.log("合并消息", msgList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((message_data.type as string) !== 'unknown' && message_data.data) {
|
if ((message_data.type as string) !== 'unknown' && message_data.data) {
|
||||||
const cqCode = encodeCQCode(message_data);
|
const cqCode = encodeCQCode(message_data);
|
||||||
|
@@ -2,5 +2,5 @@ import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
|||||||
|
|
||||||
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = 'group_admin';
|
notice_type = 'group_admin';
|
||||||
sub_type: 'set' | 'unset'; // "set" | "unset"
|
sub_type: 'set' | 'unset' = "set"; // "set" | "unset"
|
||||||
}
|
}
|
16
src/onebot11/event/notice/OB11InputStatusEvent.ts
Normal file
16
src/onebot11/event/notice/OB11InputStatusEvent.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||||
|
//输入状态事件 初步完成 Mlikio wa Todo 需要做一些过滤
|
||||||
|
export class OB11InputStatusEvent extends OB11BaseNoticeEvent {
|
||||||
|
notice_type = 'notify';
|
||||||
|
sub_type = 'input_status';
|
||||||
|
status_text = "对方正在输入..."
|
||||||
|
eventType = 1;
|
||||||
|
user_id = 0;
|
||||||
|
constructor(user_id: number, eventType: number, status_text: string) {
|
||||||
|
super();
|
||||||
|
this.user_id = user_id;
|
||||||
|
this.eventType = eventType;
|
||||||
|
this.status_text = status_text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -8,7 +8,6 @@ export interface MsgEmojiLike {
|
|||||||
export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = 'group_msg_emoji_like';
|
notice_type = 'group_msg_emoji_like';
|
||||||
message_id: number;
|
message_id: number;
|
||||||
sub_type: 'ban' | 'lift_ban';
|
|
||||||
likes: MsgEmojiLike[];
|
likes: MsgEmojiLike[];
|
||||||
|
|
||||||
constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||||
import { selfInfo } from '@/core/data';
|
|
||||||
import { OB11BaseEvent } from '../OB11BaseEvent';
|
|
||||||
|
|
||||||
class OB11PokeEvent extends OB11BaseNoticeEvent {
|
class OB11PokeEvent extends OB11BaseNoticeEvent {
|
||||||
notice_type = 'notify';
|
notice_type = 'notify';
|
||||||
|
@@ -2,7 +2,7 @@ import { OB11Message } from '@/onebot11/types';
|
|||||||
import { log } from '@/common/utils/log';
|
import { log } from '@/common/utils/log';
|
||||||
import { getGroup, getGroupMember, selfInfo } from '@/core/data';
|
import { getGroup, getGroupMember, selfInfo } from '@/core/data';
|
||||||
import exp from 'constants';
|
import exp from 'constants';
|
||||||
import { Group } from '@/core';
|
import { Group, NTQQMsgApi } from '@/core';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
const spSegColor = chalk.blue;// for special segment
|
const spSegColor = chalk.blue;// for special segment
|
||||||
@@ -24,8 +24,13 @@ export async function logMessage(ob11Message: OB11Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ob11Message.message_type === 'group') {
|
if (ob11Message.message_type === 'group') {
|
||||||
group = await getGroup(ob11Message.group_id!);
|
if (ob11Message.group_id == 284840486) {
|
||||||
prefix += `群[${group?.groupName}(${ob11Message.group_id})] `;
|
group = await getGroup(ob11Message.group_id!);
|
||||||
|
prefix += `转发消息[外部来源] `;
|
||||||
|
} else {
|
||||||
|
group = await getGroup(ob11Message.group_id!);
|
||||||
|
prefix += `群[${group?.groupName}(${ob11Message.group_id})] `;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let msgChain = '';
|
let msgChain = '';
|
||||||
if (Array.isArray(ob11Message.message)) {
|
if (Array.isArray(ob11Message.message)) {
|
||||||
@@ -66,6 +71,13 @@ export async function logMessage(ob11Message: OB11Message) {
|
|||||||
else if (segment.type === 'video') {
|
else if (segment.type === 'video') {
|
||||||
msgParts.push(spSegColor(`[视频|${segment.data.url}]`));
|
msgParts.push(spSegColor(`[视频|${segment.data.url}]`));
|
||||||
}
|
}
|
||||||
|
else if (segment.type === 'forward') {
|
||||||
|
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息开始]`));
|
||||||
|
segment.data.content.forEach((msg) => {
|
||||||
|
logMessage(msg);
|
||||||
|
});
|
||||||
|
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息结束]`));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`));
|
msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`));
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ import { logMessage, logNotice, logRequest } from '@/onebot11/log';
|
|||||||
import { OB11Message } from '@/onebot11/types';
|
import { OB11Message } from '@/onebot11/types';
|
||||||
import { isEqual } from '@/common/utils/helper';
|
import { isEqual } from '@/common/utils/helper';
|
||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
|
import { OB11InputStatusEvent } from './event/notice/OB11InputStatusEvent';
|
||||||
|
|
||||||
//下面几个其实应该移进Core-Data 缓存实现 但是现在在这里方便
|
//下面几个其实应该移进Core-Data 缓存实现 但是现在在这里方便
|
||||||
//
|
//
|
||||||
@@ -92,6 +93,21 @@ export class NapCatOnebot11 {
|
|||||||
}
|
}
|
||||||
// Create MsgListener
|
// Create MsgListener
|
||||||
const msgListener = new MsgListener();
|
const msgListener = new MsgListener();
|
||||||
|
msgListener.onInputStatusPush = async (data: {
|
||||||
|
chatType: number;
|
||||||
|
eventType: number;
|
||||||
|
fromUin: string;
|
||||||
|
interval: string;
|
||||||
|
showTime: string;
|
||||||
|
statusText: string;
|
||||||
|
timestamp: string;
|
||||||
|
toUin: string;
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
let uin = await NTQQUserApi.getUinByUid(data.fromUin);
|
||||||
|
logNotice(`[输入状态] ${uin} ${data.statusText}`);
|
||||||
|
postOB11Event(new OB11InputStatusEvent(parseInt(uin), data.eventType, data.statusText));
|
||||||
|
}
|
||||||
msgListener.onRecvSysMsg = async (protobufData: number[]) => {
|
msgListener.onRecvSysMsg = async (protobufData: number[]) => {
|
||||||
// function buf2hex(buffer: Buffer) {
|
// function buf2hex(buffer: Buffer) {
|
||||||
// return [...new Uint8Array(buffer)]
|
// return [...new Uint8Array(buffer)]
|
||||||
|
@@ -11,7 +11,7 @@ class OB11HTTPServer extends HttpServerBase {
|
|||||||
name = 'OneBot V11 server';
|
name = 'OneBot V11 server';
|
||||||
|
|
||||||
handleFailed(res: Response, payload: any, e: Error) {
|
handleFailed(res: Response, payload: any, e: Error) {
|
||||||
res.send(OB11Response.error(e?.stack?.toString() || e.message || "Error Handle", 200));
|
res.send(OB11Response.error(e?.stack?.toString() || e.message || 'Error Handle', 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected listen(port: number, host: string) {
|
protected listen(port: number, host: string) {
|
||||||
|
@@ -159,7 +159,7 @@ async function handleMsg(msg: OB11Message, quickAction: QuickAction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
|
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, peer);
|
||||||
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then().catch(logError);
|
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then().catch(logError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -181,7 +181,8 @@ export interface OB11MessageMarkdown {
|
|||||||
export interface OB11MessageForward {
|
export interface OB11MessageForward {
|
||||||
type: OB11MessageDataType.forward
|
type: OB11MessageDataType.forward
|
||||||
data: {
|
data: {
|
||||||
id: string
|
id: string,
|
||||||
|
content: OB11Message[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = '1.7.9';
|
export const version = '1.8.3';
|
||||||
|
@@ -29,7 +29,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('V1.7.9', 'napcat-update-button', 'secondary')
|
SettingButton('V1.8.3', 'napcat-update-button', 'secondary')
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@@ -163,7 +163,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
void 0,
|
void 0,
|
||||||
SettingButton("V1.7.9", "napcat-update-button", "secondary")
|
SettingButton("V1.8.3", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@@ -26,9 +26,9 @@ if (process.env.NAPCAT_BUILDSYS == 'linux') {
|
|||||||
} else if (process.env.NAPCAT_BUILDSYS == 'win32') {
|
} else if (process.env.NAPCAT_BUILDSYS == 'win32') {
|
||||||
if (process.env.NAPCAT_BUILDARCH == 'x64') {
|
if (process.env.NAPCAT_BUILDARCH == 'x64') {
|
||||||
}
|
}
|
||||||
startScripts = ['./script/dbghelp.dll', './script/BootWay05.ps1', './script/napcat-9912.ps1', './script/napcat-9912-utf8.ps1', './script/napcat-9912.bat', './script/napcat-9912-utf8.bat'];
|
startScripts = ['./script/BootWay05.bat', './script/BootWay05.utf8.bat', './script/dbghelp.dll', './script/BootWay05.ps1', './script/napcat-9912.ps1', './script/napcat-9912-utf8.ps1', './script/napcat-9912.bat', './script/napcat-9912-utf8.bat'];
|
||||||
} else {
|
} else {
|
||||||
startScripts = ['./script/dbghelp.dll', './script/BootWay05.ps1', './script/napcat.sh', './script/napcat.ps1', './script/napcat.bat', './script/napcat-utf8.bat', './script/napcat-utf8.ps1', './script/napcat-log.ps1', './script/napcat-9912.ps1', './script/napcat-9912-utf8.ps1', './script/napcat-9912.bat', './script/napcat-9912-utf8.bat'];
|
startScripts = ['./script/BootWay05.bat', './script/BootWay05.utf8.bat', './script/dbghelp.dll', './script/BootWay05.ps1', './script/napcat.sh', './script/napcat.ps1', './script/napcat.bat', './script/napcat-utf8.bat', './script/napcat-utf8.ps1', './script/napcat-log.ps1', './script/napcat-9912.ps1', './script/napcat-9912-utf8.ps1', './script/napcat-9912.bat', './script/napcat-9912-utf8.bat'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseConfigPlugin: PluginOption[] = [
|
const baseConfigPlugin: PluginOption[] = [
|
||||||
|
Reference in New Issue
Block a user