From 3da1659c8d9be76b135e8ed03aab869fa9177a25 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: Sat, 20 Jul 2024 20:16:45 +0800 Subject: [PATCH] fix: buddylike --- src/core/src/apis/user.ts | 8 +++--- src/onebot11/action/extends/GetProfileLike.ts | 26 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/core/src/apis/user.ts b/src/core/src/apis/user.ts index 51865c7a..3a5f8bf6 100644 --- a/src/core/src/apis/user.ts +++ b/src/core/src/apis/user.ts @@ -35,10 +35,10 @@ setTimeout(() => { // } // }; export class NTQQUserApi { - static async getProfileLike(uin: string) { - return napCatCore.session.getProfileLikeService().getBuddyProfileLike( { + static async getProfileLike(uid: string) { + return napCatCore.session.getProfileLikeService().getBuddyProfileLike({ "friendUids": [ - (await NTQQUserApi.getUidByUin(uin))! + uid ], "basic": 1, "vote": 1, @@ -221,7 +221,7 @@ export class NTQQUserApi { if (Uin && Uin != 0 && !isNaN(Uin)) { return true } - logWarn("uin转换到uid时异常", Uid); + logWarn("uid转换到uin时异常", Uid); return false; }) static async getUinByUid(Uid: string | undefined) { diff --git a/src/onebot11/action/extends/GetProfileLike.ts b/src/onebot11/action/extends/GetProfileLike.ts index 9962459b..29da47c4 100644 --- a/src/onebot11/action/extends/GetProfileLike.ts +++ b/src/onebot11/action/extends/GetProfileLike.ts @@ -1,24 +1,16 @@ +import { selfInfo } from '@/core/data'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQUserApi } from '@/core/apis'; -import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -const SchemaData = { - type: 'object', - properties: { - user_id: { - type: ['number', 'string'] - } - }, - required: ['user_id'], -} as const satisfies JSONSchema; -type Payload = FromSchema; - -export class GetProfileLike extends BaseAction { +export class GetProfileLike extends BaseAction { actionName = ActionName.GetProfileLike; - PayloadSchema = SchemaData; - protected async _handle(payload: Payload) { - const ret = await NTQQUserApi.getProfileLike((await NTQQUserApi.getUidByUin(payload.user_id.toString()))!); - return ret.info; + protected async _handle(payload: void) { + let ret = await NTQQUserApi.getProfileLike(selfInfo.uid); + let listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos; + for (let i = 0; i < listdata.length; i++) { + listdata[i].uin = parseInt((await NTQQUserApi.getUinByUid(listdata[i].uid)) || ''); + } + return listdata; } }