mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-13 00:10:27 +00:00
refactor: friend add
This commit is contained in:
@@ -15,7 +15,7 @@ const SchemaData = {
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetLongNick extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetSelfProfile;
|
||||
actionName = ActionName.SetLongNick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
let ret = await NTQQUserApi.setLongNick(payload.longNick)
|
||||
|
||||
@@ -2,7 +2,6 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQFriendApi } from '@/core/apis/friend';
|
||||
import { friendRequests } from '@/core/data';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
@@ -21,8 +20,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
const request = friendRequests[payload.flag];
|
||||
await NTQQFriendApi.handleFriendRequest(request, approve);
|
||||
await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import { OB11GroupIncreaseEvent } from './event/notice/OB11GroupIncreaseEvent';
|
||||
import { OB11GroupBanEvent } from './event/notice/OB11GroupBanEvent';
|
||||
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent';
|
||||
import { OB11GroupNoticeEvent } from './event/notice/OB11GroupNoticeEvent';
|
||||
import { OB11FriendAddNoticeEvent } from './event/notice/OB11FriendAddNoticeEvent';
|
||||
|
||||
import { calcQQLevel } from '../common/utils/qqlevel';
|
||||
import { log, logDebug, logError } from '../common/utils/log';
|
||||
@@ -454,18 +453,6 @@ export class OB11Constructor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async FriendAddEvent(msg: RawMessage): Promise<OB11FriendAddNoticeEvent | undefined> {
|
||||
if (msg.chatType !== ChatType.friend) {
|
||||
return;
|
||||
}
|
||||
if (msg.msgType === 5 && msg.subMsgType === 12) {
|
||||
const event = new OB11FriendAddNoticeEvent(parseInt(msg.peerUin));
|
||||
return event;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static friend(friend: User): OB11User {
|
||||
return {
|
||||
user_id: parseInt(friend.uin),
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'friend_add';
|
||||
user_id: number;
|
||||
|
||||
public constructor(user_Id: number) {
|
||||
super();
|
||||
this.user_id = user_Id;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { MsgListener, TempOnRecvParams } from '@/core/listeners';
|
||||
import { OB11Constructor } from '@/onebot11/constructor';
|
||||
import { postOB11Event } from '@/onebot11/server/postOB11Event';
|
||||
import {
|
||||
BuddyReqType,
|
||||
ChatType,
|
||||
FriendRequest,
|
||||
Group,
|
||||
@@ -17,7 +18,7 @@ import { OB11Config, ob11Config } from '@/onebot11/config';
|
||||
import { httpHeart, ob11HTTPServer } from '@/onebot11/server/http';
|
||||
import { ob11WebsocketServer } from '@/onebot11/server/ws/WebsocketServer';
|
||||
import { ob11ReverseWebsockets } from '@/onebot11/server/ws/ReverseWebsocket';
|
||||
import { friendRequests, getFriend, getGroup, getGroupMember, groupNotifies, selfInfo, tempGroupCodeMap } from '@/core/data';
|
||||
import { getFriend, getGroup, getGroupMember, groupNotifies, selfInfo, tempGroupCodeMap } from '@/core/data';
|
||||
import { dbUtil } from '@/common/utils/db';
|
||||
import { BuddyListener, GroupListener, NodeIKernelBuddyListener } from '@/core/listeners';
|
||||
import { OB11FriendRequestEvent } from '@/onebot11/event/request/OB11FriendRequest';
|
||||
@@ -334,11 +335,6 @@ export class NapCatOnebot11 {
|
||||
postOB11Event(groupEvent);
|
||||
}
|
||||
}).catch(e => logError('constructGroupEvent error: ', e));
|
||||
OB11Constructor.FriendAddEvent(message).then(friendAddEvent => {
|
||||
if (friendAddEvent) {
|
||||
postOB11Event(friendAddEvent);
|
||||
}
|
||||
}).catch(e => logError('constructFriendAddEvent error: ', e));
|
||||
}
|
||||
}
|
||||
async SetConfig(NewOb11: OB11Config) {
|
||||
@@ -525,14 +521,9 @@ export class NapCatOnebot11 {
|
||||
|
||||
async postFriendRequest(reqs: FriendRequest[]) {
|
||||
for (const req of reqs) {
|
||||
if (parseInt(req.reqTime) < this.bootTime) {
|
||||
if (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM) {
|
||||
continue;
|
||||
}
|
||||
const flag = req.friendUid + '|' + req.reqTime;
|
||||
if (friendRequests[flag]) {
|
||||
continue;
|
||||
}
|
||||
friendRequests[flag] = req;
|
||||
const friendRequestEvent = new OB11FriendRequestEvent();
|
||||
try {
|
||||
const requesterUin = await NTQQUserApi.getUinByUid(req.friendUid);
|
||||
@@ -540,7 +531,7 @@ export class NapCatOnebot11 {
|
||||
} catch (e) {
|
||||
logDebug('获取加好友者QQ号失败', e);
|
||||
}
|
||||
friendRequestEvent.flag = flag;
|
||||
friendRequestEvent.flag = req.friendUid + "|" + req.reqTime;
|
||||
friendRequestEvent.comment = req.extWords;
|
||||
postOB11Event(friendRequestEvent);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest';
|
||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||
import { isNull } from '@/common/utils/helper';
|
||||
import { dbUtil } from '@/common/utils/db';
|
||||
import { friendRequests, getGroup, groupNotifies, selfInfo } from '@/core/data';
|
||||
import { getGroup, groupNotifies, selfInfo } from '@/core/data';
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQUserApi } from '@/core/apis';
|
||||
import createSendElements from '../action/msg/SendMsg/create-send-elements';
|
||||
|
||||
@@ -176,7 +176,7 @@ async function handleGroupRequest(request: OB11GroupRequestEvent, quickAction: Q
|
||||
}
|
||||
async function handleFriendRequest(request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
|
||||
if (!isNull(quickAction.approve)) {
|
||||
NTQQFriendApi.handleFriendRequest(friendRequests[request.flag], !!quickAction.approve).then().catch(logError);
|
||||
NTQQFriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(logError);
|
||||
}
|
||||
}
|
||||
export async function handleQuickOperation(context: QuickActionEvent, quickAction: QuickAction) {
|
||||
|
||||
Reference in New Issue
Block a user