From 18b7df9fca07a4d4d59c7a761cfd27c9efd07f49 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Wed, 1 May 2024 18:46:13 +0800 Subject: [PATCH] feat: get_group_list, get_friend_list no_cache --- src/onebot11/action/group/GetGroupList.ts | 4 ++-- src/onebot11/action/user/GetFriendList.ts | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/onebot11/action/group/GetGroupList.ts b/src/onebot11/action/group/GetGroupList.ts index 676eb5eb..6d6bdc92 100644 --- a/src/onebot11/action/group/GetGroupList.ts +++ b/src/onebot11/action/group/GetGroupList.ts @@ -8,7 +8,7 @@ import { Group } from '@/core/entities'; import { log } from '@/common/utils/log'; interface Payload { - no_cache: boolean; + no_cache: boolean | string; } class GetGroupList extends BaseAction { @@ -16,7 +16,7 @@ class GetGroupList extends BaseAction { protected async _handle(payload: Payload) { let groupList: Group[] = Array.from(groups.values()); - if (groupList.length === 0 || payload?.no_cache === true) { + if (groupList.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { groupList = await NTQQGroupApi.getGroups(true); // log('get groups', groups); } diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index a7474f0f..5f406dd1 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -3,14 +3,27 @@ import { OB11Constructor } from '../../constructor'; import { friends } from '@/core/data'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; +import { NTQQFriendApi } from '@/core'; -class GetFriendList extends BaseAction { +interface Payload{ + no_cache: boolean | string +} + +export default class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList; - protected async _handle(payload: null) { + protected async _handle(payload: Payload) { + if (friends.size === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { + const _friends = await NTQQFriendApi.getFriends(true); + // log('强制刷新好友列表,结果: ', _friends) + if (_friends.length > 0) { + friends.clear(); + for (const friend of _friends) { + friends.set(friend.uid, friend); + } + } + } return OB11Constructor.friends(Array.from(friends.values())); } } - -export default GetFriendList;