From 57e72c197fc3a22d52cf78c0f94533649fe3fe35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 24 Jan 2025 20:39:52 +0800 Subject: [PATCH 1/3] fix: #733 --- src/common/cancel-task.ts | 39 +++++++++++--------- src/core/apis/group.ts | 27 ++++++++++++-- src/core/services/NodeIKernelGroupService.ts | 2 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/common/cancel-task.ts b/src/common/cancel-task.ts index 9d3de652..9fa8161a 100644 --- a/src/common/cancel-task.ts +++ b/src/common/cancel-task.ts @@ -1,4 +1,4 @@ -export type TaskExecutor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void, onCancel: (callback: () => void) => void) => void; +export type TaskExecutor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void, onCancel: (callback: () => void) => void) => void | Promise; export class CancelableTask { private promise: Promise; @@ -7,24 +7,30 @@ export class CancelableTask { private cancelListeners: Array<() => void> = []; constructor(executor: TaskExecutor) { - this.promise = new Promise((resolve, reject) => { + this.promise = new Promise(async (resolve, reject) => { const onCancel = (callback: () => void) => { this.cancelCallback = callback; }; - executor( - (value) => { - if (!this.isCanceled) { - resolve(value); - } - }, - (reason) => { - if (!this.isCanceled) { - reject(reason); - } - }, - onCancel - ); + try { + await executor( + (value) => { + if (!this.isCanceled) { + resolve(value); + } + }, + (reason) => { + if (!this.isCanceled) { + reject(reason); + } + }, + onCancel + ); + } catch (error) { + if (!this.isCanceled) { + reject(error); + } + } }); } @@ -68,9 +74,8 @@ export class CancelableTask { } } - async function demoAwait() { - const executor: TaskExecutor = (resolve, reject, onCancel) => { + const executor: TaskExecutor = async (resolve, reject, onCancel) => { let count = 0; const intervalId = setInterval(() => { count++; diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index ef58f651..a97d4bb1 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -9,10 +9,12 @@ import { NapCatCore, GroupNotify, GroupInfoSource, + ShutUpGroupMember, } from '@/core'; import { isNumeric, solveAsyncProblem } from '@/common/helper'; import { LimitedHashTable } from '@/common/message-unique'; import { NTEventWrapper } from '@/common/event'; +import { CancelableTask, TaskExecutor } from '@/common/cancel-task'; export class NTQQGroupApi { context: InstanceContext; @@ -58,9 +60,28 @@ export class NTQQGroupApi { } async getGroupShutUpMemberList(groupCode: string) { - const data = this.core.eventWrapper.registerListen('NodeIKernelGroupListener/onShutUpMemberListChanged', (group_id) => group_id === groupCode, 1, 1000); - this.context.session.getGroupService().getGroupShutUpMemberList(groupCode); - return (await data)[1]; + const executor: TaskExecutor = async (resolve, reject, onCancel) => { + this.core.eventWrapper.registerListen( + 'NodeIKernelGroupListener/onShutUpMemberListChanged', + (group_id) => group_id === groupCode, + 1, + 1000 + ).then((data) => { + resolve(data[1]) + }).catch(reject); + + onCancel(() => { + reject(new Error('Task was canceled')); + }); + }; + + const task = new CancelableTask(executor); + this.context.session.getGroupService().getGroupShutUpMemberList(groupCode).then(e => { + if (e.result !== 0) { + task.cancel() + } + }) + return await task.catch(() => []); } async clearGroupNotifiesUnreadCount(doubt: boolean) { diff --git a/src/core/services/NodeIKernelGroupService.ts b/src/core/services/NodeIKernelGroupService.ts index 49d2f881..2a4ed5a0 100644 --- a/src/core/services/NodeIKernelGroupService.ts +++ b/src/core/services/NodeIKernelGroupService.ts @@ -251,7 +251,7 @@ export interface NodeIKernelGroupService { setGroupShutUp(groupCode: string, shutUp: boolean): void; - getGroupShutUpMemberList(groupCode: string): Promise; + getGroupShutUpMemberList(groupCode: string): Promise; setMemberShutUp(groupCode: string, memberTimes: { uid: string, timeStamp: number }[]): Promise; From e069e0e8aa223e648e404ece5cf80afd34a106db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 24 Jan 2025 20:42:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?re:=20=E7=A7=BB=E9=99=A4=20FetchUserProfile?= =?UTF-8?q?Like?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/extends/FetchUserProfileLike.ts | 17 ----------------- src/onebot/action/index.ts | 3 --- src/onebot/action/router.ts | 1 - 3 files changed, 21 deletions(-) delete mode 100644 src/onebot/action/extends/FetchUserProfileLike.ts diff --git a/src/onebot/action/extends/FetchUserProfileLike.ts b/src/onebot/action/extends/FetchUserProfileLike.ts deleted file mode 100644 index fb083e33..00000000 --- a/src/onebot/action/extends/FetchUserProfileLike.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { OneBotAction } from '@/onebot/action/OneBotAction'; -import { ActionName } from '@/onebot/action/router'; -import { Type, Static } from '@sinclair/typebox'; - -const SchemaData = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()]), -}); - -type Payload = Static; - -export class FetchUserProfileLike extends OneBotAction { - actionName = ActionName.FetchUserProfileLike; - payloadSchema = SchemaData; - async _handle(payload: Payload) { - return await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); - } -} diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index 81f31882..72ffb640 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -66,7 +66,6 @@ import SetGroupPortrait from './go-cqhttp/SetGroupPortrait'; import { FetchCustomFace } from './extends/FetchCustomFace'; import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivateFile'; import { FetchEmojiLike } from './extends/FetchEmojiLike'; -import { FetchUserProfileLike } from './extends/FetchUserProfileLike'; import { NapCatCore } from '@/core'; import { NapCatOneBot11Adapter } from '@/onebot'; import { SetInputStatus } from './extends/SetInputStatus'; @@ -205,8 +204,6 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo new DeleteGroupFileFolder(obContext, core), new GetGroupFileSystemInfo(obContext, core), new GetGroupFilesByFolder(obContext, core), - new GetGroupSystemMsg(obContext, core), - new FetchUserProfileLike(obContext, core), new GetPacketStatus(obContext, core), new GroupPoke(obContext, core), new FriendPoke(obContext, core), diff --git a/src/onebot/action/router.ts b/src/onebot/action/router.ts index 7b79c50f..711fdc57 100644 --- a/src/onebot/action/router.ts +++ b/src/onebot/action/router.ts @@ -122,7 +122,6 @@ export const ActionName = { GetGroupInfoEx: 'get_group_info_ex', GetGroupIgnoreAddRequest: 'get_group_ignore_add_request', DelGroupNotice: '_del_group_notice', - FetchUserProfileLike: 'fetch_user_profile_like', FriendPoke: 'friend_poke', GroupPoke: 'group_poke', GetPacketStatus: 'nc_get_packet_status', From 15aa1fd0b8a4e8cebf1425435f9ef1aee413f731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 24 Jan 2025 21:03:15 +0800 Subject: [PATCH 3/3] fix: NTVoteInfo type --- .../services/NodeIKernelProfileLikeService.ts | 13 +++++++++++-- src/core/types/user.ts | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/core/services/NodeIKernelProfileLikeService.ts b/src/core/services/NodeIKernelProfileLikeService.ts index b4682a31..5bc413d5 100644 --- a/src/core/services/NodeIKernelProfileLikeService.ts +++ b/src/core/services/NodeIKernelProfileLikeService.ts @@ -1,4 +1,4 @@ -import { BuddyProfileLikeReq, GeneralCallResult } from '@/core'; +import { BuddyProfileLikeReq, GeneralCallResult, NTVoteInfo } from '@/core'; export interface NodeIKernelProfileLikeService { addKernelProfileLikeListener(listener: unknown): number; @@ -9,7 +9,16 @@ export interface NodeIKernelProfileLikeService { getBuddyProfileLike(req: BuddyProfileLikeReq): Promise, + userLikeInfos: Array<{ + voteInfo: { + total_count: number, + new_count: number, + new_nearby_count: number, + last_visit_time: number, + userInfos: Array + } + + }>, friendMaxVotes: number, start: number } diff --git a/src/core/types/user.ts b/src/core/types/user.ts index 25d29d0e..1757c308 100644 --- a/src/core/types/user.ts +++ b/src/core/types/user.ts @@ -5,6 +5,25 @@ export enum NTSex { GENDER_FEMALE = 2, GENDER_PRIVACY = 255, } +export interface NTVoteInfo { + age: number; + bAvailableCnt: number; + bTodayVotedCnt: number; + count: number; + customId: number; + gender: number; + giftCount: number; + isFriend: boolean; + isSvip: boolean; + isvip: boolean; + lastCharged: number; + latestTime: number; + nick: string; + src: number; + uid: string; + uin: number; +} + // 好友分类类型 export interface BuddyCategoryType {