diff --git a/packages/engine-chronocat-event/src/globalVars.ts b/packages/engine-chronocat-event/src/globalVars.ts index e1c43e7..04b9fad 100644 --- a/packages/engine-chronocat-event/src/globalVars.ts +++ b/packages/engine-chronocat-event/src/globalVars.ts @@ -1,4 +1,9 @@ +import type { Group, Profile } from '@chronocat/red' + export const requestMethodMap: Record = {} export const emittedBuddyReqList: string[] = [] export const sendQueue: string[] = [] + +export const groupMap: Record = {} +export const friendMap: Record = {} diff --git a/packages/engine-chronocat-event/src/handler.ts b/packages/engine-chronocat-event/src/handler.ts index 456d30a..1fcbae1 100644 --- a/packages/engine-chronocat-event/src/handler.ts +++ b/packages/engine-chronocat-event/src/handler.ts @@ -4,6 +4,7 @@ import type { OnAddSendMsg, OnBuddyListChange, OnBuddyReqChange, + OnGroupListUpdate, OnMemberInfoChange, OnMemberListChange, OnMsgInfoListUpdate, @@ -19,7 +20,13 @@ import type { import { ChatType, MsgType, SendType } from '@chronocat/red' import type { ChronocatContext } from '@chronocat/shell' import type { IpcManData } from 'ipcman' -import { emittedBuddyReqList, requestMethodMap, sendQueue } from './globalVars' +import { + emittedBuddyReqList, + friendMap, + groupMap, + requestMethodMap, + sendQueue, +} from './globalVars' import { FriendRequestDispatchMessage, MessageCreatedDispatchMessage, @@ -192,6 +199,15 @@ const dispatcher = async ( return } + case 'onGroupListUpdate': + case 'nodeIKernelGroupListener/onGroupListUpdate': { + const { groupList } = payload as OnGroupListUpdate + + for (const group of groupList) groupMap[group.groupCode] = group + + return + } + case 'onBuddyListChange': case 'nodeIKernelBuddyListener/onBuddyListChange': { const { data } = payload as OnBuddyListChange @@ -199,6 +215,9 @@ const dispatcher = async ( for (const category of data) { for (const buddy of category.buddyList) { ctx.chronocat.uix.add(buddy.uid, buddy.uin) + + // buddy.category = category.categoryName + friendMap[buddy.uin] = buddy } } diff --git a/packages/engine-chronocat-event/src/parser/index.ts b/packages/engine-chronocat-event/src/parser/index.ts index a61c4ed..979f5d1 100644 --- a/packages/engine-chronocat-event/src/parser/index.ts +++ b/packages/engine-chronocat-event/src/parser/index.ts @@ -19,6 +19,7 @@ import type h from '@satorijs/element' import { Buffer } from 'node:buffer' import type { O } from 'ts-toolbelt' import { parseMsgTypes } from './msgt' +import { groupMap } from '../globalVars' export const buildParser = ( @@ -111,7 +112,8 @@ export const parseMessage = async ( event.channel.type = 0 // ChannelType.TEXT event.channel.id = event.guild.id = message.peerUid - event.channel.name = event.guild.name = message.peerName + event.channel.name = event.guild.name = + groupMap[message.peerUid]!.groupName // message.peerName event.guild.avatar = `https://p.qlogo.cn/gh/${message.peerUid}/${message.peerUid}/640` break }