mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-07 11:39:01 +08:00
Refactor: 更新群组通知处理逻辑,优化数据结构和异步处理
This commit is contained in:
parent
2e5dd6535a
commit
22d3ac33a2
@ -2,32 +2,44 @@ import { GroupNotifyMsgStatus } from '@/core';
|
|||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
|
||||||
interface OB11GroupRequestNotify {
|
interface Notify {
|
||||||
group_id: number,
|
request_id: string;
|
||||||
user_id: number,
|
invitor_uin: number;
|
||||||
flag: string
|
invitor_nick?: string;
|
||||||
|
group_id?: number;
|
||||||
|
group_name?: string;
|
||||||
|
checked: boolean;
|
||||||
|
requester_nick?: string;
|
||||||
|
actor: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GetGroupAddRequest extends OneBotAction<null, OB11GroupRequestNotify[] | null> {
|
export default class GetGroupAddRequest extends OneBotAction<null, Notify[] | null> {
|
||||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||||
|
|
||||||
async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
|
async _handle(payload: null): Promise<Notify[] | null> {
|
||||||
const ignoredNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(true, 10);
|
const NTQQUserApi = this.core.apis.UserApi;
|
||||||
const retData: any = {
|
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||||
join_requests: await Promise.all(
|
const ignoredNotifies = await NTQQGroupApi.getSingleScreenNotifies(true, 10);
|
||||||
ignoredNotifies
|
const retData: Notify[] = [];
|
||||||
.filter(notify => notify.type === 7)
|
|
||||||
.map(async SSNotify => ({
|
const notifyPromises = ignoredNotifies
|
||||||
request_id: SSNotify.group.groupCode + '|' + SSNotify.seq + '|' + SSNotify.type,
|
.filter(notify => notify.type === 7)
|
||||||
requester_uin: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user1?.uid),
|
.map(async SSNotify => {
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
||||||
group_id: SSNotify.group?.groupCode,
|
const actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
group_name: SSNotify.group?.groupName,
|
retData.push({
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
||||||
actor: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
invitor_uin: invitorUin,
|
||||||
}))),
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
};
|
group_id: +SSNotify.group?.groupCode,
|
||||||
|
group_name: SSNotify.group?.groupName,
|
||||||
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
|
actor: actorUin,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(notifyPromises);
|
||||||
|
|
||||||
return retData;
|
return retData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,26 +1,55 @@
|
|||||||
import { GroupNotifyMsgStatus } from '@/core';
|
import { GroupNotifyMsgStatus } from '@/core';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
export class GetGroupIgnoredNotifies extends OneBotAction<void, any> {
|
|
||||||
actionName = ActionName.GetGroupIgnoredNotifies;
|
|
||||||
|
|
||||||
async _handle(payload: void) {
|
interface Notify {
|
||||||
const ignoredNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(true, 10);
|
request_id: string;
|
||||||
const retData: any = {
|
invitor_uin: number;
|
||||||
join_requests: await Promise.all(
|
invitor_nick?: string;
|
||||||
ignoredNotifies
|
group_id?: number;
|
||||||
.filter(notify => notify.type === 7)
|
group_name?: string;
|
||||||
.map(async SSNotify => ({
|
checked: boolean;
|
||||||
request_id: SSNotify.group.groupCode + '|' + SSNotify.seq + '|' + SSNotify.type,
|
requester_nick?: string;
|
||||||
requester_uin: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user1?.uid),
|
actor: number;
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
}
|
||||||
group_id: SSNotify.group?.groupCode,
|
interface RetData {
|
||||||
group_name: SSNotify.group?.groupName,
|
InvitedRequest: Notify[];
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
join_requests: Notify[];
|
||||||
actor: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
}
|
||||||
}))),
|
|
||||||
};
|
export class GetGroupIgnoredNotifies extends OneBotAction<void, RetData> {
|
||||||
|
actionName = ActionName.GetGroupSystemMsg;
|
||||||
|
|
||||||
|
async _handle(): Promise<RetData> {
|
||||||
|
const NTQQUserApi = this.core.apis.UserApi;
|
||||||
|
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||||
|
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(false, 50);
|
||||||
|
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
||||||
|
|
||||||
|
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
||||||
|
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
||||||
|
const actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
|
|
||||||
|
const commonData = {
|
||||||
|
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
||||||
|
invitor_uin: invitorUin,
|
||||||
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
|
group_id: +SSNotify.group?.groupCode,
|
||||||
|
group_name: SSNotify.group?.groupName,
|
||||||
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
|
actor: actorUin,
|
||||||
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (SSNotify.type === 1) {
|
||||||
|
retData.InvitedRequest.push(commonData);
|
||||||
|
} else if (SSNotify.type === 7) {
|
||||||
|
retData.join_requests.push(commonData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(notifyPromises);
|
||||||
|
|
||||||
return retData;
|
return retData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,38 +1,63 @@
|
|||||||
import { GroupNotifyMsgStatus } from '@/core';
|
import { GroupNotifyMsgStatus } from '@/core';
|
||||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
export class GetGroupSystemMsg extends OneBotAction<void, any> {
|
|
||||||
|
interface Notify {
|
||||||
|
request_id: string;
|
||||||
|
invitor_uin: number;
|
||||||
|
invitor_nick?: string;
|
||||||
|
group_id?: number;
|
||||||
|
group_name?: string;
|
||||||
|
checked: boolean;
|
||||||
|
actor: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JoinRequest extends Notify {
|
||||||
|
requester_nick?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RetData {
|
||||||
|
InvitedRequest: Notify[];
|
||||||
|
join_requests: JoinRequest[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
||||||
actionName = ActionName.GetGroupSystemMsg;
|
actionName = ActionName.GetGroupSystemMsg;
|
||||||
|
|
||||||
async _handle() {
|
async _handle(): Promise<RetData> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const NTQQUserApi = this.core.apis.UserApi;
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||||
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
|
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(false, 50);
|
||||||
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(false, 10);
|
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
||||||
const retData: any = { InvitedRequest: [], join_requests: [] };
|
|
||||||
for (const SSNotify of SingleScreenNotifies) {
|
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
||||||
if (SSNotify.type == 1) {
|
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
||||||
|
const actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
|
|
||||||
|
if (SSNotify.type === 1) {
|
||||||
retData.InvitedRequest.push({
|
retData.InvitedRequest.push({
|
||||||
request_id: SSNotify.group.groupCode + '|' + SSNotify.seq + '|' + SSNotify.type,
|
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
||||||
invitor_uin: await NTQQUserApi.getUinByUidV2(SSNotify.user1?.uid),
|
invitor_uin: invitorUin,
|
||||||
invitor_nick: SSNotify.user1?.nickName,
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
group_id: SSNotify.group?.groupCode,
|
group_id: +SSNotify.group?.groupCode,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status === GroupNotifyMsgStatus.KUNHANDLE ? false : true,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
actor: actorUin,
|
||||||
});
|
});
|
||||||
} else if (SSNotify.type == 7) {
|
} else if (SSNotify.type === 7) {
|
||||||
retData.join_requests.push({
|
retData.join_requests.push({
|
||||||
request_id: SSNotify.group.groupCode + '|' + SSNotify.seq + '|' + SSNotify.type,
|
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
||||||
requester_uin: await NTQQUserApi.getUinByUidV2(SSNotify.user1?.uid),
|
invitor_uin: invitorUin,
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
group_id: SSNotify.group?.groupCode,
|
group_id: +SSNotify.group?.groupCode,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status === GroupNotifyMsgStatus.KUNHANDLE ? false : true,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
actor: actorUin,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
await Promise.all(notifyPromises);
|
||||||
|
|
||||||
return retData;
|
return retData;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user