From d4f322dd4dc60508244fa87bbd4d22362ef906ea Mon Sep 17 00:00:00 2001 From: Il Harper Date: Fri, 23 Aug 2024 12:06:40 +0800 Subject: [PATCH] feat(event): implement `guild-request` event --- .../src/definitions/groupService.ts | 11 +++ .../engine-chronocat-event/src/globalVars.ts | 1 + .../engine-chronocat-event/src/handler.ts | 29 ++++++- .../engine-chronocat-event/src/messages.ts | 42 +++++++++- packages/red/src/redIpcEntity.ts | 77 +++++++++++++++++++ 5 files changed, 157 insertions(+), 3 deletions(-) diff --git a/packages/engine-chronocat-api/src/definitions/groupService.ts b/packages/engine-chronocat-api/src/definitions/groupService.ts index e5b7005..30be4fc 100644 --- a/packages/engine-chronocat-api/src/definitions/groupService.ts +++ b/packages/engine-chronocat-api/src/definitions/groupService.ts @@ -139,6 +139,17 @@ export const quitGroup = define< ] >('ns-ntApi-2', 'nodeIKernelGroupService/quitGroup') +export const getSingleScreenNotifies = define< + unknown, + [ + { + doubt: boolean + startSeq: string // '1716209619000000' + number: number // 16 + }, + ] +>('ns-ntApi-2', 'nodeIKernelGroupService/getSingleScreenNotifies') + export const operateSysNotify = define< unknown, [ diff --git a/packages/engine-chronocat-event/src/globalVars.ts b/packages/engine-chronocat-event/src/globalVars.ts index 04b9fad..ecd9239 100644 --- a/packages/engine-chronocat-event/src/globalVars.ts +++ b/packages/engine-chronocat-event/src/globalVars.ts @@ -2,6 +2,7 @@ import type { Group, Profile } from '@chronocat/red' export const requestMethodMap: Record = {} export const emittedBuddyReqList: string[] = [] +export const emittedGroupReqList: string[] = [] export const sendQueue: string[] = [] diff --git a/packages/engine-chronocat-event/src/handler.ts b/packages/engine-chronocat-event/src/handler.ts index 1fcbae1..e64d237 100644 --- a/packages/engine-chronocat-event/src/handler.ts +++ b/packages/engine-chronocat-event/src/handler.ts @@ -5,6 +5,7 @@ import type { OnBuddyListChange, OnBuddyReqChange, OnGroupListUpdate, + OnGroupSingleScreenNotifies, OnMemberInfoChange, OnMemberListChange, OnMsgInfoListUpdate, @@ -22,6 +23,7 @@ import type { ChronocatContext } from '@chronocat/shell' import type { IpcManData } from 'ipcman' import { emittedBuddyReqList, + emittedGroupReqList, friendMap, groupMap, requestMethodMap, @@ -29,6 +31,7 @@ import { } from './globalVars' import { FriendRequestDispatchMessage, + GuildRequestDispatchMessage, MessageCreatedDispatchMessage, MessageDeletedDispatchMessage, } from './messages' @@ -208,6 +211,30 @@ const dispatcher = async ( return } + case 'nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated': { + // const {} = payload as OnGroupNotifiesUnreadCountUpdated + + return + } + + case 'nodeIKernelGroupListener/onGroupSingleScreenNotifies': { + const { notifies } = payload as OnGroupSingleScreenNotifies + + for (const notify of notifies) { + const uin = ctx.chronocat.uix.getUin(notify.user1.uid) + if (!uin) return + + const key = `${notify.group.groupCode}:${uin}:${notify.seq}` + if (emittedGroupReqList.includes(key)) return + + emittedGroupReqList.push(key) + + ctx.chronocat.emit(new GuildRequestDispatchMessage(notify, uin)) + } + + return + } + case 'onBuddyListChange': case 'nodeIKernelBuddyListener/onBuddyListChange': { const { data } = payload as OnBuddyListChange @@ -225,8 +252,6 @@ const dispatcher = async ( } case 'nodeIKernelBuddyListener/onBuddyReqChange': { - if (channel !== 'IPC_DOWN_2') return - const { buddyReqs } = payload as OnBuddyReqChange buddyReqs.forEach((x) => { diff --git a/packages/engine-chronocat-event/src/messages.ts b/packages/engine-chronocat-event/src/messages.ts index 10cf58d..d5a7a27 100644 --- a/packages/engine-chronocat-event/src/messages.ts +++ b/packages/engine-chronocat-event/src/messages.ts @@ -1,4 +1,4 @@ -import type { BuddyReq, RedMessage } from '@chronocat/red' +import type { BuddyReq, GroupNotify, RedMessage } from '@chronocat/red' import type { ChronocatContext, ChronocatLogCurrentConfig, @@ -38,6 +38,46 @@ export class MessageDeletedDispatchMessage implements SatoriDispatchMessage { .map((e) => ((e.type = 'message-deleted'), e)) } +export class GuildRequestDispatchMessage implements SatoriDispatchMessage { + constructor( + private notify: GroupNotify, + private uin: string, + ) {} + + type = 'satori' as const + + toSatori = async ( + ctx: ChronocatContext, + _config: O.Intersect< + ChronocatLogCurrentConfig, + ChronocatSatoriEventsConfig + >, + ) => { + const event: Event = { + id: undefined as unknown as number, + type: 'guild-request', + + platform: ctx.chronocat.platform, + self_id: undefined as unknown as string, + timestamp: new Date().getTime(), + + guild: { + id: this.notify.group.groupCode, + name: this.notify.group.groupName, + avatar: `https://p.qlogo.cn/gh/${this.notify.group.groupCode}/${this.notify.group.groupCode}/640`, + }, + + user: { + id: `${this.uin}`, + name: this.notify.user1.nickName, + avatar: `http://thirdqq.qlogo.cn/headimg_dl?dst_uin=${this.uin}&spec=640`, + }, + } + + return [event] + } +} + export class FriendRequestDispatchMessage implements SatoriDispatchMessage { constructor( private buddyReq: BuddyReq, diff --git a/packages/red/src/redIpcEntity.ts b/packages/red/src/redIpcEntity.ts index f077086..88fb8dd 100644 --- a/packages/red/src/redIpcEntity.ts +++ b/packages/red/src/redIpcEntity.ts @@ -180,3 +180,80 @@ export interface MsgsIncludeSelf { export interface OnOpenParamChange { data: Contact[] } + +export interface OnGroupNotifiesUnreadCountUpdated { + /** + * 是否有过滤消息 + */ + doubt: boolean + + /** + * 最旧未读消息 ID + */ + oldestUnreadSeq: string // '1716209619000000' + + /** + * + * 未读消息数 + */ + unreadCount: number +} + +export interface OnGroupSingleScreenNotifies { + /** + * 是否是过滤消息列表 + */ + doubt: false + + /** + * 分页 ID + */ + nextStartSeq: '0' + + notifies: GroupNotify[] +} + +export interface GroupNotify { + seq: string // '1716209619000000' + + type: number // 7 + + status: number // 1 + + group: { + groupCode: string + groupName: string + } + + user1: { + uid: string + nickName: string + } + + user2: { + uid: string + nickName: string + } + + actionUser: { + uid: string + nickName: string + } + + actionTime: string // '0' + + invitationExt: { + srcType: number // 0 + groupCode: string // '0' + waitStatus: number // 0 + } + + /** + * 验证消息 + */ + postscript: string + + repeatSeqs: [] + + warningTips: string // '该账号存在风险,请谨慎操作' +}