From 63f37d971c761ddf02cb806d68d50ca292dedc26 Mon Sep 17 00:00:00 2001 From: "Wesley F. Young" Date: Wed, 28 Aug 2024 20:39:30 +0800 Subject: [PATCH] feat: emit group/request,invite --- src/core/events.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/core/events.ts b/src/core/events.ts index e91b9b4c..882aecb7 100644 --- a/src/core/events.ts +++ b/src/core/events.ts @@ -5,9 +5,11 @@ import { FriendRequest, GrayTipElement, GroupNotify, + GroupNotifyMsgStatus, GroupNotifyMsgType, RawMessage, - SendStatusType, TipGroupElement, + SendStatusType, + TipGroupElement, } from '@/core/entities'; import { NodeIKernelBuddyListener, NodeIKernelGroupListener, NodeIKernelMsgListener } from '@/core/listeners'; import EventEmitter from 'node:events'; @@ -37,7 +39,11 @@ type NapCatInternalEvents = { 'buddy/input-status': (data: Parameters[0]) => PromiseLike; - 'group/request': (request: GroupNotify) => PromiseLike; + 'group/request': (groupCode: string, requestUin: string, words: string, + xGroupNotify: GroupNotify) => PromiseLike; + + 'group/invite': (groupCode: string, invitorUin: string, + xGroupNotify: GroupNotify) => PromiseLike; 'group/admin': (groupCode: string, targetUin: string, operation: 'set' | 'unset', // If it comes from onGroupNotifiesUpdated @@ -234,6 +240,7 @@ export class NapCatEventChannel extends operatorUin, notify ); + continue; } else { // No operator, indicates that the member leaves this.emit( @@ -242,11 +249,52 @@ export class NapCatEventChannel extends leftMemberUin, notify ); + continue; } } } catch (e) { this.core.context.logger.logError('处理退群消息失败', e); } + + try { + if ( + notify.type === GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS && + notify.status === GroupNotifyMsgStatus.KUNHANDLE + ) { + this.core.context.logger.logDebug('入群请求', notify); + const requesterUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); + this.emit( + 'group/request', + notify.group.groupCode, + requesterUin, + notify.postscript, + notify + ); + continue; + } + } catch (e) { + this.core.context.logger.logError('处理入群请求失败', e); + } + + try { + // Todo: unstable, may need to be in sync with main branch + if ( + notify.type == GroupNotifyMsgType.INVITED_BY_MEMBER && + notify.status == GroupNotifyMsgStatus.KUNHANDLE + ) { + this.core.context.logger.logDebug('入群邀请', notify); + const requesterUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); + this.emit( + 'group/invite', + notify.group.groupCode, + requesterUin, + notify + ); + // continue; + } + } catch (e) { + this.core.context.logger.logError('处理入群邀请失败', e); + } } }; }