From 9738c3f63c0bfa9ab133f9f6f58007a5f674722d Mon Sep 17 00:00:00 2001 From: idranme Date: Tue, 10 Sep 2024 13:36:00 +0800 Subject: [PATCH] feat: GetProfileLike --- src/ntqqapi/api/user.ts | 15 +++++++++++++++ src/ntqqapi/core.ts | 6 ------ src/ntqqapi/hook.ts | 7 +++---- src/ntqqapi/ntcall.ts | 1 - .../services/NodeIKernelProfileLikeService.ts | 15 +++++++++++++-- src/onebot11/action/index.ts | 2 ++ src/onebot11/action/llonebot/GetProfileLike.ts | 17 +++++++++++++++++ src/onebot11/action/types.ts | 1 + 8 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 src/onebot11/action/llonebot/GetProfileLike.ts diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index 3fa39cf..f6836af 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -296,4 +296,19 @@ export class NTQQUserApi extends Service { } }, null]) } + + async getProfileLike(uid: string) { + return await invoke('nodeIKernelProfileLikeService/getBuddyProfileLike', [{ + req: { + friendUids: [uid], + basic: 1, + vote: 1, + favorite: 0, + userProfile: 1, + type: 2, + start: 0, + limit: 20, + } + }, null]) + } } diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index 156c7be..402abba 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -185,12 +185,6 @@ class Core extends Service { }) registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, payload => { - const { msgId, chatType, peerUid } = payload.msgRecord - const peer = { - chatType, - peerUid - } - MessageUnique.createMsg(peer, msgId) if (!this.config.reportSelfMessage) { return } diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index 06b715f..eddfa16 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -82,8 +82,7 @@ export function hookNTQQApiReceive(window: BrowserWindow, onlyLog: boolean) { } } } - const ret = target.apply(thisArg, args) - return ret + return target.apply(thisArg, args) }, }) } @@ -143,7 +142,7 @@ export function hookNTQQApiCall(window: BrowserWindow, onlyLog: boolean) { } export function registerReceiveHook( - method: ReceiveCmdS | ReceiveCmdS[], + method: string | string[], hookFunc: (payload: PayloadType) => void, ): string { const id = randomUUID() @@ -151,7 +150,7 @@ export function registerReceiveHook( method = [method] } receiveHooks.push({ - method, + method: method as ReceiveCmdS[], hookFunc, id, }) diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index 0148d89..de47f0d 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -136,7 +136,6 @@ export function invoke< // 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据 const secondCallback = () => { const hookId = registerReceiveHook(options.cbCmd!, (payload) => { - // log(methodName, "second callback", cbCmd, payload, cmdCB); if (options.cmdCB) { if (options.cmdCB(payload, result)) { removeReceiveHook(hookId) diff --git a/src/ntqqapi/services/NodeIKernelProfileLikeService.ts b/src/ntqqapi/services/NodeIKernelProfileLikeService.ts index 52835f9..da29f2c 100644 --- a/src/ntqqapi/services/NodeIKernelProfileLikeService.ts +++ b/src/ntqqapi/services/NodeIKernelProfileLikeService.ts @@ -1,5 +1,6 @@ import { BuddyProfileLikeReq } from '../types' import { GeneralCallResult } from './common' +import { Dict } from 'cosmokit' export interface NodeIKernelProfileLikeService { addKernelProfileLikeListener(listener: NodeIKernelProfileLikeService): void @@ -10,8 +11,18 @@ export interface NodeIKernelProfileLikeService { getBuddyProfileLike(req: BuddyProfileLikeReq): Promise, - friendMaxVotes: number, + userLikeInfos: { + uid: string + time: string + favoriteInfo: { + total_count: number + last_time: number + today_count: number + userInfos: Dict[] + } + voteInfo: Dict + }[] + friendMaxVotes: number start: number } }> diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index be36f77..756246b 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -62,6 +62,7 @@ import { GetGroupAtAllRemain } from './go-cqhttp/GetGroupAtAllRemain' import { GetGroupRootFiles } from './go-cqhttp/GetGroupRootFiles' import { SetOnlineStatus } from './llonebot/SetOnlineStatus' import { SendGroupNotice } from './go-cqhttp/SendGroupNotice' +import { GetProfileLike } from './llonebot/GetProfileLike' export function initActionMap(adapter: Adapter) { const actionHandlers = [ @@ -74,6 +75,7 @@ export function initActionMap(adapter: Adapter) { new GetFriendWithCategory(adapter), new GetEvent(adapter), new SetOnlineStatus(adapter), + new GetProfileLike(adapter), // onebot11 new SendLike(adapter), new GetMsg(adapter), diff --git a/src/onebot11/action/llonebot/GetProfileLike.ts b/src/onebot11/action/llonebot/GetProfileLike.ts new file mode 100644 index 0000000..af08e02 --- /dev/null +++ b/src/onebot11/action/llonebot/GetProfileLike.ts @@ -0,0 +1,17 @@ +import BaseAction from '../BaseAction' +import { ActionName } from '../types' +import { selfInfo } from '@/common/globalVars' +import { Dict } from 'cosmokit' + +export class GetProfileLike extends BaseAction { + actionName = ActionName.GetProfileLike + + async _handle() { + const ret = await this.ctx.ntUserApi.getProfileLike(selfInfo.uid) + const listdata = ret.info.userLikeInfos[0].favoriteInfo.userInfos + for (const item of listdata) { + item.uin = Number(await this.ctx.ntUserApi.getUinByUid(item.uid)) || 0 + } + return listdata + } +} \ No newline at end of file diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 382ee69..13c151b 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -20,6 +20,7 @@ export enum ActionName { GetFriendsWithCategory = 'get_friends_with_category', GetEvent = 'get_event', SetOnlineStatus = 'set_online_status', + GetProfileLike = 'get_profile_like', // onebot 11 SendLike = 'send_like', GetLoginInfo = 'get_login_info',