Compare commits

...

2 Commits

Author SHA1 Message Date
手瓜一十雪
b23c357f73 release: 2.6.24 2024-10-06 10:07:39 +08:00
Wesley F. Young
f561c2b0fa refactor: rewrite switch with object mapping or if-else 2024-10-05 17:03:02 +08:00
10 changed files with 40 additions and 57 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.23", "version": "2.6.24",
"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.23", "version": "2.6.24",
"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

@@ -53,26 +53,22 @@ export class QQBasicInfoWrapper {
} }
//此方法不要直接使用 //此方法不要直接使用
getQUAInternal() { getQUAFallback() {
switch (systemPlatform) { const platformMapping: Partial<Record<NodeJS.Platform, string>> = {
case 'linux': win32: `V1_WIN_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`,
return `V1_LNX_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; darwin: `V1_MAC_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`,
case 'darwin': linux: `V1_LNX_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`,
return `V1_MAC_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`; };
default: return platformMapping[systemPlatform] ?? (platformMapping.win32)!;
return `V1_WIN_${this.getFullQQVesion()}_${this.getQQBuildStr()}_GW_B`;
}
} }
getAppidInternal() { getAppIdFallback() {
switch (systemPlatform) { const platformMapping: Partial<Record<NodeJS.Platform, string>> = {
case 'linux': win32: '537246092',
return '537246140'; darwin: '537246140',
case 'darwin': linux: '537246140',
return '537246140'; };
default: return platformMapping[systemPlatform] ?? '537246092';
return '537246092';
}
} }
getAppidV2(): { appid: string; qua: string } { getAppidV2(): { appid: string; qua: string } {
@@ -88,6 +84,6 @@ export class QQBasicInfoWrapper {
// else // else
this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`); this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`);
this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,); this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,);
return { appid: this.getAppidInternal(), qua: this.getQUAInternal() }; return { appid: this.getAppIdFallback(), qua: this.getQUAFallback() };
} }
} }

View File

@@ -1 +1 @@
export const napCatVersion = '2.6.23'; export const napCatVersion = '2.6.24';

View File

@@ -396,7 +396,9 @@ export class NTQQFileApi {
return IMAGE_HTTP_HOST + `/download?appid=${imageAppid}&fileid=${imageFileId}&rkey=${rkey}`; return IMAGE_HTTP_HOST + `/download?appid=${imageAppid}&fileid=${imageFileId}&rkey=${rkey}`;
} }
} else if (fileMd5 || md5HexStr) { }
//到这里说明可能是旧客户端
if (fileMd5 || md5HexStr) {
return `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${(fileMd5 ?? md5HexStr)!.toUpperCase()}/0`; return `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${(fileMd5 ?? md5HexStr)!.toUpperCase()}/0`;
} }

View File

@@ -20,11 +20,11 @@ import { LogLevel, LogWrapper } from '@/common/log';
import { NodeIKernelLoginService } from '@/core/services'; import { NodeIKernelLoginService } from '@/core/services';
import { QQBasicInfoWrapper } from '@/common/qq-basic-info'; import { QQBasicInfoWrapper } from '@/common/qq-basic-info';
import { NapCatPathWrapper } from '@/common/path'; import { NapCatPathWrapper } from '@/common/path';
import path, { resolve } from 'node:path'; import path from 'node:path';
import fs from 'node:fs'; import fs from 'node:fs';
import { hostname, systemName, systemVersion } from '@/common/system'; import { hostname, systemName, systemVersion } from '@/common/system';
import { NTEventWrapper } from '@/common/event'; import { NTEventWrapper } from '@/common/event';
import { ChatType, DataSource, GroupMember, KickedOffLineInfo, Peer, SelfInfo, SelfStatusInfo } from '@/core/entities'; import { DataSource, GroupMember, KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/entities';
import { NapCatConfigLoader } from '@/core/helper/config'; import { NapCatConfigLoader } from '@/core/helper/config';
import os from 'node:os'; import os from 'node:os';
import { NodeIKernelGroupListener, NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners'; import { NodeIKernelGroupListener, NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners';
@@ -257,19 +257,12 @@ export async function genSessionConfig(
): Promise<WrapperSessionInitConfig> { ): 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 });
//os.platform() const platformMapping: Partial<Record<NodeJS.Platform, PlatformType>> = {
let systemPlatform = PlatformType.KWINDOWS; win32: PlatformType.KWINDOWS,
switch (os.platform()) { darwin: PlatformType.KMAC,
case 'win32': linux: PlatformType.KLINUX,
systemPlatform = PlatformType.KWINDOWS; };
break; const systemPlatform = platformMapping[os.platform()] ?? PlatformType.KWINDOWS;
case 'darwin':
systemPlatform = PlatformType.KMAC;
break;
case 'linux':
systemPlatform = PlatformType.KLINUX;
break;
}
return { return {
selfUin, selfUin,
selfUid, selfUid,

View File

@@ -139,8 +139,7 @@ export class OneBotGroupApi {
} }
if (element.grayTipElement.jsonGrayTipElement.busiId == 2407) { if (element.grayTipElement.jsonGrayTipElement.busiId == 2407) {
const type = json.items[json.items.length - 1]?.txt; const type = json.items[json.items.length - 1]?.txt;
switch (type) { if (type === "头衔") {
case "头衔": {
const memberUin = json.items[1].param[0]; const memberUin = json.items[1].param[0];
const title = json.items[3].txt; const title = json.items[3].txt;
logger.logDebug('收到群成员新头衔消息', json); logger.logDebug('收到群成员新头衔消息', json);
@@ -150,11 +149,10 @@ export class OneBotGroupApi {
parseInt(memberUin), parseInt(memberUin),
title, title,
); );
} } else if (type === "移出") {
case "移出":
logger.logDebug('收到机器人被踢消息', json); logger.logDebug('收到机器人被踢消息', json);
return; return;
default: } else {
logger.logWarn('收到未知的灰条消息', json); logger.logWarn('收到未知的灰条消息', json);
} }
} }

View File

@@ -69,18 +69,12 @@ 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; const platformMapping: Partial<Record<NodeJS.Platform, PlatformType>> = {
switch (os.platform()) { win32: PlatformType.KWINDOWS,
case 'win32': darwin: PlatformType.KMAC,
systemPlatform = PlatformType.KWINDOWS; linux: PlatformType.KLINUX,
break; };
case 'darwin': const systemPlatform = platformMapping[os.platform()] ?? PlatformType.KWINDOWS;
systemPlatform = PlatformType.KMAC;
break;
case 'linux':
systemPlatform = PlatformType.KLINUX;
break;
}
if (!basicInfoWrapper.QQVersionAppid || !basicInfoWrapper.QQVersionQua) throw new Error('QQVersionAppid or QQVersionQua is not defined'); if (!basicInfoWrapper.QQVersionAppid || !basicInfoWrapper.QQVersionQua) throw new Error('QQVersionAppid or QQVersionQua is not defined');
// from initConfig // from initConfig
engine.initWithDeskTopConfig( engine.initWithDeskTopConfig(

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.23', 'napcat-update-button', 'secondary'), SettingButton('V2.6.24', '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.23", "napcat-update-button", "secondary") SettingButton("V2.6.24", "napcat-update-button", "secondary")
) )
]), ]),
SettingList([ SettingList([