mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-16 13:01:14 +00:00
feat: initBuddyListener
This commit is contained in:
parent
f25fdcdc3d
commit
4e7595d8d1
@ -1,4 +1,4 @@
|
|||||||
import { ChatType, InstanceContext, MsgListener, NapCatCore, RawMessage } from '@/core';
|
import { BuddyListener, BuddyReqType, ChatType, InstanceContext, MsgListener, NapCatCore, RawMessage } from '@/core';
|
||||||
import { OB11Config } from './helper/config';
|
import { OB11Config } from './helper/config';
|
||||||
import { NapCatPathWrapper } from '@/common/framework/napcat';
|
import { NapCatPathWrapper } from '@/common/framework/napcat';
|
||||||
import { OneBotApiContextType } from '@/onebot/types';
|
import { OneBotApiContextType } from '@/onebot/types';
|
||||||
@ -14,6 +14,7 @@ import { InitWebUi } from '@/webui';
|
|||||||
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
||||||
import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRecallNoticeEvent';
|
import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRecallNoticeEvent';
|
||||||
import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent';
|
import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent';
|
||||||
|
import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest';
|
||||||
|
|
||||||
//OneBot实现类
|
//OneBot实现类
|
||||||
export class NapCatOneBot11Adapter {
|
export class NapCatOneBot11Adapter {
|
||||||
@ -86,7 +87,10 @@ export class NapCatOneBot11Adapter {
|
|||||||
|
|
||||||
await this.networkManager.registerAllActions(actions);
|
await this.networkManager.registerAllActions(actions);
|
||||||
await this.networkManager.openAllAdapters();
|
await this.networkManager.openAllAdapters();
|
||||||
await this.initMsgListener();
|
|
||||||
|
this.initMsgListener();
|
||||||
|
this.initBuddyListener();
|
||||||
|
|
||||||
// 未对shell版本兼容
|
// 未对shell版本兼容
|
||||||
// Mlikiowa V2.0.0 Refactor Todo
|
// Mlikiowa V2.0.0 Refactor Todo
|
||||||
WebUiDataRuntime.setQQLoginUin(selfInfo.uin.toString());
|
WebUiDataRuntime.setQQLoginUin(selfInfo.uin.toString());
|
||||||
@ -97,7 +101,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
InitWebUi(this.context.logger, this.context.pathWrapper).then().catch(this.context.logger.logError);
|
InitWebUi(this.context.logger, this.context.pathWrapper).then().catch(this.context.logger.logError);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initMsgListener() {
|
private initMsgListener() {
|
||||||
const msgListener = new MsgListener();
|
const msgListener = new MsgListener();
|
||||||
|
|
||||||
msgListener.onInputStatusPush = async data => {
|
msgListener.onInputStatusPush = async data => {
|
||||||
@ -155,6 +159,33 @@ export class NapCatOneBot11Adapter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initBuddyListener() {
|
||||||
|
const buddyListener = new BuddyListener();
|
||||||
|
|
||||||
|
buddyListener.onBuddyReqChange = reqs => {
|
||||||
|
reqs.buddyReqs.forEach(async req => {
|
||||||
|
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const requesterUin = await this.core.ApiContext.UserApi.getUinByUidV2(req.friendUid);
|
||||||
|
await this.networkManager.emitEvent(new OB11FriendRequestEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(requesterUin!),
|
||||||
|
req.friendUid + '|' + req.reqTime,
|
||||||
|
req.extWords
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
this.context.logger.logDebug('获取加好友者QQ号失败', e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.context.session.getBuddyService().addKernelBuddyListener(
|
||||||
|
new this.context.wrapper.NodeIBuddyListener(proxiedListenerOf(buddyListener, this.context.logger)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async emitMsg(message: RawMessage) {
|
private async emitMsg(message: RawMessage) {
|
||||||
const { debug, reportSelfMessage } = this.config;
|
const { debug, reportSelfMessage } = this.config;
|
||||||
this.context.logger.logDebug('收到新消息', message);
|
this.context.logger.logDebug('收到新消息', message);
|
||||||
|
Loading…
Reference in New Issue
Block a user