mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: flag handle&onebot标准化
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { FriendV2 } from '@/core/types';
|
import { FriendRequest, FriendV2 } from '@/core/types';
|
||||||
import { BuddyListReqType, InstanceContext, NapCatCore } from '@/core';
|
import { BuddyListReqType, InstanceContext, NapCatCore } from '@/core';
|
||||||
import { LimitedHashTable } from '@/common/message-unique';
|
import { LimitedHashTable } from '@/common/message-unique';
|
||||||
|
|
||||||
@@ -79,16 +79,10 @@ export class NTQQFriendApi {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleFriendRequest(flag: string, accept: boolean) {
|
async handleFriendRequest(notify: FriendRequest, accept: boolean) {
|
||||||
const data = flag.split('|');
|
|
||||||
if (data.length < 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const friendUid = data[0];
|
|
||||||
const reqTime = data[1];
|
|
||||||
this.context.session.getBuddyService()?.approvalFriendRequest({
|
this.context.session.getBuddyService()?.approvalFriendRequest({
|
||||||
friendUid: friendUid,
|
friendUid: notify.friendUid,
|
||||||
reqTime: reqTime,
|
reqTime: notify.reqTime,
|
||||||
accept,
|
accept,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
KickMemberV2Req,
|
KickMemberV2Req,
|
||||||
MemberExtSourceType,
|
MemberExtSourceType,
|
||||||
NapCatCore,
|
NapCatCore,
|
||||||
|
GroupNotify,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { isNumeric, solveAsyncProblem } from '@/common/helper';
|
import { isNumeric, solveAsyncProblem } from '@/common/helper';
|
||||||
import { LimitedHashTable } from '@/common/message-unique';
|
import { LimitedHashTable } from '@/common/message-unique';
|
||||||
@@ -288,20 +289,15 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getGroupService().uploadGroupBulletinPic(groupCode, _Pskey, imageurl);
|
return this.context.session.getGroupService().uploadGroupBulletinPic(groupCode, _Pskey, imageurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleGroupRequest(flag: string, operateType: NTGroupRequestOperateTypes, reason?: string) {
|
async handleGroupRequest(notify: GroupNotify, operateType: NTGroupRequestOperateTypes, reason?: string) {
|
||||||
const flagitem = flag.split('|');
|
|
||||||
const groupCode = flagitem[0];
|
|
||||||
const seq = flagitem[1];
|
|
||||||
const type = parseInt(flagitem[2]);
|
|
||||||
|
|
||||||
return this.context.session.getGroupService().operateSysNotify(
|
return this.context.session.getGroupService().operateSysNotify(
|
||||||
false,
|
false,
|
||||||
{
|
{
|
||||||
operateType: operateType,
|
operateType: operateType,
|
||||||
targetMsg: {
|
targetMsg: {
|
||||||
seq: seq, // 通知序列号
|
seq: notify.seq, // 通知序列号
|
||||||
type: type,
|
type: notify.type,
|
||||||
groupCode: groupCode,
|
groupCode: notify.group.groupCode,
|
||||||
postscript: reason ?? ' ', // 仅传空值可能导致处理失败,故默认给个空格
|
postscript: reason ?? ' ', // 仅传空值可能导致处理失败,故默认给个空格
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -1,17 +1,7 @@
|
|||||||
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';
|
||||||
|
import { Notify } from '@/onebot/types';
|
||||||
interface Notify {
|
|
||||||
request_id: string;
|
|
||||||
invitor_uin: number;
|
|
||||||
invitor_nick?: string;
|
|
||||||
group_id?: number;
|
|
||||||
group_name?: string;
|
|
||||||
checked: boolean;
|
|
||||||
requester_nick?: string;
|
|
||||||
actor: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class GetGroupAddRequest extends OneBotAction<null, Notify[] | null> {
|
export default class GetGroupAddRequest extends OneBotAction<null, Notify[] | null> {
|
||||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||||
@@ -28,13 +18,15 @@ export default class GetGroupAddRequest extends OneBotAction<null, Notify[] | nu
|
|||||||
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
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 actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
retData.push({
|
retData.push({
|
||||||
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
request_id: +SSNotify.seq,
|
||||||
invitor_uin: invitorUin,
|
invitor_uin: invitorUin,
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
group_id: +SSNotify.group?.groupCode,
|
group_id: +SSNotify.group?.groupCode,
|
||||||
|
message: SSNotify?.postscript,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: actorUin,
|
actor: actorUin,
|
||||||
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,40 +1,29 @@
|
|||||||
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';
|
||||||
|
import { Notify } from '@/onebot/types';
|
||||||
|
|
||||||
interface Notify {
|
|
||||||
request_id: string;
|
|
||||||
invitor_uin: number;
|
|
||||||
invitor_nick?: string;
|
|
||||||
group_id?: number;
|
|
||||||
group_name?: string;
|
|
||||||
checked: boolean;
|
|
||||||
requester_nick?: string;
|
|
||||||
actor: number;
|
|
||||||
}
|
|
||||||
interface RetData {
|
interface RetData {
|
||||||
InvitedRequest: Notify[];
|
InvitedRequest: Notify[];
|
||||||
join_requests: Notify[];
|
join_requests: Notify[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetGroupIgnoredNotifies extends OneBotAction<void, RetData> {
|
export class GetGroupIgnoredNotifies extends OneBotAction<void, RetData> {
|
||||||
actionName = ActionName.GetGroupSystemMsg;
|
actionName = ActionName.GetGroupIgnoredNotifies;
|
||||||
|
|
||||||
async _handle(): Promise<RetData> {
|
async _handle(): Promise<RetData> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50);
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(false, 50);
|
|
||||||
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
||||||
|
|
||||||
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
||||||
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
const invitorUin = SSNotify.user1?.uid ? +await this.core.apis.UserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
||||||
const actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
const actorUin = SSNotify.user2?.uid ? +await this.core.apis.UserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
|
|
||||||
const commonData = {
|
const commonData = {
|
||||||
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
request_id: +SSNotify.seq,
|
||||||
invitor_uin: invitorUin,
|
invitor_uin: invitorUin,
|
||||||
invitor_nick: SSNotify.user1?.nickName,
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
group_id: +SSNotify.group?.groupCode,
|
group_id: +SSNotify.group?.groupCode,
|
||||||
|
message: SSNotify?.postscript,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: actorUin,
|
actor: actorUin,
|
||||||
|
@@ -4,9 +4,9 @@ import { ActionName } from '@/onebot/action/router';
|
|||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
flag: Type.String(),
|
flag: Type.Union([Type.String(), Type.Number()]),
|
||||||
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||||
reason: Type.Union([Type.String({ default: ' ' }), Type.Null()]),
|
reason: Type.Optional(Type.Union([Type.String({ default: ' ' }), Type.Null()])),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Payload = Static<typeof SchemaData>;
|
type Payload = Static<typeof SchemaData>;
|
||||||
@@ -18,10 +18,26 @@ export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
|||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const flag = payload.flag.toString();
|
const flag = payload.flag.toString();
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
await this.core.apis.GroupApi.handleGroupRequest(flag,
|
const reason = payload.reason ?? ' ';
|
||||||
|
|
||||||
|
let notify = await this.findNotify(flag);
|
||||||
|
if (!notify) {
|
||||||
|
throw new Error('No such request');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.core.apis.GroupApi.handleGroupRequest(
|
||||||
|
notify,
|
||||||
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
payload.reason ?? ' ',
|
reason,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async findNotify(flag: string) {
|
||||||
|
let notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(false, 100)).find(e => e.seq == flag);
|
||||||
|
if (!notify) {
|
||||||
|
notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(true, 100)).find(e => e.seq == flag);
|
||||||
|
}
|
||||||
|
return notify;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,59 +1,39 @@
|
|||||||
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';
|
||||||
|
import { Notify } from '@/onebot/types';
|
||||||
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 {
|
interface RetData {
|
||||||
InvitedRequest: Notify[];
|
InvitedRequest: Notify[];
|
||||||
join_requests: JoinRequest[];
|
join_requests: Notify[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
||||||
actionName = ActionName.GetGroupSystemMsg;
|
actionName = ActionName.GetGroupSystemMsg;
|
||||||
|
|
||||||
async _handle(): Promise<RetData> {
|
async _handle(): Promise<RetData> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50);
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(false, 50);
|
|
||||||
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
const retData: RetData = { InvitedRequest: [], join_requests: [] };
|
||||||
|
|
||||||
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
const notifyPromises = SingleScreenNotifies.map(async (SSNotify) => {
|
||||||
const invitorUin = SSNotify.user1?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
const invitorUin = SSNotify.user1?.uid ? +await this.core.apis.UserApi.getUinByUidV2(SSNotify.user1.uid) : 0;
|
||||||
const actorUin = SSNotify.user2?.uid ? +await NTQQUserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
const actorUin = SSNotify.user2?.uid ? +await this.core.apis.UserApi.getUinByUidV2(SSNotify.user2.uid) : 0;
|
||||||
|
const commonData = {
|
||||||
if (SSNotify.type === 1) {
|
request_id: +SSNotify.seq,
|
||||||
retData.InvitedRequest.push({
|
|
||||||
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
|
||||||
invitor_uin: invitorUin,
|
invitor_uin: invitorUin,
|
||||||
invitor_nick: SSNotify.user1?.nickName,
|
invitor_nick: SSNotify.user1?.nickName,
|
||||||
group_id: +SSNotify.group?.groupCode,
|
group_id: +SSNotify.group?.groupCode,
|
||||||
|
message: SSNotify?.postscript,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: actorUin,
|
actor: actorUin,
|
||||||
});
|
|
||||||
} else if (SSNotify.type === 7) {
|
|
||||||
retData.join_requests.push({
|
|
||||||
request_id: `${SSNotify.group.groupCode}|${SSNotify.seq}|${SSNotify.type}`,
|
|
||||||
invitor_uin: invitorUin,
|
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
group_id: +SSNotify.group?.groupCode,
|
};
|
||||||
group_name: SSNotify.group?.groupName,
|
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
if (SSNotify.type === 1) {
|
||||||
actor: actorUin,
|
retData.InvitedRequest.push(commonData);
|
||||||
});
|
} else if (SSNotify.type === 7) {
|
||||||
|
retData.join_requests.push(commonData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import { ActionName } from '@/onebot/action/router';
|
|||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
const SchemaData = Type.Object({
|
const SchemaData = Type.Object({
|
||||||
flag: Type.String(),
|
flag: Type.Union([Type.String(), Type.Number()]),
|
||||||
approve: Type.Optional(Type.Union([Type.String(), Type.Boolean()])),
|
approve: Type.Optional(Type.Union([Type.String(), Type.Boolean()])),
|
||||||
remark: Type.Optional(Type.String())
|
remark: Type.Optional(Type.String())
|
||||||
});
|
});
|
||||||
@@ -16,14 +16,13 @@ export default class SetFriendAddRequest extends OneBotAction<Payload, null> {
|
|||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
await this.core.apis.FriendApi.handleFriendRequest(payload.flag, approve);
|
let notify = (await this.core.apis.FriendApi.getBuddyReq()).buddyReqs.find(e => e.reqTime == payload.flag.toString());
|
||||||
if (payload.remark) {
|
if (!notify) {
|
||||||
const data = payload.flag.split('|');
|
throw new Error('No such request');
|
||||||
if (data.length < 2) {
|
|
||||||
throw new Error('Invalid flag');
|
|
||||||
}
|
}
|
||||||
const friendUid = data[0];
|
await this.core.apis.FriendApi.handleFriendRequest(notify, approve);
|
||||||
await this.core.apis.FriendApi.setBuddyRemark(friendUid, payload.remark);
|
if (payload.remark) {
|
||||||
|
await this.core.apis.FriendApi.setBuddyRemark(notify.friendUid, payload.remark);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -333,7 +333,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.core,
|
this.core,
|
||||||
+requesterUin,
|
+requesterUin,
|
||||||
req.extWords,
|
req.extWords,
|
||||||
req.friendUid + '|' + req.reqTime
|
req.reqTime
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -365,8 +365,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
if (notifyTime < this.bootTime) {
|
if (notifyTime < this.bootTime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
const flag = notify.seq;
|
||||||
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type;
|
|
||||||
this.context.logger.logDebug('收到群通知', notify);
|
this.context.logger.logDebug('收到群通知', notify);
|
||||||
if (
|
if (
|
||||||
[GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS].includes(notify.type) &&
|
[GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS].includes(notify.type) &&
|
||||||
|
@@ -11,6 +11,17 @@ export interface OB11User {
|
|||||||
categoryName?: string; // 分组名称
|
categoryName?: string; // 分组名称
|
||||||
categoryId?: number; // 分组ID 999为特别关心
|
categoryId?: number; // 分组ID 999为特别关心
|
||||||
}
|
}
|
||||||
|
export interface Notify {
|
||||||
|
request_id: number;
|
||||||
|
invitor_uin: number;
|
||||||
|
invitor_nick?: string;
|
||||||
|
group_id?: number;
|
||||||
|
group_name?: string;
|
||||||
|
message?: string;
|
||||||
|
checked: boolean;
|
||||||
|
actor: number;
|
||||||
|
requester_nick?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export enum OB11UserSex {
|
export enum OB11UserSex {
|
||||||
male = 'male', // 男性
|
male = 'male', // 男性
|
||||||
|
Reference in New Issue
Block a user