From 44448895a070c8c98c4b3ec3e1ac394149acf286 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Sat, 18 May 2024 13:08:44 +0800 Subject: [PATCH 1/2] feat: 209 --- src/common/data.ts | 19 +++++++++++++++---- src/ntqqapi/hook.ts | 18 ++++++++++-------- src/ntqqapi/types/user.ts | 11 ++++++++++- src/onebot11/action/index.ts | 3 ++- src/onebot11/action/types.ts | 1 + src/onebot11/action/user/GetFriendList.ts | 17 ++++++++++++----- 6 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/common/data.ts b/src/common/data.ts index 6a3b0e5..4d8fbb9 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -1,4 +1,12 @@ -import { type Friend, type FriendRequest, type Group, type GroupMember, type SelfInfo } from '../ntqqapi/types' +import { + CategoryFriend, + type Friend, + type FriendRequest, + type Group, + type GroupMember, + type SelfInfo, + User, +} from '../ntqqapi/types' import { type FileCache, type LLOneBotError } from './types' import { NTQQGroupApi } from '../ntqqapi/api/group' import { log } from './utils/log' @@ -14,8 +22,8 @@ export const selfInfo: SelfInfo = { } export const WebGroupData = { GroupData: new Map>(), - GroupTime: new Map() -}; + GroupTime: new Map(), +} export let groups: Group[] = [] export let friends: Friend[] = [] export let friendRequests: Map = new Map() @@ -53,7 +61,8 @@ export async function getGroup(qq: string): Promise { if (group) { groups.push(group) } - } catch (e) {} + } catch (e) { + } } return group } @@ -111,3 +120,5 @@ export function getUidByUin(uin: string) { } export let tempGroupCodeMap: Record = {} // peerUid => 群号 + +export let rawFriends: CategoryFriend[] = [] \ No newline at end of file diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index 168519d..8c1a480 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -1,26 +1,26 @@ import { BrowserWindow } from 'electron' import { NTQQApiClass, NTQQApiMethod } from './ntcall' import { NTQQMsgApi, sendMessagePool } from './api/msg' -import { ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User } from './types' +import { CategoryFriend, ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User } from './types' import { deleteGroup, friends, getFriend, getGroupMember, - groups, + groups, rawFriends, selfInfo, tempGroupCodeMap, uidMaps, -} from '../common/data' +} from '@/common/data' import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent' import { v4 as uuidv4 } from 'uuid' import { postOb11Event } from '../onebot11/server/post-ob11-event' -import { getConfigUtil, HOOK_LOG } from '../common/config' +import { getConfigUtil, HOOK_LOG } from '@/common/config' import fs from 'fs' -import { dbUtil } from '../common/db' +import { dbUtil } from '@/common/db' import { NTQQGroupApi } from './api/group' -import { log } from '../common/utils/log' -import { isNumeric, sleep } from '../common/utils/helper' +import { log } from '@/common/utils' +import { isNumeric, sleep } from '@/common/utils' import { OB11Constructor } from '../onebot11/constructor' export let hookApiCallbacks: Record void> = {} @@ -380,8 +380,10 @@ registerReceiveHook<{ // 好友列表变动 registerReceiveHook<{ - data: { categoryId: number; categroyName: string; categroyMbCount: number; buddyList: User[] }[] + data:CategoryFriend[] }>(ReceiveCmdS.FRIENDS, (payload) => { + rawFriends.length = 0; + rawFriends.push(...payload.data); for (const fData of payload.data) { const _friends = fData.buddyList for (let friend of _friends) { diff --git a/src/ntqqapi/types/user.ts b/src/ntqqapi/types/user.ts index ef07164..5fbe4b8 100644 --- a/src/ntqqapi/types/user.ts +++ b/src/ntqqapi/types/user.ts @@ -10,6 +10,7 @@ export interface QQLevel { moonNum: number starNum: number } + export interface User { uid: string // 加密的字符串 uin: string // QQ号 @@ -72,4 +73,12 @@ export interface SelfInfo extends User { online?: boolean } -export interface Friend extends User {} +export interface Friend extends User { +} + +export interface CategoryFriend { + categoryId: number; + categroyName: string; + categroyMbCount: number; + buddyList: User[] +} \ No newline at end of file diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 9f140a1..e2e09c3 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -1,6 +1,6 @@ import GetMsg from './msg/GetMsg' import GetLoginInfo from './system/GetLoginInfo' -import GetFriendList from './user/GetFriendList' +import { GetFriendList, GetFriendWithCategory} from './user/GetFriendList' import GetGroupList from './group/GetGroupList' import GetGroupInfo from './group/GetGroupInfo' import GetGroupMemberList from './group/GetGroupMemberList' @@ -58,6 +58,7 @@ export const actionHandlers = [ new SetConfigAction(), new GetGroupAddRequest(), new SetQQAvatar(), + new GetFriendWithCategory(), // onebot11 new SendLike(), new GetMsg(), diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 1f8c57f..1b61ecc 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -21,6 +21,7 @@ export enum ActionName { SetConfig = 'set_config', Debug = 'llonebot_debug', GetFile = 'get_file', + GetFriendsWithCategory = 'get_friends_with_category', // onebot 11 SendLike = 'send_like', GetLoginInfo = 'get_login_info', diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index 4408ff3..deab4b9 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -1,16 +1,16 @@ import { OB11User } from '../../types' import { OB11Constructor } from '../../constructor' -import { friends } from '../../../common/data' +import { friends, rawFriends } from '@/common/data' import BaseAction from '../BaseAction' import { ActionName } from '../types' -import { NTQQFriendApi } from '../../../ntqqapi/api' -import { log } from '../../../common/utils' +import { NTQQFriendApi } from '@/ntqqapi/api' +import { CategoryFriend } from '@/ntqqapi/types' interface Payload { no_cache: boolean | string } -class GetFriendList extends BaseAction { +export class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList protected async _handle(payload: Payload) { @@ -26,4 +26,11 @@ class GetFriendList extends BaseAction { } } -export default GetFriendList + +export class GetFriendWithCategory extends BaseAction> { + actionName = ActionName.GetFriendsWithCategory; + + protected async _handle(payload: void) { + return rawFriends; + } +} \ No newline at end of file From 6413b0ff8291b4d4a973f28086ca9d90f2c40163 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Sat, 18 May 2024 16:34:12 +0800 Subject: [PATCH 2/2] fix: Send msg timeout minimum --- src/onebot11/action/msg/SendMsg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index 1bda604..841b07e 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -327,7 +327,7 @@ export async function sendMsg( } } log('发送消息总大小', totalSize, 'bytes') - let timeout = ((totalSize / 1024 / 512) * 1000) || 5000 // 512kb/s + let timeout = ((totalSize / 1024 / 512) * 1000) + 5000 // 512kb/s log('设置消息超时时间', timeout) const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout) log('消息发送结果', returnMsg)