mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
chore: merge main
This commit is contained in:
commit
b76edcaf1d
@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "2.2.7",
|
"version": "2.2.8",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.2.7",
|
"version": "2.2.8",
|
||||||
"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",
|
||||||
|
@ -124,14 +124,7 @@ export class NTEventChannel extends EventEmitter {
|
|||||||
EventName = '', timeout: number = 3000, ...args: Parameters<EventType>) {
|
EventName = '', timeout: number = 3000, ...args: Parameters<EventType>) {
|
||||||
return new Promise<Awaited<ReturnType<EventType>>>(async (resolve, reject) => {
|
return new Promise<Awaited<ReturnType<EventType>>>(async (resolve, reject) => {
|
||||||
const EventFunc = this.createEventFunction<EventType>(EventName);
|
const EventFunc = this.createEventFunction<EventType>(EventName);
|
||||||
let complete = false;
|
|
||||||
const Timeouter = setTimeout(() => {
|
|
||||||
if (!complete) {
|
|
||||||
reject(new Error('NTEvent EventName:' + EventName + ' timeout'));
|
|
||||||
}
|
|
||||||
}, timeout);
|
|
||||||
const retData = await EventFunc!(...args);
|
const retData = await EventFunc!(...args);
|
||||||
complete = true;
|
|
||||||
resolve(retData);
|
resolve(retData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export const napcat_version = '2.2.7';
|
export const napcat_version = '2.2.8';
|
||||||
|
|
||||||
export class NapCatPathWrapper {
|
export class NapCatPathWrapper {
|
||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
|
@ -53,7 +53,7 @@ export abstract class ConfigBase<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
save(newConfigData: T = this.configData as T) {
|
save(newConfigData: T = this.configData) {
|
||||||
const logger = this.coreContext.context.logger;
|
const logger = this.coreContext.context.logger;
|
||||||
const selfInfo = this.coreContext.selfInfo;
|
const selfInfo = this.coreContext.selfInfo;
|
||||||
this.configData = newConfigData;
|
this.configData = newConfigData;
|
||||||
|
@ -46,7 +46,7 @@ export class QQBasicInfoWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requireMinNTQQBuild(buildStr: string) {
|
requireMinNTQQBuild(buildStr: string) {
|
||||||
const currentBuild = parseInt(this.getQQBuildStr() || '0');
|
const currentBuild = +(this.getQQBuildStr() ?? '0');
|
||||||
if (currentBuild == 0) throw new Error('QQBuildStr获取失败');
|
if (currentBuild == 0) throw new Error('QQBuildStr获取失败');
|
||||||
return currentBuild >= parseInt(buildStr);
|
return currentBuild >= parseInt(buildStr);
|
||||||
}
|
}
|
||||||
|
@ -187,22 +187,27 @@ export enum FileUriType {
|
|||||||
|
|
||||||
export async function checkUriType(Uri: string) {
|
export async function checkUriType(Uri: string) {
|
||||||
|
|
||||||
const LocalFileRet = await solveProblem((Uri) => { if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local }; });
|
const LocalFileRet = await solveProblem((uri: string) => {
|
||||||
|
if (fs.existsSync(uri)) {
|
||||||
|
return { Uri: uri, Type: FileUriType.Local };
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}, Uri);
|
||||||
if (LocalFileRet) return LocalFileRet;
|
if (LocalFileRet) return LocalFileRet;
|
||||||
|
|
||||||
const OtherFileRet = await solveProblem((Uri) => {
|
const OtherFileRet = await solveProblem((uri: string) => {
|
||||||
//再判断是否是Http
|
//再判断是否是Http
|
||||||
if (Uri.startsWith('http://') || Uri.startsWith('https://')) {
|
if (uri.startsWith('http://') || uri.startsWith('https://')) {
|
||||||
return { Uri: Uri, Type: FileUriType.Remote };
|
return { Uri: uri, Type: FileUriType.Remote };
|
||||||
}
|
}
|
||||||
//再判断是否是Base64
|
//再判断是否是Base64
|
||||||
if (Uri.startsWith('base64://')) {
|
if (uri.startsWith('base64://')) {
|
||||||
return { Uri: Uri, Type: FileUriType.Base64 };
|
return { Uri: uri, Type: FileUriType.Base64 };
|
||||||
}
|
}
|
||||||
if (Uri.startsWith('file://')) {
|
if (uri.startsWith('file://')) {
|
||||||
let filePath: string;
|
let filePath: string;
|
||||||
// await fs.copyFile(url.pathname, filePath);
|
// await fs.copyFile(url.pathname, filePath);
|
||||||
const pathname = decodeURIComponent(new URL(Uri).pathname);
|
const pathname = decodeURIComponent(new URL(uri).pathname);
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
filePath = pathname.slice(1);
|
filePath = pathname.slice(1);
|
||||||
} else {
|
} else {
|
||||||
@ -210,7 +215,7 @@ export async function checkUriType(Uri: string) {
|
|||||||
}
|
}
|
||||||
return { Uri: filePath, Type: FileUriType.Local };
|
return { Uri: filePath, Type: FileUriType.Local };
|
||||||
}
|
}
|
||||||
});
|
}, Uri);
|
||||||
if (OtherFileRet) return OtherFileRet;
|
if (OtherFileRet) return OtherFileRet;
|
||||||
|
|
||||||
return { Uri: Uri, Type: FileUriType.Unknown };
|
return { Uri: Uri, Type: FileUriType.Unknown };
|
||||||
|
@ -3,10 +3,10 @@ import fs from 'fs';
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { QQLevel } from '@/core';
|
import { QQLevel } from '@/core';
|
||||||
|
|
||||||
export async function solveProblem<T extends (...arg: any[]) => any>(func: T): Promise<ReturnType<T> | undefined> {
|
export async function solveProblem<T extends (...arg: any[]) => any>(func: T, ...args: Parameters<T>): Promise<ReturnType<T> | undefined> {
|
||||||
return new Promise<ReturnType<T> | undefined>(async (resolve) => {
|
return new Promise<ReturnType<T> | undefined>((resolve) => {
|
||||||
try {
|
try {
|
||||||
const result = func();
|
const result = func(...args);
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
@ -14,10 +14,10 @@ export async function solveProblem<T extends (...arg: any[]) => any>(func: T): P
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function solveAsyncProblem<T extends (...arg: any[]) => Promise<any>>(func: T): Promise<Awaited<ReturnType<T>> | undefined> {
|
export async function solveAsyncProblem<T extends (...args: any[]) => Promise<any>>(func: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>> | undefined> {
|
||||||
return new Promise<Awaited<ReturnType<T>> | undefined>(async (resolve) => {
|
return new Promise<Awaited<ReturnType<T>> | undefined>(async (resolve) => {
|
||||||
try {
|
try {
|
||||||
const result = await func();
|
const result = await func(...args);
|
||||||
resolve(result);
|
resolve(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
NodeIKernelGroupListener,
|
NodeIKernelGroupListener,
|
||||||
NodeIKernelGroupService,
|
NodeIKernelGroupService,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { isNumeric, runAllWithTimeout } from '@/common/utils/helper';
|
import { isNumeric, runAllWithTimeout, sleep } from '@/common/utils/helper';
|
||||||
|
|
||||||
export class NTQQGroupApi {
|
export class NTQQGroupApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@ -25,7 +25,9 @@ export class NTQQGroupApi {
|
|||||||
constructor(context: InstanceContext, core: NapCatCore) {
|
constructor(context: InstanceContext, core: NapCatCore) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.initCache().then().catch(context.logger.logError);
|
sleep(1000).then(() => {
|
||||||
|
this.initCache().then().catch(context.logger.logError);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
async initCache() {
|
async initCache() {
|
||||||
this.groups = await this.getGroups();
|
this.groups = await this.getGroups();
|
||||||
@ -269,10 +271,7 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getGroupMemberV2(GroupCode: string, uid: string, forced = false) {
|
async getGroupMemberV2(GroupCode: string, uid: string, forced = false) {
|
||||||
//type ListenerType = NodeIKernelGroupListener['onMemberInfoChange'];
|
|
||||||
type EventType = NodeIKernelGroupService['getMemberInfo'];
|
type EventType = NodeIKernelGroupService['getMemberInfo'];
|
||||||
// NTEventDispatch.CreatListenerFunction('NodeIKernelGroupListener/onGroupMemberInfoUpdate',
|
|
||||||
//return napCatCore.session.getGroupService().getMemberInfo(GroupCode, [uid], forced);
|
|
||||||
const Listener = this.core.eventWrapper.RegisterListen<(params: any) => void>
|
const Listener = this.core.eventWrapper.RegisterListen<(params: any) => void>
|
||||||
(
|
(
|
||||||
'NodeIKernelGroupListener/onMemberInfoChange',
|
'NodeIKernelGroupListener/onMemberInfoChange',
|
||||||
@ -294,20 +293,6 @@ export class NTQQGroupApi {
|
|||||||
member = members.get(uid);
|
member = members.get(uid);
|
||||||
}
|
}
|
||||||
return member;
|
return member;
|
||||||
|
|
||||||
// 原本的方法: (no_cache 下效率很高, cache 下效率一致)
|
|
||||||
// const [, , , _members] = await this.core.eventWrapper.CallNormalEvent<EventType, ListenerType>
|
|
||||||
// (
|
|
||||||
// 'NodeIKernelGroupService/getMemberInfo',
|
|
||||||
// 'NodeIKernelGroupListener/onMemberInfoChange',
|
|
||||||
// 1,
|
|
||||||
// 5000,
|
|
||||||
// (groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
|
|
||||||
// return groupCode == GroupCode && members.has(uid);
|
|
||||||
// },
|
|
||||||
// GroupCode, [uid], forced,
|
|
||||||
// );
|
|
||||||
// return _members.get(uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {
|
async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {
|
||||||
|
@ -75,7 +75,7 @@ export class OneBotGroupApi {
|
|||||||
const NTQQGroupApi = this.coreContext.apis.GroupApi;
|
const NTQQGroupApi = this.coreContext.apis.GroupApi;
|
||||||
const groupElement = grayTipElement?.groupElement;
|
const groupElement = grayTipElement?.groupElement;
|
||||||
if (!groupElement) return undefined;
|
if (!groupElement) return undefined;
|
||||||
const member = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.memberUid);
|
const member = await NTQQGroupApi.getGroupMemberV2(GroupCode, groupElement.memberUid);
|
||||||
const memberUin = member?.uin;
|
const memberUin = member?.uin;
|
||||||
const adminMember = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid);
|
const adminMember = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid);
|
||||||
if (memberUin) {
|
if (memberUin) {
|
||||||
|
@ -94,7 +94,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
|||||||
if (emojiLikeEvent) return emojiLikeEvent;
|
if (emojiLikeEvent) return emojiLikeEvent;
|
||||||
}
|
}
|
||||||
if (element.grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
if (element.grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
||||||
const GroupIncreaseEvent = await obContext.apiContext.GroupApi.parseGroupMemberIncreaseEvent(msg.peerUid, element.grayTipElement);
|
const GroupIncreaseEvent = await obContext.apiContext.GroupApi.parseGroupIncreaseEvent(msg.peerUid, element.grayTipElement);
|
||||||
if (GroupIncreaseEvent) return GroupIncreaseEvent;
|
if (GroupIncreaseEvent) return GroupIncreaseEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.2.7', 'napcat-update-button', 'secondary'),
|
SettingButton('V2.2.8', 'napcat-update-button', 'secondary'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@ -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.2.7", "napcat-update-button", "secondary")
|
SettingButton("V2.2.8", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user