mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: emit buddy/request
This commit is contained in:
parent
3a1c428917
commit
f311ab5f7b
@ -21,7 +21,8 @@ type NapCatInternalEvents = {
|
||||
'message/send': (msg: RawMessage) => PromiseLike<void>;
|
||||
|
||||
|
||||
'buddy/request': (request: FriendRequest) => PromiseLike<void>;
|
||||
'buddy/request': (uid: string, words: string,
|
||||
xRequest: FriendRequest) => PromiseLike<void>;
|
||||
|
||||
'buddy/add': (uin: string,
|
||||
xMsg: RawMessage) => PromiseLike<void>;
|
||||
@ -87,6 +88,7 @@ export class NapCatEventChannel extends
|
||||
super();
|
||||
|
||||
this.initMsgListener();
|
||||
this.initBuddyListener();
|
||||
}
|
||||
|
||||
private initMsgListener() {
|
||||
@ -133,4 +135,28 @@ export class NapCatEventChannel extends
|
||||
proxiedListenerOf(msgListener, this.core.context.logger) as any,
|
||||
);
|
||||
}
|
||||
|
||||
private initBuddyListener() {
|
||||
const buddyListener = new NodeIKernelBuddyListener();
|
||||
|
||||
buddyListener.onBuddyReqChange = async reqs => {
|
||||
await this.core.apis.FriendApi.clearBuddyReqUnreadCnt();
|
||||
for (let i = 0; i < reqs.unreadNums; i++) {
|
||||
const req = reqs.buddyReqs[i];
|
||||
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const reqUin = await this.core.apis.UserApi.getUinByUidV2(req.friendUid);
|
||||
this.emit('buddy/request', reqUin, req.extWords, req);
|
||||
} catch (e) {
|
||||
this.core.context.logger.logDebug('获取加好友者 QQ 号失败', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.core.context.session.getBuddyService().addKernelBuddyListener(
|
||||
proxiedListenerOf(buddyListener, this.core.context.logger) as any,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user