Compare commits

...

7 Commits

Author SHA1 Message Date
手瓜一十雪
1a64e796bd release: 2.6.4 2024-09-17 23:17:19 +08:00
手瓜一十雪
a8b85a34f7 feat: 追平NT逻辑 2024-09-17 23:17:02 +08:00
手瓜一十雪
e7bec7d6b0 feat: systemPlatform标准化 2024-09-17 22:24:09 +08:00
手瓜一十雪
a582026037 release:2.6.3 2024-09-17 13:57:54 +08:00
手瓜一十雪
1a67a001c5 style: lint 2024-09-17 13:15:12 +08:00
手瓜一十雪
406deac592 fix:api外的推送事件 2024-09-17 13:14:18 +08:00
手瓜一十雪
e719ae0676 release: 2.6.2 2024-09-17 13:01:02 +08:00
17 changed files with 88 additions and 56 deletions

View File

@@ -4,7 +4,7 @@
"name": "NapCatQQ", "name": "NapCatQQ",
"slug": "NapCat.Framework", "slug": "NapCat.Framework",
"description": "高性能的 OneBot 11 协议实现", "description": "高性能的 OneBot 11 协议实现",
"version": "2.6.1", "version": "2.6.4",
"icon": "./logo.png", "icon": "./logo.png",
"authors": [ "authors": [
{ {

View File

@@ -2,7 +2,7 @@
"name": "napcat", "name": "napcat",
"private": true, "private": true,
"type": "module", "type": "module",
"version": "2.6.1", "version": "2.6.4",
"scripts": { "scripts": {
"build:framework": "vite build --mode framework", "build:framework": "vite build --mode framework",
"build:shell": "vite build --mode shell", "build:shell": "vite build --mode shell",

View File

@@ -45,9 +45,9 @@ async function handleWavFile(
): Promise<{input: Buffer, sampleRate: number}> { ): Promise<{input: Buffer, sampleRate: number}> {
const { fmt } = getWavFileInfo(file); const { fmt } = getWavFileInfo(file);
if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) { if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) {
return {input: await convert(filePath, pcmPath, logger), sampleRate: 24000}; return { input: await convert(filePath, pcmPath, logger), sampleRate: 24000 };
} }
return {input: file, sampleRate: fmt.sampleRate}; return { input: file, sampleRate: fmt.sampleRate };
} }
export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: LogWrapper) { export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: LogWrapper) {
@@ -59,7 +59,7 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log
const pcmPath = `${pttPath}.pcm`; const pcmPath = `${pttPath}.pcm`;
const { input, sampleRate } = isWav(file) const { input, sampleRate } = isWav(file)
? (await handleWavFile(file, filePath, pcmPath, logger)) ? (await handleWavFile(file, filePath, pcmPath, logger))
: {input: await convert(filePath, pcmPath, logger), sampleRate: 24000}; : { input: await convert(filePath, pcmPath, logger), sampleRate: 24000 };
const silk = await encode(input, sampleRate); const silk = await encode(input, sampleRate);
await fsPromise.writeFile(pttPath, silk.data); await fsPromise.writeFile(pttPath, silk.data);
logger.log(`语音文件${filePath}转换成功!`, pttPath, '时长:', silk.duration); logger.log(`语音文件${filePath}转换成功!`, pttPath, '时长:', silk.duration);

View File

@@ -187,7 +187,7 @@ export class NTEventWrapper {
const id = randomUUID(); const id = randomUUID();
let complete = 0; let complete = 0;
let retData: Parameters<ListenerType> | undefined = undefined; let retData: Parameters<ListenerType> | undefined = undefined;
let retEvent: any = {}; const retEvent: any = {};
function sendDataCallback() { function sendDataCallback() {
if (complete == 0) { if (complete == 0) {

View File

@@ -144,7 +144,7 @@ async function tryDownload(options: string | HttpDownloadOptions, useReferer: bo
} }
if (useReferer && !headers['Referer']) { if (useReferer && !headers['Referer']) {
headers['Referer'] = url; headers['Referer'] = url;
}; }
const fetchRes = await fetch(url, { headers }).catch((err) => { const fetchRes = await fetch(url, { headers }).catch((err) => {
if (err.cause) { if (err.cause) {
throw err.cause; throw err.cause;

View File

@@ -188,14 +188,20 @@ export function getDefaultQQVersionConfigInfo(): QQVersionConfigType {
}; };
} }
export function getQQPackageInfoPath(exePath: string = '', version: string): string { export function getQQPackageInfoPath(exePath: string = '', version?: string): string {
let packagePath;
if (os.platform() === 'darwin') { if (os.platform() === 'darwin') {
return path.join(path.dirname(exePath), '..', 'Resources', 'app', 'package.json'); packagePath = path.join(path.dirname(exePath), '..', 'Resources', 'app', 'package.json');
} else if (os.platform() === 'linux') { } else if (os.platform() === 'linux') {
return path.join(path.dirname(exePath), './resources/app/package.json'); packagePath = path.join(path.dirname(exePath), './resources/app/package.json');
} else { } else {
return path.join(path.dirname(exePath), './versions/' + version + '/resources/app/package.json'); packagePath = path.join(path.dirname(exePath), './versions/' + version + '/resources/app/package.json');
} }
//下面是老版本兼容 未来去掉
if (!fs.existsSync(packagePath)) {
packagePath = path.join(path.dirname(exePath), './resources/app/versions/' + version + '/package.json');
}
return packagePath;
} }
export function getQQVersionConfigPath(exePath: string = ''): string | undefined { export function getQQVersionConfigPath(exePath: string = ''): string | undefined {
@@ -214,6 +220,10 @@ export function getQQVersionConfigPath(exePath: string = ''): string | undefined
if (typeof configVersionInfoPath !== 'string') { if (typeof configVersionInfoPath !== 'string') {
return undefined; return undefined;
} }
//老版本兼容 未来去掉
if (!fs.existsSync(configVersionInfoPath)) {
configVersionInfoPath = path.join(path.dirname(exePath), './resources/app/versions/config.json');
}
if (!fs.existsSync(configVersionInfoPath)) { if (!fs.existsSync(configVersionInfoPath)) {
return undefined; return undefined;
} }

View File

@@ -28,7 +28,7 @@ export class QQBasicInfoWrapper {
? JSON.parse(fs.readFileSync(this.QQVersionConfigPath!).toString()) ? JSON.parse(fs.readFileSync(this.QQVersionConfigPath!).toString())
: getDefaultQQVersionConfigInfo(); : getDefaultQQVersionConfigInfo();
this.QQPackageInfoPath = getQQPackageInfoPath(this.QQMainPath, this.QQVersionConfig?.curVersion!); this.QQPackageInfoPath = getQQPackageInfoPath(this.QQMainPath, this.QQVersionConfig?.curVersion);
this.QQPackageInfo = JSON.parse(fs.readFileSync(this.QQPackageInfoPath).toString()); this.QQPackageInfo = JSON.parse(fs.readFileSync(this.QQPackageInfoPath).toString());
const { appid: IQQVersionAppid, qua: IQQVersionQua } = this.getAppidV2(); const { appid: IQQVersionAppid, qua: IQQVersionQua } = this.getAppidV2();
this.QQVersionAppid = IQQVersionAppid; this.QQVersionAppid = IQQVersionAppid;
@@ -55,23 +55,23 @@ export class QQBasicInfoWrapper {
//此方法不要直接使用 //此方法不要直接使用
getQUAInternal() { getQUAInternal() {
switch (systemPlatform) { switch (systemPlatform) {
case 'linux': case 'linux':
return `V1_LNX_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; return `V1_LNX_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`;
case 'darwin': case 'darwin':
return `V1_MAC_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; return `V1_MAC_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`;
default: default:
return `V1_WIN_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; return `V1_WIN_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`;
} }
} }
getAppidInternal() { getAppidInternal() {
switch (systemPlatform) { switch (systemPlatform) {
case 'linux': case 'linux':
return '537246140'; return '537246140';
case 'darwin': case 'darwin':
return '537246140'; return '537246140';
default: default:
return '537246092'; return '537246092';
} }
} }

View File

@@ -1 +1 @@
export const napCatVersion = '2.6.1'; export const napCatVersion = '2.6.4';

View File

@@ -54,6 +54,10 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi {
if (!fs.existsSync(wrapperNodePath)) { if (!fs.existsSync(wrapperNodePath)) {
wrapperNodePath = path.join(appPath, `./resources/app/wrapper.node`); wrapperNodePath = path.join(appPath, `./resources/app/wrapper.node`);
} }
//老版本兼容 未来去掉
if (!fs.existsSync(wrapperNodePath)) {
wrapperNodePath = path.join(path.dirname(process.execPath), `./resources/app/versions/${QQVersion}/wrapper.node`);
}
const nativemodule: any = { exports: {} }; const nativemodule: any = { exports: {} };
process.dlopen(nativemodule, wrapperNodePath); process.dlopen(nativemodule, wrapperNodePath);
return nativemodule.exports; return nativemodule.exports;
@@ -247,18 +251,31 @@ export async function genSessionConfig(QQVersionAppid: string, QQVersion: string
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 });
const guid: string = await getMachineId();//26702 支持JS获取guid值 在LoginService中获取 TODO mlikiow a const guid: string = await getMachineId();//26702 支持JS获取guid值 在LoginService中获取 TODO mlikiow a
//os.platform()
let systemPlatform = PlatformType.KWINDOWS;
switch (os.platform()) {
case 'win32':
systemPlatform = PlatformType.KWINDOWS;
break;
case 'darwin':
systemPlatform = PlatformType.KMAC;
break;
case 'linux':
systemPlatform = PlatformType.KANDROID; //Android 怎么不算Linux!
break;
}
return { return {
selfUin, selfUin,
selfUid, selfUid,
desktopPathConfig: { desktopPathConfig: {
account_path, // 可以通过NodeQQNTWrapperUtil().getNTUserDataInfoConfig()获取 account_path, // 可以通过NodeQQNTWrapperUtil().getNTUserDataInfoConfig()获取
}, },
clientVer: QQVersion, // 9.9.8-22355 clientVer: QQVersion,
a2: '', a2: '',
d2: '', d2: '',
d2Key: '', d2Key: '',
machineId: '', machineId: '',
platform: PlatformType.KWINDOWS, // 3是Windows? platform: systemPlatform, // 3是Windows?
platVer: systemVersion, // 系统版本号, 应该可以固定 platVer: systemVersion, // 系统版本号, 应该可以固定
appid: QQVersionAppid, appid: QQVersionAppid,
rdeliveryConfig: { rdeliveryConfig: {
@@ -266,7 +283,7 @@ export async function genSessionConfig(QQVersionAppid: string, QQVersion: string
systemId: 0, systemId: 0,
appId: '', appId: '',
logicEnvironment: '', logicEnvironment: '',
platform: PlatformType.KWINDOWS, platform: systemPlatform,
language: '', language: '',
sdkVersion: '', sdkVersion: '',
userId: '', userId: '',

View File

@@ -144,7 +144,7 @@ export interface NodeQQNTWrapperUtil {
export interface NodeIQQNTWrapperSession { export interface NodeIQQNTWrapperSession {
create(): NodeIQQNTWrapperSession; create(): NodeIQQNTWrapperSession;
init( init(
wrapperSessionInitConfig: WrapperSessionInitConfig, wrapperSessionInitConfig: WrapperSessionInitConfig,
nodeIDependsAdapter: NodeIDependsAdapter, nodeIDependsAdapter: NodeIDependsAdapter,
@@ -249,7 +249,7 @@ export interface NodeIQQNTWrapperSession {
export interface EnginInitDesktopConfig { export interface EnginInitDesktopConfig {
base_path_prefix: string; base_path_prefix: string;
platform_type: 3; platform_type: PlatformType;
app_type: 4; app_type: 4;
app_version: string; app_version: string;
os_version: string; os_version: string;
@@ -262,8 +262,7 @@ export interface EnginInitDesktopConfig {
} }
export interface NodeIQQNTWrapperEngine { export interface NodeIQQNTWrapperEngine {
// eslint-disable-next-line @typescript-eslint/no-misused-new get(): NodeIQQNTWrapperEngine;
new(): NodeIQQNTWrapperEngine;
initWithDeskTopConfig(config: EnginInitDesktopConfig, nodeIGlobalAdapter: NodeIGlobalAdapter): void; initWithDeskTopConfig(config: EnginInitDesktopConfig, nodeIGlobalAdapter: NodeIGlobalAdapter): void;
} }

View File

@@ -23,7 +23,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
async _handle(payload: Payload) { async _handle(payload: Payload) {
const groupMembers = await this.core.apis.GroupApi.getGroupMembersV2(payload.group_id.toString()); const groupMembers = await this.core.apis.GroupApi.getGroupMembersV2(payload.group_id.toString());
const groupMembersArr = Array.from(groupMembers.values()); const groupMembersArr = Array.from(groupMembers.values());
let uids = groupMembersArr.map(item => item.uid); const uids = groupMembersArr.map(item => item.uid);
//let CoreAndBase = await this.core.apis.GroupApi.getCoreAndBaseInfo(uids) //let CoreAndBase = await this.core.apis.GroupApi.getCoreAndBaseInfo(uids)
let _groupMembers = groupMembersArr.map(item => { let _groupMembers = groupMembersArr.map(item => {
return OB11Entities.groupMember(payload.group_id.toString(), item); return OB11Entities.groupMember(payload.group_id.toString(), item);

View File

@@ -574,9 +574,10 @@ export class OneBotMsgApi {
} else { } else {
postData = data; postData = data;
} }
const signUrl = this.obContext.configLoader.configData.musicSignUrl; let signUrl = this.obContext.configLoader.configData.musicSignUrl;
if (!signUrl) { if (!signUrl) {
throw Error('音乐消息签名地址未配置'); signUrl = 'https://ss.xingzhige.com/music_card/card';//感谢思思!
//throw Error('音乐消息签名地址未配置');
} }
try { try {
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData); const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
@@ -609,7 +610,7 @@ export class OneBotMsgApi {
[OB11MessageDataType.miniapp]: async () => undefined, [OB11MessageDataType.miniapp]: async () => undefined,
[OB11MessageDataType.contact]: async ({ data }, context) => { [OB11MessageDataType.contact]: async ({ data }, context) => {
let arkJson = await this.core.apis.UserApi.getBuddyRecommendContactArkJson(data.id.toString(), ''); const arkJson = await this.core.apis.UserApi.getBuddyRecommendContactArkJson(data.id.toString(), '');
return this.ob11ToRawConverters.json({ return this.ob11ToRawConverters.json({
data: { data: arkJson.arkMsg }, data: { data: arkJson.arkMsg },
type: OB11MessageDataType.json type: OB11MessageDataType.json

View File

@@ -48,8 +48,8 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
//鉴权 //鉴权
this.authorize(token, wsClient, wsReq); this.authorize(token, wsClient, wsReq);
const paramUrl = wsReq.url?.indexOf('?') !== -1 ? wsReq.url?.substring(0, wsReq.url?.indexOf('?')) : wsReq.url; const paramUrl = wsReq.url?.indexOf('?') !== -1 ? wsReq.url?.substring(0, wsReq.url?.indexOf('?')) : wsReq.url;
const isEventConnect = paramUrl === '/event' || paramUrl === '' || paramUrl === '/'; const isApiConnect = paramUrl === '/api' || paramUrl === '/api/';
if (isEventConnect) { if (!isApiConnect) {
this.connectEvent(core, wsClient); this.connectEvent(core, wsClient);
} }
@@ -77,7 +77,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
}); });
}); });
await this.wsClientsMutex.runExclusive(async () => { await this.wsClientsMutex.runExclusive(async () => {
if(isEventConnect){ if (!isApiConnect) {
this.wsClientWithEvent.push(wsClient); this.wsClientWithEvent.push(wsClient);
} }
this.wsClients.push(wsClient); this.wsClients.push(wsClient);

View File

@@ -11,6 +11,7 @@ import {
NapCatCore, NapCatCore,
NapCatCoreWorkingEnv, NapCatCoreWorkingEnv,
NodeIQQNTWrapperSession, NodeIQQNTWrapperSession,
PlatformType,
WrapperNodeApi, WrapperNodeApi,
} from '@/core'; } from '@/core';
import { QQBasicInfoWrapper } from '@/common/qq-basic-info'; import { QQBasicInfoWrapper } from '@/common/qq-basic-info';
@@ -43,7 +44,7 @@ export async function NCoreInitShell() {
InitWebUi(logger, pathWrapper).then().catch(logger.logError); InitWebUi(logger, pathWrapper).then().catch(logger.logError);
// from constructor // from constructor
const engine = new wrapper.NodeIQQNTWrapperEngine(); const engine = wrapper.NodeIQQNTWrapperEngine.get();
//const util = wrapper.NodeQQNTWrapperUtil.get(); //const util = wrapper.NodeQQNTWrapperUtil.get();
const loginService = wrapper.NodeIKernelLoginService.get(); const loginService = wrapper.NodeIKernelLoginService.get();
const session = wrapper.NodeIQQNTWrapperSession.create(); const session = wrapper.NodeIQQNTWrapperSession.create();
@@ -63,17 +64,29 @@ export async function NCoreInitShell() {
const dataPathGlobal = path.resolve(dataPath, './nt_qq/global'); const dataPathGlobal = path.resolve(dataPath, './nt_qq/global');
return [dataPath, dataPathGlobal]; return [dataPath, dataPathGlobal];
})(); })();
let systemPlatform = PlatformType.KWINDOWS;
switch (os.platform()) {
case 'win32':
systemPlatform = PlatformType.KWINDOWS;
break;
case 'darwin':
systemPlatform = PlatformType.KMAC;
break;
case 'linux':
systemPlatform = PlatformType.KANDROID; //Android 怎么不算Linux!
break;
}
if (!basicInfoWrapper.QQVersionAppid || !basicInfoWrapper.QQVersionQua) throw new Error('QQVersionAppid or QQVersionQua is not defined');
// from initConfig // from initConfig
engine.initWithDeskTopConfig( engine.initWithDeskTopConfig(
{ {
base_path_prefix: '', base_path_prefix: '',
platform_type: 3, platform_type: systemPlatform,
app_type: 4, app_type: 4,
app_version: basicInfoWrapper.getFullQQVesion(), app_version: basicInfoWrapper.getFullQQVesion(),
os_version: 'Windows 10 Pro', os_version: systemVersion,
use_xlog: true, use_xlog: true,
qua: basicInfoWrapper.QQVersionQua!, qua: basicInfoWrapper.QQVersionQua,
global_path_config: { global_path_config: {
desktopGlobalPath: dataPathGlobal, desktopGlobalPath: dataPathGlobal,
}, },
@@ -83,7 +96,7 @@ export async function NCoreInitShell() {
); );
loginService.initConfig({ loginService.initConfig({
machineId: '', machineId: '',
appid: basicInfoWrapper.QQVersionAppid!, appid: basicInfoWrapper.QQVersionAppid,
platVer: systemVersion, platVer: systemVersion,
commonPath: dataPathGlobal, commonPath: dataPathGlobal,
clientVer: basicInfoWrapper.getFullQQVesion(), clientVer: basicInfoWrapper.getFullQQVesion(),
@@ -117,7 +130,7 @@ export async function NCoreInitShell() {
nick: '', // 获取不到 nick: '', // 获取不到
online: true, online: true,
}); });
} };
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => { loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
//设置WebuiQrcode //设置WebuiQrcode

View File

@@ -30,7 +30,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('V2.6.1', 'napcat-update-button', 'secondary'), SettingButton('V2.6.4', 'napcat-update-button', 'secondary'),
), ),
]), ]),
SettingList([ SettingList([

View File

@@ -164,7 +164,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("V2.6.1", "napcat-update-button", "secondary") SettingButton("V2.6.4", "napcat-update-button", "secondary")
) )
]), ]),
SettingList([ SettingList([

View File

@@ -1,4 +1,3 @@
// import PreprocessorDirectives from 'unplugin-preprocessor-directives/vite';
import cp from 'vite-plugin-cp'; import cp from 'vite-plugin-cp';
import { defineConfig, PluginOption, UserConfig } from 'vite'; import { defineConfig, PluginOption, UserConfig } from 'vite';
import { resolve } from 'path'; import { resolve } from 'path';
@@ -35,25 +34,18 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [
{ src: './src/framework/renderer.js', dest: 'dist' }, { src: './src/framework/renderer.js', dest: 'dist' },
{ src: './package.json', dest: 'dist' }, { src: './package.json', dest: 'dist' },
{ src: './logo.png', dest: 'dist' }, { src: './logo.png', dest: 'dist' },
//...external.map(genCpModule)
], ],
}), }),
nodeResolve(), nodeResolve(),
]; ];
const ShellBaseConfigPlugin: PluginOption[] = [ const ShellBaseConfigPlugin: PluginOption[] = [
// PreprocessorDirectives(),
cp({ cp({
targets: [ targets: [
// ...external.map(genCpModule),
// { src: './src/napcat.json', dest: 'dist/config/' },
{ src: './static/', dest: 'dist/static/', flatten: false }, { src: './static/', dest: 'dist/static/', flatten: false },
// { src: './src/onebot11/onebot11.json', dest: 'dist/config/' },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/core/external/napcat.json', dest: 'dist/config/' },
{ src: './src/onebot/config/onebot11.json', dest: 'dist/config/' }, { src: './src/onebot/config/onebot11.json', dest: 'dist/config/' },
{ src: './package.json', dest: 'dist' }, { src: './package.json', dest: 'dist' },
{ src: './launcher/', dest: 'dist', flatten: true }, { src: './launcher/', dest: 'dist', flatten: true },
// { src: './README.md', dest: 'dist' },
// { src: './logo.png', dest: 'dist/logs' },
...(startScripts.map((startScript) => { ...(startScripts.map((startScript) => {
return { src: startScript, dest: 'dist' }; return { src: startScript, dest: 'dist' };
})), })),