diff --git a/src/ntqqapi/api/webapi.ts b/src/ntqqapi/api/webapi.ts index 130e1e3..c6296ed 100644 --- a/src/ntqqapi/api/webapi.ts +++ b/src/ntqqapi/api/webapi.ts @@ -17,39 +17,6 @@ export enum WebHonorType { EMOTION = 'emotion' } -export interface WebApiGroupMember { - uin: number - role: number - g: number - join_time: number - last_speak_time: number - lv: { - point: number - level: number - } - card: string - tags: string - flag: number - nick: string - qage: number - rm: number -} - -interface WebApiGroupMemberRet { - ec: number - errcode: number - em: string - cache: number - adm_num: number - levelname: unknown - mems: WebApiGroupMember[] - count: number - svr_time: number - max_count: number - search_count: number - extmode: number -} - export class NTQQWebApi extends Service { static inject = ['ntUserApi'] @@ -57,47 +24,6 @@ export class NTQQWebApi extends Service { super(ctx, 'ntWebApi', true) } - async getGroupMembers(groupCode: string): Promise { - const memberData: Array = new Array() - const cookieObject = await this.ctx.ntUserApi.getCookies('qun.qq.com') - const cookieStr = this.cookieToString(cookieObject) - const retList: Promise[] = [] - const params = new URLSearchParams({ - st: '0', - end: '40', - sort: '1', - gc: groupCode, - bkn: this.genBkn(cookieObject.skey) - }) - const fastRet = await RequestUtil.HttpGetJson(`https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?${params}`, 'POST', '', { 'Cookie': cookieStr }) - if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) { - return [] - } else { - for (const member of fastRet.mems) { - memberData.push(member) - } - } - const pageNum = Math.ceil(fastRet.count / 40) - //遍历批量请求 - for (let i = 2; i <= pageNum; i++) { - params.set('st', String((i - 1) * 40)) - params.set('end', String(i * 40)) - const ret = RequestUtil.HttpGetJson(`https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?${params}`, 'POST', '', { 'Cookie': cookieStr }) - retList.push(ret) - } - //批量等待 - for (let i = 1; i <= pageNum; i++) { - const ret = await (retList[i]) - if (!ret?.count || ret?.errcode !== 0 || !ret?.mems) { - continue - } - for (const member of ret.mems) { - memberData.push(member) - } - } - return memberData - } - genBkn(sKey: string) { sKey = sKey || '' let hash = 5381 diff --git a/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts b/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts index a4815bd..89e735f 100644 --- a/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts +++ b/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts @@ -5,7 +5,7 @@ interface Payload { message_id: number | string } -export class DelEssenceMsg extends BaseAction { +export class DeleteEssenceMsg extends BaseAction { actionName = ActionName.GoCQHTTP_DelEssenceMsg payloadSchema = Schema.object({ message_id: Schema.union([Number, String]).required() diff --git a/src/onebot11/action/group/GetGroupEssence.ts b/src/onebot11/action/go-cqhttp/GetGroupEssence.ts similarity index 95% rename from src/onebot11/action/group/GetGroupEssence.ts rename to src/onebot11/action/go-cqhttp/GetGroupEssence.ts index 06d78da..fa4aa11 100644 --- a/src/onebot11/action/group/GetGroupEssence.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupEssence.ts @@ -16,7 +16,7 @@ interface EssenceMsg { message_id: number } -export class GetGroupEssence extends BaseAction { +export class GetEssenceMsgList extends BaseAction { actionName = ActionName.GoCQHTTP_GetEssenceMsgList payloadSchema = Schema.object({ group_id: Schema.union([Number, String]).required() diff --git a/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts b/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts index 6bfbc0f..dc124b6 100644 --- a/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts +++ b/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts @@ -1,24 +1,22 @@ -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' interface Payload { message_id: number | string } -export class SetEssenceMsg extends BaseAction { +export class SetEssenceMsg extends BaseAction { actionName = ActionName.GoCQHTTP_SetEssenceMsg + payloadSchema = Schema.object({ + message_id: Schema.union([Number, String]).required() + }) protected async _handle(payload: Payload) { - if (!payload.message_id) { - throw Error('message_id不能为空') - } const msg = await this.ctx.store.getMsgInfoByShortId(+payload.message_id) if (!msg) { throw new Error('msg not found') } - return await this.ctx.ntGroupApi.addGroupEssence( - msg.peer.peerUid, - msg.msgId - ) + await this.ctx.ntGroupApi.addGroupEssence(msg.peer.peerUid, msg.msgId) + return null } } diff --git a/src/onebot11/action/go-cqhttp/UploadGroupFile.ts b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts new file mode 100644 index 0000000..10ba0e5 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts @@ -0,0 +1,35 @@ +import { BaseAction, Schema } from '../BaseAction' +import { ActionName } from '../types' +import { SendElementEntities } from '@/ntqqapi/entities' +import { uri2local } from '@/common/utils' +import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage' + +interface Payload { + group_id: number | string + file: string + name: string + folder?: string + folder_id?: string +} + +export class UploadGroupFile extends BaseAction { + actionName = ActionName.GoCQHTTP_UploadGroupFile + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required(), + file: Schema.string().required(), + name: Schema.string(), + folder: Schema.string(), + folder_id: Schema.string() + }) + + protected async _handle(payload: Payload): Promise { + const { success, errMsg, path, fileName } = await uri2local(payload.file) + if (!success) { + throw new Error(errMsg) + } + const file = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id) + const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group) + await sendMsg(this.ctx, peer, [file], []) + return null + } +} diff --git a/src/onebot11/action/go-cqhttp/UploadFile.ts b/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts similarity index 53% rename from src/onebot11/action/go-cqhttp/UploadFile.ts rename to src/onebot11/action/go-cqhttp/UploadPrivateFile.ts index c52b36f..667b791 100644 --- a/src/onebot11/action/go-cqhttp/UploadFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts @@ -1,32 +1,9 @@ -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { SendElementEntities } from '@/ntqqapi/entities' import { uri2local } from '@/common/utils' import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage' -interface UploadGroupFilePayload { - group_id: number | string - file: string - name: string - folder?: string - folder_id?: string -} - -export class UploadGroupFile extends BaseAction { - actionName = ActionName.GoCQHTTP_UploadGroupFile - - protected async _handle(payload: UploadGroupFilePayload): Promise { - const { success, errMsg, path, fileName } = await uri2local(payload.file) - if (!success) { - throw new Error(errMsg) - } - const file = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id) - const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group) - await sendMsg(this.ctx, peer, [file], []) - return null - } -} - interface UploadPrivateFilePayload { user_id: number | string file: string @@ -35,6 +12,11 @@ interface UploadPrivateFilePayload { export class UploadPrivateFile extends BaseAction { actionName = ActionName.GoCQHTTP_UploadPrivateFile + payloadSchema = Schema.object({ + user_id: Schema.union([Number, String]).required(), + file: Schema.string().required(), + name: Schema.string() + }) protected async _handle(payload: UploadPrivateFilePayload): Promise { const { success, errMsg, path, fileName } = await uri2local(payload.file) diff --git a/src/onebot11/action/group/GetGroupInfo.ts b/src/onebot11/action/group/GetGroupInfo.ts index 30d0357..cc3faf1 100644 --- a/src/onebot11/action/group/GetGroupInfo.ts +++ b/src/onebot11/action/group/GetGroupInfo.ts @@ -1,6 +1,6 @@ import { OB11Group } from '../../types' import { OB11Entities } from '../../entities' -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' interface Payload { @@ -9,14 +9,17 @@ interface Payload { class GetGroupInfo extends BaseAction { actionName = ActionName.GetGroupInfo + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required() + }) protected async _handle(payload: Payload) { - const group = (await this.ctx.ntGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString()) + const groupCode = payload.group_id.toString() + const group = (await this.ctx.ntGroupApi.getGroups()).find(e => e.groupCode === groupCode) if (group) { return OB11Entities.group(group) - } else { - throw `群${payload.group_id}不存在` } + throw new Error(`群${payload.group_id}不存在`) } } diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index e47b1be..8fe323c 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -1,8 +1,7 @@ -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { OB11GroupMember } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' -import { selfInfo } from '@/common/globalVars' import { isNullable } from 'cosmokit' interface Payload { @@ -12,35 +11,26 @@ interface Payload { class GetGroupMemberInfo extends BaseAction { actionName = ActionName.GetGroupMemberInfo + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required(), + user_id: Schema.union([Number, String]).required() + }) protected async _handle(payload: Payload) { - const member = await this.ctx.ntGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString()) + const groupCode = payload.group_id.toString() + const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, payload.user_id.toString()) if (member) { if (isNullable(member.sex)) { - //log('获取群成员详细信息') const info = await this.ctx.ntUserApi.getUserDetailInfo(member.uid) - //log('群成员详细信息结果', info) Object.assign(member, info) } - const ret = OB11Entities.groupMember(payload.group_id.toString(), member) - const self = await this.ctx.ntGroupApi.getGroupMember(payload.group_id.toString(), selfInfo.uid) - if (self?.role === 3 || self?.role === 4) { - const webGroupMembers = await this.ctx.ntWebApi.getGroupMembers(payload.group_id.toString()) - const target = webGroupMembers.find(e => e?.uin && e.uin === ret.user_id) - if (target) { - ret.join_time = target.join_time - ret.last_sent_time = target.last_speak_time - ret.qage = target.qage - ret.level = target.lv.level.toString() - } - } + const ret = OB11Entities.groupMember(groupCode, member) const date = Math.round(Date.now() / 1000) - ret.last_sent_time ||= Number(member.lastSpeakTime || date) - ret.join_time ||= Number(member.joinTime || date) + ret.last_sent_time ??= date + ret.join_time ??= date return ret - } else { - throw `群成员${payload.user_id}不存在` } + throw new Error(`群成员${payload.user_id}不存在`) } } diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index a6d5efc..11f2666 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -1,16 +1,18 @@ import { OB11GroupMember } from '../../types' import { OB11Entities } from '../../entities' -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { selfInfo } from '@/common/globalVars' interface Payload { group_id: number | string - no_cache: boolean | string + no_cache?: boolean | string } class GetGroupMemberList extends BaseAction { actionName = ActionName.GetGroupMemberList + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required() + }) protected async _handle(payload: Payload) { const groupCode = payload.group_id.toString() @@ -20,43 +22,14 @@ class GetGroupMemberList extends BaseAction { groupMembers = await this.ctx.ntGroupApi.getGroupMembers(groupCode) } const groupMembersArr = Array.from(groupMembers.values()) - - const _groupMembers = groupMembersArr.map(item => { - return OB11Entities.groupMember(groupCode, item) - }) - - const MemberMap: Map = new Map() const date = Math.round(Date.now() / 1000) - for (let i = 0, len = _groupMembers.length; i < len; i++) { - // 保证基础数据有这个 同时避免群管插件过于依赖这个杀了 - _groupMembers[i].join_time ||= date - _groupMembers[i].last_sent_time ||= date - MemberMap.set(_groupMembers[i].user_id, _groupMembers[i]) - } - - const selfRole = groupMembers.get(selfInfo.uid)?.role - const isPrivilege = selfRole === 3 || selfRole === 4 - - if (isPrivilege) { - const webGroupMembers = await this.ctx.ntWebApi.getGroupMembers(groupCode) - for (let i = 0, len = webGroupMembers.length; i < len; i++) { - if (!webGroupMembers[i]?.uin) { - continue - } - const MemberData = MemberMap.get(webGroupMembers[i]?.uin) - if (MemberData) { - if (MemberData.join_time === date) { - MemberData.join_time = webGroupMembers[i]?.join_time - MemberData.last_sent_time = webGroupMembers[i]?.last_speak_time - } - MemberData.qage = webGroupMembers[i]?.qage - MemberMap.set(webGroupMembers[i]?.uin, MemberData) - } - } - } - - return Array.from(MemberMap.values()) + return groupMembersArr.map(item => { + const member = OB11Entities.groupMember(groupCode, item) + member.join_time ??= date + member.last_sent_time ??= date + return member + }) } } diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 0c85a33..082ae58 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -1,7 +1,7 @@ import type Adapter from '../adapter' import GetMsg from './msg/GetMsg' import GetLoginInfo from './system/GetLoginInfo' -import { GetFriendList, GetFriendWithCategory } from './user/GetFriendList' +import { GetFriendList } from './user/GetFriendList' import GetGroupList from './group/GetGroupList' import GetGroupInfo from './group/GetGroupInfo' import GetGroupMemberList from './group/GetGroupMemberList' @@ -37,7 +37,6 @@ import GetImage from './file/GetImage' import GetRecord from './file/GetRecord' import { MarkMsgAsRead } from './go-cqhttp/MarkMsgAsRead' import CleanCache from './system/CleanCache' -import { UploadGroupFile, UploadPrivateFile } from './go-cqhttp/UploadFile' import { GetConfigAction, SetConfigAction } from './llonebot/Config' import GetGroupAddRequest from './llonebot/GetGroupAddRequest' import SetQQAvatar from './llonebot/SetQQAvatar' @@ -48,11 +47,11 @@ import { GetForwardMsg } from './go-cqhttp/GetForwardMsg' import { GetCookies } from './user/GetCookie' import { SetMsgEmojiLike } from './msg/SetMsgEmojiLike' import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from './msg/ForwardSingleMsg' -import { GetGroupEssence } from './group/GetGroupEssence' +import { GetEssenceMsgList } from './go-cqhttp/GetGroupEssence' import { GetGroupHonorInfo } from './group/GetGroupHonorInfo' import { HandleQuickOperation } from './go-cqhttp/QuickOperation' import { SetEssenceMsg } from './go-cqhttp/SetEssenceMsg' -import { DelEssenceMsg } from './go-cqhttp/DelEssenceMsg' +import { DeleteEssenceMsg } from './go-cqhttp/DelEssenceMsg' import { GetEvent } from './llonebot/GetEvent' import { DelGroupFile } from './go-cqhttp/DelGroupFile' import { GetGroupSystemMsg } from './go-cqhttp/GetGroupSystemMsg' @@ -67,6 +66,9 @@ import { FetchEmojiLike } from './llonebot/FetchEmojiLike' import { FetchCustomFace } from './llonebot/FetchCustomFace' import { GetFriendMsgHistory } from './llonebot/GetFriendMsgHistory' import { GetGroupFilesByFolder } from './go-cqhttp/GetGroupFilesByFolder' +import { GetFriendWithCategory } from './llonebot/GetFriendWithCategory' +import { UploadGroupFile } from './go-cqhttp/UploadGroupFile' +import { UploadPrivateFile } from './go-cqhttp/UploadPrivateFile' export function initActionMap(adapter: Adapter) { const actionHandlers = [ @@ -117,7 +119,7 @@ export function initActionMap(adapter: Adapter) { new ForwardFriendSingleMsg(adapter), new ForwardGroupSingleMsg(adapter), // go-cqhttp - new GetGroupEssence(adapter), + new GetEssenceMsgList(adapter), new GetGroupHonorInfo(adapter), new SendForwardMsg(adapter), new SendGroupForwardMsg(adapter), @@ -132,7 +134,7 @@ export function initActionMap(adapter: Adapter) { new GetForwardMsg(adapter), new HandleQuickOperation(adapter), new SetEssenceMsg(adapter), - new DelEssenceMsg(adapter), + new DeleteEssenceMsg(adapter), new DelGroupFile(adapter), new GetGroupSystemMsg(adapter), new CreateGroupFileFolder(adapter), diff --git a/src/onebot11/action/llonebot/GetFriendMsgHistory.ts b/src/onebot11/action/llonebot/GetFriendMsgHistory.ts index 87605dd..e7c3219 100644 --- a/src/onebot11/action/llonebot/GetFriendMsgHistory.ts +++ b/src/onebot11/action/llonebot/GetFriendMsgHistory.ts @@ -43,9 +43,9 @@ export class GetFriendMsgHistory extends BaseAction { } if (msgList.length === 0) throw new Error('未找到消息') if (payload.reverseOrder) msgList.reverse() - msgList.map(msg => { + for (const msg of msgList) { msg.msgShortId = this.ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId) - }) + } const ob11MsgList = await Promise.all(msgList.map(msg => OB11Entities.message(this.ctx, msg))) return { messages: filterNullable(ob11MsgList) } } diff --git a/src/onebot11/action/llonebot/GetFriendWithCategory.ts b/src/onebot11/action/llonebot/GetFriendWithCategory.ts new file mode 100644 index 0000000..7451d4f --- /dev/null +++ b/src/onebot11/action/llonebot/GetFriendWithCategory.ts @@ -0,0 +1,17 @@ +import { BaseAction } from '../BaseAction' +import { OB11User } from '../../types' +import { OB11Entities } from '../../entities' +import { ActionName } from '../types' +import { getBuildVersion } from '@/common/utils' + +export class GetFriendWithCategory extends BaseAction { + actionName = ActionName.GetFriendsWithCategory + + protected async _handle() { + if (getBuildVersion() >= 26702) { + return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2ExWithCate(true)) + } else { + throw new Error('this ntqq version not support, must be 26702 or later') + } + } +} diff --git a/src/onebot11/action/llonebot/GetGroupAddRequest.ts b/src/onebot11/action/llonebot/GetGroupAddRequest.ts index 147b074..920cd39 100644 --- a/src/onebot11/action/llonebot/GetGroupAddRequest.ts +++ b/src/onebot11/action/llonebot/GetGroupAddRequest.ts @@ -1,5 +1,5 @@ import { BaseAction } from '../BaseAction' -import { GroupNotify, GroupNotifyStatus } from '@/ntqqapi/types' +import { GroupNotifyStatus } from '@/ntqqapi/types' import { ActionName } from '../types' interface OB11GroupRequestNotify { @@ -13,7 +13,7 @@ export default class GetGroupAddRequest extends BaseAction { const data = await this.ctx.ntGroupApi.getGroupIgnoreNotifies() - const notifies: GroupNotify[] = data.notifies.filter((notify) => notify.status === GroupNotifyStatus.KUNHANDLE) + const notifies = data.notifies.filter(notify => notify.status === GroupNotifyStatus.KUNHANDLE) const returnData: OB11GroupRequestNotify[] = [] for (const notify of notifies) { const uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) diff --git a/src/onebot11/action/llonebot/GetProfileLike.ts b/src/onebot11/action/llonebot/GetProfileLike.ts index 5f6a3e7..a80690a 100644 --- a/src/onebot11/action/llonebot/GetProfileLike.ts +++ b/src/onebot11/action/llonebot/GetProfileLike.ts @@ -8,10 +8,10 @@ export class GetProfileLike extends BaseAction { async _handle() { const ret = await this.ctx.ntUserApi.getProfileLike(selfInfo.uid) - const listdata = ret.info.userLikeInfos[0].favoriteInfo.userInfos - for (const item of listdata) { + const data = ret.info.userLikeInfos[0].favoriteInfo.userInfos + for (const item of data) { item.uin = Number(await this.ctx.ntUserApi.getUinByUid(item.uid)) || 0 } - return listdata + return data } } diff --git a/src/onebot11/action/llonebot/SetQQAvatar.ts b/src/onebot11/action/llonebot/SetQQAvatar.ts index b79b391..0f8ed82 100644 --- a/src/onebot11/action/llonebot/SetQQAvatar.ts +++ b/src/onebot11/action/llonebot/SetQQAvatar.ts @@ -1,4 +1,4 @@ -import fs from 'node:fs' +import { unlink } from 'node:fs/promises' import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { checkFileReceived, uri2local } from '../../../common/utils/file' @@ -13,18 +13,17 @@ export default class SetAvatar extends BaseAction { protected async _handle(payload: Payload): Promise { const { path, isLocal, errMsg } = await uri2local(payload.file) if (errMsg) { - throw `头像${payload.file}设置失败,file字段可能格式不正确` + throw new Error(errMsg) } if (path) { await checkFileReceived(path, 5000) // 文件不存在QQ会崩溃,需要提前判断 const ret = await this.ctx.ntUserApi.setQQAvatar(path) if (!isLocal) { - fs.unlink(path, () => { }) + unlink(path) } if (!ret) { throw `头像${payload.file}设置失败,api无返回` } - // log(`头像设置返回:${JSON.stringify(ret)}`) if ((ret.result as number) === 1004022) { throw `头像${payload.file}设置失败,文件可能不是图片格式` } else if (ret.result !== 0) { @@ -32,7 +31,7 @@ export default class SetAvatar extends BaseAction { } } else { if (!isLocal) { - fs.unlink(path, () => { }) + unlink(path) } throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在` } diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index a2fd1e8..540702b 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -1,35 +1,24 @@ -import { BaseAction } from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { OB11User } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' import { getBuildVersion } from '@/common/utils' interface Payload { - no_cache: boolean | string + no_cache: boolean } export class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList + payloadSchema = Schema.object({ + no_cache: Schema.boolean().default(false) + }) protected async _handle(payload: Payload) { - const refresh = payload?.no_cache === true || payload?.no_cache === 'true' + const refresh = payload.no_cache if (getBuildVersion() >= 26702) { return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2(refresh)) } return OB11Entities.friends(await this.ctx.ntFriendApi.getFriends()) } } - -// extend -export class GetFriendWithCategory extends BaseAction { - actionName = ActionName.GetFriendsWithCategory - - protected async _handle() { - if (getBuildVersion() >= 26702) { - //全新逻辑 - return OB11Entities.friendsV2(await this.ctx.ntFriendApi.getBuddyV2ExWithCate(true)) - } else { - throw new Error('this ntqq version not support, must be 26702 or later') - } - } -}