NapCatQQ/packages/napcat-protocol/event/NapCatProtocolEvent.ts
手瓜一十雪 65bae6b57a
Some checks are pending
Build NapCat Artifacts / Build-Framework (push) Waiting to run
Build NapCat Artifacts / Build-Shell (push) Waiting to run
Introduce NapCat Protocol and adapter management
Added the new napcat-protocol package with protocol config, event, API, and network management modules. Introduced napcat-adapter package to unify protocol adapter management, replacing direct OneBot usage in framework and shell. Updated napcat-framework and napcat-shell to use NapCatAdapterManager for protocol initialization and registration. Adjusted dependencies and Vite configs to include new packages.
2026-01-29 22:14:55 +08:00

67 lines
1.7 KiB
TypeScript

import { NapCatCore } from 'napcat-core';
// NapCat Protocol 事件基类
export abstract class NapCatProtocolEvent {
protected core: NapCatCore;
public time: number;
public self_id: number;
public post_type: string;
constructor (core: NapCatCore) {
this.core = core;
this.time = Math.floor(Date.now() / 1000);
this.self_id = parseInt(core.selfInfo.uin);
this.post_type = 'event';
}
abstract toJSON (): Record<string, unknown>;
}
// 消息事件基类
export abstract class NapCatProtocolMessageEvent extends NapCatProtocolEvent {
public message_type: 'private' | 'group';
public message_id: number;
public user_id: number;
constructor (core: NapCatCore, messageType: 'private' | 'group', messageId: number, userId: number) {
super(core);
this.post_type = 'message';
this.message_type = messageType;
this.message_id = messageId;
this.user_id = userId;
}
}
// 通知事件基类
export abstract class NapCatProtocolNoticeEvent extends NapCatProtocolEvent {
public notice_type: string;
constructor (core: NapCatCore, noticeType: string) {
super(core);
this.post_type = 'notice';
this.notice_type = noticeType;
}
}
// 请求事件基类
export abstract class NapCatProtocolRequestEvent extends NapCatProtocolEvent {
public request_type: string;
constructor (core: NapCatCore, requestType: string) {
super(core);
this.post_type = 'request';
this.request_type = requestType;
}
}
// 元事件基类
export abstract class NapCatProtocolMetaEvent extends NapCatProtocolEvent {
public meta_event_type: string;
constructor (core: NapCatCore, metaEventType: string) {
super(core);
this.post_type = 'meta_event';
this.meta_event_type = metaEventType;
}
}