This commit is contained in:
idranme
2024-08-30 02:51:56 +08:00
parent 6af31c48c4
commit 64a8efb8df
4 changed files with 35 additions and 51 deletions

View File

@@ -3,7 +3,7 @@ import {
GroupExtParam, GroupExtParam,
GroupMember, GroupMember,
GroupMemberRole, GroupMemberRole,
GroupNotifyTypes, GroupNotifyType,
GroupRequestOperateTypes, GroupRequestOperateTypes,
} from '@/ntqqapi/types' } from '@/ntqqapi/types'
import { GeneralCallResult } from './common' import { GeneralCallResult } from './common'
@@ -181,7 +181,7 @@ export interface NodeIKernelGroupService {
operateType: GroupRequestOperateTypes, // 2 拒绝 operateType: GroupRequestOperateTypes, // 2 拒绝
targetMsg: { targetMsg: {
seq: string, // 通知序列号 seq: string, // 通知序列号
type: GroupNotifyTypes, type: GroupNotifyType,
groupCode: string, groupCode: string,
postscript: string postscript: string
} }

View File

@@ -1,13 +1,19 @@
export enum GroupNotifyTypes { export enum GroupNotifyType {
INVITE_ME = 1, INVITED_BY_MEMBER = 1,
INVITED_JOIN = 4, // 有人接受了邀请入群 REFUSE_INVITED,
JOIN_REQUEST_BY_INVITED = 5, // 有人邀请了别人入群 REFUSED_BY_ADMINI_STRATOR,
JOIN_REQUEST = 7, AGREED_TOJOIN_DIRECT, // 有人接受了邀请入群
ADMIN_SET = 8, INVITED_NEED_ADMINI_STRATOR_PASS, // 有人邀请了别人入群
KICK_MEMBER = 9, AGREED_TO_JOIN_BY_ADMINI_STRATOR,
MEMBER_EXIT = 11, // 主动退出 REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS,
ADMIN_UNSET = 12, // 我被取消管理员 SET_ADMIN,
ADMIN_UNSET_OTHER = 13, // 其他人取消管理员 KICK_MEMBER_NOTIFY_ADMIN,
KICK_MEMBER_NOTIFY_KICKED,
MEMBER_LEAVE_NOTIFY_ADMIN, // 主动退出
CANCEL_ADMIN_NOTIFY_CANCELED, // 我被取消管理员
CANCEL_ADMIN_NOTIFY_ADMIN, // 其他人取消管理员
TRANSFER_GROUP_NOTIFY_OLDOWNER,
TRANSFER_GROUP_NOTIFY_ADMIN
} }
export interface GroupNotifies { export interface GroupNotifies {
@@ -27,7 +33,7 @@ export enum GroupNotifyStatus {
export interface GroupNotify { export interface GroupNotify {
time: number // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify time: number // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
seq: string // 唯一标识符转成数字再除以1000应该就是时间戳 seq: string // 唯一标识符转成数字再除以1000应该就是时间戳
type: GroupNotifyTypes type: GroupNotifyType
status: GroupNotifyStatus status: GroupNotifyStatus
group: { groupCode: string; groupName: string } group: { groupCode: string; groupName: string }
user1: { uid: string; nickName: string } // 被设置管理员的人 user1: { uid: string; nickName: string } // 被设置管理员的人

View File

@@ -2,13 +2,14 @@ import { Service, Context } from 'cordis'
import { OB11Entities } from './entities' import { OB11Entities } from './entities'
import { import {
GroupNotify, GroupNotify,
GroupNotifyTypes, GroupNotifyType,
RawMessage, RawMessage,
BuddyReqType, BuddyReqType,
Peer, Peer,
FriendRequest, FriendRequest,
GroupMember, GroupMember,
GroupMemberRole GroupMemberRole,
GroupNotifyStatus
} from '../ntqqapi/types' } from '../ntqqapi/types'
import { OB11GroupRequestEvent } from './event/request/OB11GroupRequest' import { OB11GroupRequestEvent } from './event/request/OB11GroupRequest'
import { OB11FriendRequestEvent } from './event/request/OB11FriendRequest' import { OB11FriendRequestEvent } from './event/request/OB11FriendRequest'
@@ -108,15 +109,14 @@ class OneBot11Adapter extends Service {
private async handleGroupNotify(notifies: GroupNotify[]) { private async handleGroupNotify(notifies: GroupNotify[]) {
for (const notify of notifies) { for (const notify of notifies) {
try { try {
notify.time = Date.now()
const notifyTime = parseInt(notify.seq) / 1000 const notifyTime = parseInt(notify.seq) / 1000
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
if (notifyTime < this.startTime) { if (notifyTime < this.startTime) {
continue continue
} }
if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) { if ([GroupNotifyType.MEMBER_LEAVE_NOTIFY_ADMIN, GroupNotifyType.KICK_MEMBER_NOTIFY_ADMIN].includes(notify.type)) {
this.ctx.logger.info('有成员退出通知', notify) this.ctx.logger.info('有成员退出通知', notify)
const member1Uin = (await this.ctx.ntUserApi.getUinByUid(notify.user1.uid))! const member1Uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)
let operatorId = member1Uin let operatorId = member1Uin
let subType: GroupDecreaseSubType = 'leave' let subType: GroupDecreaseSubType = 'leave'
if (notify.user2.uid) { if (notify.user2.uid) {
@@ -135,57 +135,35 @@ class OneBot11Adapter extends Service {
) )
this.dispatch(groupDecreaseEvent) this.dispatch(groupDecreaseEvent)
} }
else if ([GroupNotifyTypes.JOIN_REQUEST, GroupNotifyTypes.JOIN_REQUEST_BY_INVITED].includes(notify.type)) { else if ([GroupNotifyType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS].includes(notify.type) && notify.status === GroupNotifyStatus.KUNHANDLE) {
this.ctx.logger.info('有加群请求') this.ctx.logger.info('有加群请求')
let requestQQ = '' let requestUin = (await this.ctx.ntUserApi.getUinByUid(notify.user1.uid))
try { if (isNaN(parseInt(requestUin))) {
// uid-->uin requestUin = (await this.ctx.ntUserApi.getUserDetailInfo(notify.user1.uid)).uin
requestQQ = (await this.ctx.ntUserApi.getUinByUid(notify.user1.uid))
if (isNaN(parseInt(requestQQ))) {
requestQQ = (await this.ctx.ntUserApi.getUserDetailInfo(notify.user1.uid)).uin
}
} catch (e) {
this.ctx.logger.error('获取加群人QQ号失败 Uid:', notify.user1.uid, e)
}
let invitorId: string
if (notify.type == GroupNotifyTypes.JOIN_REQUEST_BY_INVITED) {
// groupRequestEvent.sub_type = 'invite'
try {
// uid-->uin
invitorId = (await this.ctx.ntUserApi.getUinByUid(notify.user2.uid))
if (isNaN(parseInt(invitorId))) {
invitorId = (await this.ctx.ntUserApi.getUserDetailInfo(notify.user2.uid)).uin
}
} catch (e) {
invitorId = ''
this.ctx.logger.error('获取邀请人QQ号失败 Uid:', notify.user2.uid, e)
}
} }
const groupRequestEvent = new OB11GroupRequestEvent( const groupRequestEvent = new OB11GroupRequestEvent(
parseInt(notify.group.groupCode), parseInt(notify.group.groupCode),
parseInt(requestQQ) || 0, parseInt(requestUin) || 0,
flag, flag,
notify.postscript, notify.postscript,
invitorId! === undefined ? undefined : +invitorId,
'add'
) )
this.dispatch(groupRequestEvent) this.dispatch(groupRequestEvent)
} }
else if (notify.type == GroupNotifyTypes.INVITE_ME) { else if (notify.type === GroupNotifyType.INVITED_BY_MEMBER && notify.status === GroupNotifyStatus.KUNHANDLE) {
this.ctx.logger.info('收到邀请我加群通知') this.ctx.logger.info('收到邀请我加群通知')
const userId = (await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)) || '' const userId = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)
const groupInviteEvent = new OB11GroupRequestEvent( const groupInviteEvent = new OB11GroupRequestEvent(
parseInt(notify.group.groupCode), parseInt(notify.group.groupCode),
parseInt(userId), parseInt(userId) || 0,
flag, flag,
undefined, notify.postscript,
undefined, undefined,
'invite' 'invite'
) )
this.dispatch(groupInviteEvent) this.dispatch(groupInviteEvent)
} }
} catch (e: any) { } catch (e: any) {
this.ctx.logger.error('解析群通知失败', e.stack.toString()) this.ctx.logger.error('解析群通知失败', e.stack)
} }
} }
} }

View File

@@ -427,7 +427,7 @@ export namespace OB11Entities {
ctx.logger.info(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement) ctx.logger.info(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement)
ctx.ntGroupApi.quitGroup(msg.peerUid) ctx.ntGroupApi.quitGroup(msg.peerUid)
try { try {
const adminUin = (await ctx.ntGroupApi.getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await ctx.ntUserApi.getUidByUin(groupElement.adminUid)) const adminUin = (await ctx.ntGroupApi.getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await ctx.ntUserApi.getUinByUid(groupElement.adminUid))
if (adminUin) { if (adminUin) {
return new OB11GroupDecreaseEvent( return new OB11GroupDecreaseEvent(
parseInt(msg.peerUid), parseInt(msg.peerUid),