mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: move all callNormalEvent
calls to V2
substitutes
This commit is contained in:
parent
7092894d22
commit
7aa0bd9b79
@ -158,11 +158,11 @@ export class LegacyNTEventWrapper {
|
||||
>(
|
||||
serviceAndMethod: `${Service}/${ServiceMethod}`,
|
||||
listenerAndMethod: `${Listener}/${ListenerMethod}`,
|
||||
waitTimes = 1,
|
||||
timeout: number = 3000,
|
||||
args: Parameters<EventType>,
|
||||
checkerEvent: (ret: Awaited<ReturnType<EventType>>) => boolean = () => true,
|
||||
checkerListener: (...args: Parameters<ListenerType>) => boolean = () => true,
|
||||
...args: Parameters<EventType>
|
||||
callbackTimesToWait = 1,
|
||||
timeout = 5000,
|
||||
) {
|
||||
return new Promise<[EventRet: Awaited<ReturnType<EventType>>, ...Parameters<ListenerType>]>(
|
||||
async (resolve, reject) => {
|
||||
@ -202,7 +202,7 @@ export class LegacyNTEventWrapper {
|
||||
func: (...args: any[]) => {
|
||||
complete++;
|
||||
retData = args as Parameters<ListenerType>;
|
||||
if (complete >= waitTimes) {
|
||||
if (complete >= callbackTimesToWait) {
|
||||
clearTimeout(timeoutRef);
|
||||
sendDataCallback();
|
||||
}
|
||||
@ -216,8 +216,8 @@ export class LegacyNTEventWrapper {
|
||||
}
|
||||
this.EventTask.get(ListenerMainName)?.get(ListenerSubName)?.set(id, eventCallback);
|
||||
this.createListenerFunction(ListenerMainName);
|
||||
const EventFunc = this.createEventFunction<EventType>(serviceAndMethod);
|
||||
retEvent = await EventFunc!(...(args as any[]));
|
||||
const eventFunction = this.createEventFunction<EventType>(serviceAndMethod);
|
||||
retEvent = await eventFunction!(...(args));
|
||||
if (!checkerEvent(retEvent)) {
|
||||
clearTimeout(timeoutRef);
|
||||
reject(
|
||||
@ -236,6 +236,7 @@ export class LegacyNTEventWrapper {
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
async callNormalEvent<
|
||||
Service extends keyof ServiceNamingMapping,
|
||||
ServiceMethod extends Exclude<keyof ServiceNamingMapping[Service], symbol>,
|
||||
@ -312,4 +313,5 @@ export class LegacyNTEventWrapper {
|
||||
},
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import {
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import fsPromises from 'fs/promises';
|
||||
import { InstanceContext, NapCatCore, OnRichMediaDownloadCompleteParams } from '@/core';
|
||||
import { InstanceContext, NapCatCore } from '@/core';
|
||||
import * as fileType from 'file-type';
|
||||
import imageSize from 'image-size';
|
||||
import { ISizeCalculationResult } from 'image-size/dist/types/interface';
|
||||
@ -304,18 +304,10 @@ export class NTQQFileApi {
|
||||
return sourcePath;
|
||||
}
|
||||
}
|
||||
const [, fileTransNotifyInfo] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [, fileTransNotifyInfo] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelMsgService/downloadRichMedia',
|
||||
'NodeIKernelMsgListener/onRichMediaDownloadComplete',
|
||||
1,
|
||||
timeout,
|
||||
(arg: OnRichMediaDownloadCompleteParams) => {
|
||||
if (arg.msgId === msgId) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
{
|
||||
[{
|
||||
fileModelId: '0',
|
||||
downloadSourceType: 0,
|
||||
triggerType: 1,
|
||||
@ -326,7 +318,11 @@ export class NTQQFileApi {
|
||||
thumbSize: 0,
|
||||
downloadType: 1,
|
||||
filePath: thumbPath,
|
||||
},
|
||||
}],
|
||||
() => true,
|
||||
(arg) => arg.msgId === msgId,
|
||||
1,
|
||||
timeout,
|
||||
);
|
||||
const msg = await this.core.apis.MsgApi.getMsgsByMsgId({
|
||||
guildId: '',
|
||||
@ -482,7 +478,7 @@ export class NTQQFileApi {
|
||||
const url: string = element.originImageUrl!; // 没有域名
|
||||
const md5HexStr = element.md5HexStr;
|
||||
const fileMd5 = element.md5HexStr;
|
||||
const fileUuid = element.fileUuid;
|
||||
// const fileUuid = element.fileUuid;
|
||||
|
||||
if (url) {
|
||||
const UrlParse = new URL(IMAGE_HTTP_HOST + url);//临时解析拼接
|
||||
@ -554,7 +550,7 @@ export class NTQQFileCacheApi {
|
||||
}
|
||||
|
||||
getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||
const _lastRecord = lastRecord ? lastRecord : { fileType: fileType };
|
||||
// const _lastRecord = lastRecord ? lastRecord : { fileType: fileType };
|
||||
// 需要五个参数
|
||||
// return napCatCore.session.getStorageCleanService().getFileCacheInfo();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { LimitedHashTable } from '@/common/utils/message-unique';
|
||||
export class NTQQFriendApi {
|
||||
context: InstanceContext;
|
||||
core: NapCatCore;
|
||||
|
||||
// friends: Map<string, Friend> = new Map<string, FriendV2>();
|
||||
|
||||
constructor(context: InstanceContext, core: NapCatCore) {
|
||||
@ -70,15 +71,17 @@ export class NTQQFriendApi {
|
||||
async isBuddy(uid: string) {
|
||||
return this.context.session.getBuddyService().isBuddy(uid);
|
||||
}
|
||||
|
||||
async clearBuddyReqUnreadCnt() {
|
||||
return this.context.session.getBuddyService().clearBuddyReqUnreadCnt();
|
||||
}
|
||||
|
||||
async getBuddyReq() {
|
||||
const [, ret] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelBuddyService/getBuddyReq',
|
||||
'NodeIKernelBuddyListener/onBuddyReqChange',
|
||||
1,
|
||||
5000);
|
||||
[],
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,11 @@ import {
|
||||
Group,
|
||||
GroupMember,
|
||||
GroupMemberRole,
|
||||
GroupNotify,
|
||||
GroupRequestOperateTypes,
|
||||
InstanceContext,
|
||||
KickMemberV2Req,
|
||||
MemberExtSourceType,
|
||||
NapCatCore,
|
||||
NodeIKernelGroupListener,
|
||||
NodeIKernelGroupService,
|
||||
} from '@/core';
|
||||
import { isNumeric, runAllWithTimeout, sleep } from '@/common/utils/helper';
|
||||
@ -42,14 +40,10 @@ export class NTQQGroupApi {
|
||||
}
|
||||
|
||||
async getGroups(forced = false) {
|
||||
type ListenerType = NodeIKernelGroupListener['onGroupListUpdate'];
|
||||
const [,, groupList] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [,, groupList] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelGroupService/getGroupList',
|
||||
'NodeIKernelGroupListener/onGroupListUpdate',
|
||||
1,
|
||||
5000,
|
||||
() => true,
|
||||
forced,
|
||||
[forced],
|
||||
);
|
||||
return groupList;
|
||||
}
|
||||
@ -254,15 +248,14 @@ export class NTQQGroupApi {
|
||||
}
|
||||
|
||||
async getSingleScreenNotifies(num: number) {
|
||||
const [,,, notifies] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [,,, notifies] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelGroupService/getSingleScreenNotifies',
|
||||
'NodeIKernelGroupListener/onGroupSingleScreenNotifies',
|
||||
1,
|
||||
5000,
|
||||
() => true,
|
||||
[
|
||||
false,
|
||||
'',
|
||||
num,
|
||||
num
|
||||
],
|
||||
);
|
||||
return notifies;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export class NTQQMsgApi {
|
||||
async getMsgEmojiLikesList(peer: Peer, msgSeq: string, emojiId: string, emojiType: string, count: number = 20) {
|
||||
//console.log(peer, msgSeq, emojiId, emojiType, count);
|
||||
//注意此处emojiType 可选值一般为1-2 2好像是unicode表情dec值 大部分情况 Taged M likiowa
|
||||
return this.context.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, '', false, 20);
|
||||
return this.context.session.getMsgService().getMsgEmojiLikesList(peer, msgSeq, emojiId, emojiType, '', false, count);
|
||||
}
|
||||
|
||||
// napCatCore: NapCatCore | null = null;
|
||||
@ -50,7 +50,7 @@ export class NTQQMsgApi {
|
||||
}
|
||||
|
||||
async getLastestMsgByUids(peer: Peer, count: number = 20, isReverseOrder: boolean = false) {
|
||||
const ret = await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
|
||||
return await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
|
||||
chatInfo: peer,
|
||||
filterMsgType: [],
|
||||
filterSendersUid: [],
|
||||
@ -60,7 +60,6 @@ export class NTQQMsgApi {
|
||||
isIncludeCurrent: true,
|
||||
pageLimit: count,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getMsgsByMsgId(peer: Peer | undefined, msgIds: string[] | undefined) {
|
||||
@ -79,7 +78,7 @@ export class NTQQMsgApi {
|
||||
}
|
||||
|
||||
async queryMsgsWithFilterExWithSeq(peer: Peer, msgSeq: string) {
|
||||
const ret = await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
||||
return await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
||||
chatInfo: peer,//此处为Peer 为关键查询参数 没有啥也没有 by mlik iowa
|
||||
filterMsgType: [],
|
||||
filterSendersUid: [],
|
||||
@ -89,7 +88,6 @@ export class NTQQMsgApi {
|
||||
isIncludeCurrent: true,
|
||||
pageLimit: 1,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) {
|
||||
@ -99,7 +97,7 @@ export class NTQQMsgApi {
|
||||
const DateNow = Math.floor(Date.now() / 1000);
|
||||
const filterMsgFromTime = (DateNow - 300).toString();
|
||||
const filterMsgToTime = DateNow.toString();
|
||||
const ret = await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
||||
return await this.context.session.getMsgService().queryMsgsWithFilterEx('0', '0', msgSeq, {
|
||||
chatInfo: peer,//此处为Peer 为关键查询参数 没有啥也没有 by mlik iowa
|
||||
filterMsgType: [],
|
||||
filterSendersUid: [],
|
||||
@ -109,24 +107,26 @@ export class NTQQMsgApi {
|
||||
isIncludeCurrent: true,
|
||||
pageLimit: 100,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
async setMsgRead(peer: Peer) {
|
||||
return this.context.session.getMsgService().setMsgRead(peer);
|
||||
}
|
||||
|
||||
async getGroupFileList(GroupCode: string, params: GetFileListParam) {
|
||||
const [, groupFileListResult] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [, groupFileListResult] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelRichMediaService/getGroupFileList',
|
||||
'NodeIKernelMsgListener/onGroupFileInfoUpdate',
|
||||
1,
|
||||
5000,
|
||||
[
|
||||
GroupCode,
|
||||
params
|
||||
],
|
||||
() => true,
|
||||
( /* groupFileListResult: GroupFileInfoUpdateParamType */) => {
|
||||
//Developer Mlikiowa Todo: 此处有问题 无法判断是否成功
|
||||
return true;
|
||||
},
|
||||
GroupCode,
|
||||
params,
|
||||
1,
|
||||
5000,
|
||||
);
|
||||
return groupFileListResult.item;
|
||||
}
|
||||
@ -175,12 +175,17 @@ export class NTQQMsgApi {
|
||||
}
|
||||
const msgId = await this.generateMsgUniqueId(peer.chatType, await this.getServerTime());
|
||||
peer.guildId = msgId;
|
||||
const [, msgList] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [, msgList] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelMsgService/sendMsg',
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
timeout,
|
||||
(msgRecords: RawMessage[]) => {
|
||||
[
|
||||
'0',
|
||||
peer,
|
||||
msgElements,
|
||||
new Map()
|
||||
],
|
||||
() => true,
|
||||
msgRecords => {
|
||||
for (const msgRecord of msgRecords) {
|
||||
if (msgRecord.guildId === msgId && msgRecord.sendStatus === SendStatusType.KSEND_STATUS_SUCCESS) {
|
||||
return true;
|
||||
@ -188,10 +193,8 @@ export class NTQQMsgApi {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
'0',
|
||||
peer,
|
||||
msgElements,
|
||||
new Map(),
|
||||
1,
|
||||
timeout,
|
||||
);
|
||||
return msgList.find(msgRecord => {
|
||||
if (msgRecord.guildId === msgId) {
|
||||
@ -216,12 +219,18 @@ export class NTQQMsgApi {
|
||||
const msgInfos = msgIds.map(id => {
|
||||
return { msgId: id, senderShowName: this.core.selfInfo.nick };
|
||||
});
|
||||
const [, msgList] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [, msgList] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelMsgService/multiForwardMsgWithComment',
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
5000,
|
||||
(msgRecords: RawMessage[]) => {
|
||||
[
|
||||
msgInfos,
|
||||
srcPeer,
|
||||
destPeer,
|
||||
[],
|
||||
new Map(),
|
||||
],
|
||||
() => true,
|
||||
(msgRecords) => {
|
||||
for (const msgRecord of msgRecords) {
|
||||
if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == this.core.selfInfo.uid) {
|
||||
return true;
|
||||
@ -229,11 +238,6 @@ export class NTQQMsgApi {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
msgInfos,
|
||||
srcPeer,
|
||||
destPeer,
|
||||
[],
|
||||
new Map(),
|
||||
);
|
||||
for (const msg of msgList) {
|
||||
const arkElement = msg.elements.find(ele => ele.arkElement);
|
||||
|
@ -1,7 +1,6 @@
|
||||
import type { ModifyProfileParams, User, UserDetailInfoByUin, UserDetailInfoByUinV2 } from '@/core/entities';
|
||||
import { NodeIKernelProfileListener } from '@/core/listeners';
|
||||
import type { ModifyProfileParams, User, UserDetailInfoByUinV2 } from '@/core/entities';
|
||||
import { RequestUtil } from '@/common/utils/request';
|
||||
import { NodeIKernelProfileService, ProfileBizType, UserDetailSource } from '@/core/services';
|
||||
import { ProfileBizType, UserDetailSource } from '@/core/services';
|
||||
import { InstanceContext, NapCatCore } from '..';
|
||||
import { solveAsyncProblem } from '@/common/utils/helper';
|
||||
|
||||
@ -65,15 +64,18 @@ export class NTQQUserApi {
|
||||
}
|
||||
|
||||
async fetchUserDetailInfos(uids: string[]) {
|
||||
//26702 以上使用新接口 .Dev Mlikiowa
|
||||
type EventService = NodeIKernelProfileService['fetchUserDetailInfo'];
|
||||
type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged'];
|
||||
// TODO: 26702 以上使用新接口 .Dev MliKiowa
|
||||
const retData: User[] = [];
|
||||
const [_retData, _retListener] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [_retData, _retListener] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelProfileService/fetchUserDetailInfo',
|
||||
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||
uids.length,
|
||||
5000,
|
||||
[
|
||||
'BuddyProfileStore',
|
||||
uids,
|
||||
UserDetailSource.KSERVER,
|
||||
[ProfileBizType.KALL]
|
||||
],
|
||||
() => true,
|
||||
(profile) => {
|
||||
if (uids.includes(profile.uid)) {
|
||||
const RetUser: User = {
|
||||
@ -90,26 +92,24 @@ export class NTQQUserApi {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
'BuddyProfileStore',
|
||||
uids,
|
||||
UserDetailSource.KSERVER,
|
||||
[ProfileBizType.KALL],
|
||||
uids.length,
|
||||
);
|
||||
|
||||
return retData;
|
||||
}
|
||||
|
||||
async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) {
|
||||
const [_retData, profile] = await this.core.eventWrapper.callNormalEvent(
|
||||
const [_retData, profile] = await this.core.eventWrapper.callNormalEventV2(
|
||||
'NodeIKernelProfileService/fetchUserDetailInfo',
|
||||
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||
1,
|
||||
5000,
|
||||
(profile) => profile.uid === uid,
|
||||
[
|
||||
'BuddyProfileStore',
|
||||
[uid],
|
||||
mode,
|
||||
[ProfileBizType.KALL],
|
||||
[ProfileBizType.KALL]
|
||||
],
|
||||
() => true,
|
||||
(profile) => profile.uid === uid,
|
||||
);
|
||||
const RetUser: User = {
|
||||
...profile.simpleInfo.coreInfo,
|
||||
@ -142,8 +142,7 @@ export class NTQQUserApi {
|
||||
const ClientKeyData = await this.forceFetchClientKey();
|
||||
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + this.core.selfInfo.uin +
|
||||
'&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + this.core.selfInfo.uin + '%2Finfocenter&keyindex=19%27';
|
||||
const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl);
|
||||
return cookies;
|
||||
return await RequestUtil.HttpsGetCookies(requestUrl);
|
||||
}
|
||||
|
||||
async getPSkey(domainList: string[]) {
|
||||
@ -166,8 +165,7 @@ export class NTQQUserApi {
|
||||
async getQzoneCookies() {
|
||||
const ClientKeyData = await this.forceFetchClientKey();
|
||||
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + this.core.selfInfo.uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + this.core.selfInfo.uin + '%2Finfocenter&keyindex=19%27';
|
||||
const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl);
|
||||
return cookies;
|
||||
return await RequestUtil.HttpsGetCookies(requestUrl);
|
||||
}
|
||||
|
||||
//需要异常处理
|
||||
@ -178,7 +176,7 @@ export class NTQQUserApi {
|
||||
throw new Error('getClientKey Error');
|
||||
}
|
||||
const clientKey = ClientKeyData.clientKey;
|
||||
const keyIndex = ClientKeyData.keyIndex;
|
||||
// const keyIndex = ClientKeyData.keyIndex;
|
||||
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + this.core.selfInfo.uin + '&clientkey=' + clientKey + '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=19%27';
|
||||
const cookies: { [key: string]: string; } = await RequestUtil.HttpsGetCookies(requestUrl);
|
||||
const skey = cookies['skey'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user