diff --git a/package.json b/package.json index fa7bb8fa..a997bc3e 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "qrcode-terminal": "^0.12.0", "silk-wasm": "^3.6.1", "strtok3": "8.0.1", + "typed-emitter": "^2.1.0", "ws": "^8.18.0" } } diff --git a/src/core/events.ts b/src/core/events.ts new file mode 100644 index 00000000..dbdeb77b --- /dev/null +++ b/src/core/events.ts @@ -0,0 +1,78 @@ +import { FileElement, FriendRequest, GrayTipElement, GroupNotify, RawMessage } from '@/core/entities'; +import { NodeIKernelMsgListener } from '@/core/listeners'; +import EventEmitter from 'node:events'; +import TypedEmitter from 'typed-emitter/rxjs'; +import { NapCatCore } from '@/core/index'; + +type NapCatInternalEvents = { + 'message/receive': (msg: RawMessage) => PromiseLike; + + 'message/send': (msg: RawMessage) => PromiseLike; + + + 'buddy/request': (request: FriendRequest) => PromiseLike; + + 'buddy/add': (uin: string, + xMsg: RawMessage) => PromiseLike; + + 'buddy/poke': (initiatorUin: string, targetUin: string, displayMsg: string, + xMsg: RawMessage) => PromiseLike; + + 'buddy/recall': (uin: string, messageId: string, + xMsg: RawMessage) => PromiseLike; + + 'buddy/input-status': (data: Parameters[0]) => PromiseLike; + + + 'group/request': (request: GroupNotify) => PromiseLike; + + 'group/admin': (groupCode: string, targetUin: string, operation: 'set' | 'unset', + // If it comes from onMemberInfoChange + xDataSource?: RawMessage, xMsg?: RawMessage, + // If it comes from onGroupNotifiesUpdated + xGroupNotify?: GroupNotify) => PromiseLike; + + 'group/mute': (groupCode: string, targetUin: string, duration: number, operation: 'mute' | 'unmute', + xGrayTipElement: GrayTipElement, xMsg: RawMessage) => PromiseLike; + + 'group/card-change': (groupCode: string, changedUin: string, newCard: string, oldCard: string, + xMsg: RawMessage) => PromiseLike; + + 'group/member-increase': (groupCode: string, targetUin: string, operatorUin: string, reason: 'invite' | 'approve' | 'unknown', + xGrayTipElement: GrayTipElement, xMsg: RawMessage) => PromiseLike; + + 'group/member-decrease': (groupCode: string, targetUin: string, operatorUin: string, reason: 'leave' | 'kick' | 'unknown', + xGrayTipElement: GrayTipElement, xMsg: RawMessage) => PromiseLike; + + 'group/essence': (groupCode: string, messageId: string, senderUin: string, operation: 'add' | 'delete', + xGrayTipElement: GrayTipElement, + xGrayTipSourceMsg: RawMessage /* this is not the message that is set to be essence msg */) => PromiseLike; + + 'group/recall': (groupCode: string, operatorUin: string, messageId: string, + xGrayTipSourceMsg: RawMessage /* This is not the message that is recalled */) => PromiseLike; + + 'group/title': (groupCode: string, targetUin: string, newTitle: string, + xMsg: RawMessage) => PromiseLike; + + 'group/upload': (groupCode: string, uploaderUin: string, fileElement: FileElement, + xMsg: RawMessage) => PromiseLike; + + 'group/emoji-like': (groupCode: string, operatorUin: string, messageId: string, likes: { emojiId: string, count: number }[], + // If it comes from onRecvMsg + xGrayTipElement?: GrayTipElement, xMsg?: RawMessage, + // If it comes from onRecvSysMsg + xSysMsg?: number[]) => PromiseLike; + + 'group/poke': (groupCode: string, initiatorUin: string, targetUin: string, displayMsg: string, + xGrayTipElement: GrayTipElement, xMsg: RawMessage) => PromiseLike; +} + +export class NapCatEventChannel extends + // eslint-disable-next-line + // @ts-ignore + (EventEmitter as new () => TypedEmitter) { + + constructor(public core: NapCatCore) { + super(); + } +}