Skip to content

Commit

Permalink
fix: #513
Browse files Browse the repository at this point in the history
  • Loading branch information
MliKiowa committed Nov 12, 2024
1 parent e287906 commit ed9cd2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/listeners/NodeIKernelMsgListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatType, RawMessage } from '@/core/entities';
import { ChatType, KickedOffLineInfo, RawMessage } from '@/core/entities';
import { CommonFileInfo } from '@/core';

export interface OnRichMediaDownloadCompleteParams {
Expand Down Expand Up @@ -212,7 +212,7 @@ export class NodeIKernelMsgListener {

}

onKickedOffLine(kickedInfo: unknown) {
onKickedOffLine(kickedInfo: KickedOffLineInfo) {

}

Expand Down
16 changes: 16 additions & 0 deletions src/onebot/event/notice/BotOfflineEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
import { NapCatCore } from '@/core';

export class BotOfflineEvent extends OB11BaseNoticeEvent {
notice_type = 'bot_offline';
user_id: number;
tag: string = 'BotOfflineEvent';
message: string = 'BotOfflineEvent';

public constructor(core: NapCatCore, tag: string, message: string) {
super(core);
this.user_id = +core.selfInfo.uin;
this.tag = tag;
this.message = message;
}
}
7 changes: 6 additions & 1 deletion src/onebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { LRUCache } from '@/common/lru-cache';
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
import { Native } from '@/native';
import { decodeMessage, decodeRecallGroup } from '@/core/packet/proto/old/Message';
import { BotOfflineEvent } from './event/notice/BotOfflineEvent';

//OneBot实现类
export class NapCatOneBot11Adapter {
Expand Down Expand Up @@ -343,7 +344,11 @@ export class NapCatOneBot11Adapter {
}
}
};

msgListener.onKickedOffLine = async (kick) => {
let event = new BotOfflineEvent(this.core, kick.tipsTitle, kick.tipsDesc);
this.networkManager.emitEvent(event)
.catch(e => this.context.logger.logError.bind(this.context.logger)('处理Bot掉线失败', e));
}
this.context.session.getMsgService().addKernelMsgListener(
proxiedListenerOf(msgListener, this.context.logger),
);
Expand Down

0 comments on commit ed9cd2f

Please sign in to comment.