From aee4f349c6a27f4a13d323d9a78e6ab7c1e73bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 15 Aug 2024 00:06:41 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=B8=A2=E5=BC=83=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/action/group/GetGroupMemberInfo.ts | 55 +++++++------------ src/onebot/action/group/SetGroupAdmin.ts | 5 +- src/onebot/action/group/SetGroupLeave.ts | 2 +- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/onebot/action/group/GetGroupMemberInfo.ts b/src/onebot/action/group/GetGroupMemberInfo.ts index b38d8daa..34feac51 100644 --- a/src/onebot/action/group/GetGroupMemberInfo.ts +++ b/src/onebot/action/group/GetGroupMemberInfo.ts @@ -26,13 +26,9 @@ class GetGroupMemberInfo extends BaseAction { const NTQQWebApi = this.CoreContext.apis.WebApi; const isNocache = payload.no_cache == true || payload.no_cache === 'true'; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); - if (!uid) { - throw (`Uin2Uid Error ${payload.user_id}不存在`); - } + if (!uid) throw (`Uin2Uid Error ${payload.user_id}不存在`); const member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache); - if (!member) { - throw (`群(${payload.group_id})成员${payload.user_id}不存在`); - } + if (!member) throw (`群(${payload.group_id})成员${payload.user_id}不存在`); try { const info = (await NTQQUserApi.getUserDetailInfo(member.uid)); this.CoreContext.context.logger.logDebug('群成员详细信息结果', info); @@ -42,37 +38,24 @@ class GetGroupMemberInfo extends BaseAction { } const date = Math.round(Date.now() / 1000); const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member); - if (!this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) { - const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache); - let isPrivilege = false; - if (SelfInfoInGroup) { - isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4; - } - if (isPrivilege) { - const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString()); - for (let i = 0, len = webGroupMembers.length; i < len; i++) { - if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) { - retMember.join_time = webGroupMembers[i]?.join_time; - retMember.last_sent_time = webGroupMembers[i]?.last_speak_time; - retMember.qage = webGroupMembers[i]?.qage; - retMember.level = webGroupMembers[i]?.lv.level.toString(); - } - } - } else { - const LastestMsgList = await NTQQGroupApi.getLatestMsg(payload.group_id.toString(), [payload.user_id.toString()]); - if (LastestMsgList?.msgList?.length && LastestMsgList?.msgList?.length > 0) { - const last_send_time = LastestMsgList.msgList[0].msgTime; - if (last_send_time && last_send_time != '0' && last_send_time != '') { - retMember.last_sent_time = parseInt(last_send_time); - retMember.join_time = Math.round(Date.now() / 1000);//兜底数据 防止群管乱杀 - } - } - } - } else { - // Mlikiowa V2.0.20 Refactor Todo - // retMember.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString()); - // retMember.join_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString()); + const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache); + let isPrivilege = false; + if (SelfInfoInGroup) { + isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4; } + if (isPrivilege) { + const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString()); + for (let i = 0, len = webGroupMembers.length; i < len; i++) { + if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) { + retMember.join_time = webGroupMembers[i]?.join_time; + retMember.last_sent_time = webGroupMembers[i]?.last_speak_time; + retMember.qage = webGroupMembers[i]?.qage; + retMember.level = webGroupMembers[i]?.lv.level.toString(); + } + } + } + retMember.last_sent_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString()); + retMember.join_time = parseInt((await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString()); return retMember; } } diff --git a/src/onebot/action/group/SetGroupAdmin.ts b/src/onebot/action/group/SetGroupAdmin.ts index 8a33ad57..cb031028 100644 --- a/src/onebot/action/group/SetGroupAdmin.ts +++ b/src/onebot/action/group/SetGroupAdmin.ts @@ -8,7 +8,7 @@ const SchemaData = { properties: { group_id: { type: ['number', 'string'] }, user_id: { type: ['number', 'string'] }, - enable: { type: 'boolean' }, + enable: { type: ['boolean', 'string'] }, }, required: ['group_id', 'user_id'], } as const satisfies JSONSchema; @@ -20,11 +20,12 @@ export default class SetGroupAdmin extends BaseAction { PayloadSchema = SchemaData; async _handle(payload: Payload): Promise { + const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : payload.enable; const NTQQGroupApi = this.CoreContext.apis.GroupApi; const NTQQUserApi = this.CoreContext.apis.UserApi; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error('get Uid Error'); - await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal); + await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal); return null; } } diff --git a/src/onebot/action/group/SetGroupLeave.ts b/src/onebot/action/group/SetGroupLeave.ts index 43b3fe2c..4d3b1153 100644 --- a/src/onebot/action/group/SetGroupLeave.ts +++ b/src/onebot/action/group/SetGroupLeave.ts @@ -6,7 +6,7 @@ const SchemaData = { type: 'object', properties: { group_id: { type: ['number', 'string'] }, - is_dismiss: { type: 'boolean' }, + is_dismiss: { type: ['boolean', 'string'] }, }, required: ['group_id'], } as const satisfies JSONSchema;