mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-20 05:30:06 +08:00
Bind TypedEventEmitter to DI container and update usage
Added TypedEventEmitter to the dependency injection container and exposed it in ServiceBase. Updated OlPushService to use the injected event emitter instead of directly importing appEvent. Also performed minor code style improvements for consistency.
This commit is contained in:
parent
31bb1e5dee
commit
8e71dec63a
@ -33,6 +33,7 @@ import { NTQQPacketApi } from './apis/packet';
|
|||||||
import { NativePacketHandler } from './packet/handler/client';
|
import { NativePacketHandler } from './packet/handler/client';
|
||||||
import { container, ReceiverServiceRegistry } from './packet/handler/serviceRegister';
|
import { container, ReceiverServiceRegistry } from './packet/handler/serviceRegister';
|
||||||
import { appEvent } from './packet/handler/eventList';
|
import { appEvent } from './packet/handler/eventList';
|
||||||
|
import { TypedEventEmitter } from './packet/handler/typeEvent';
|
||||||
export * from './wrapper';
|
export * from './wrapper';
|
||||||
export * from './types/index';
|
export * from './types/index';
|
||||||
export * from './services/index';
|
export * from './services/index';
|
||||||
@ -122,6 +123,7 @@ export class NapCatCore {
|
|||||||
GroupApi: new NTQQGroupApi(this.context, this),
|
GroupApi: new NTQQGroupApi(this.context, this),
|
||||||
};
|
};
|
||||||
container.bind(NapCatCore).toConstantValue(this);
|
container.bind(NapCatCore).toConstantValue(this);
|
||||||
|
container.bind(TypedEventEmitter).toConstantValue(this.event);
|
||||||
ReceiverServiceRegistry.forEach((ServiceClass, serviceName) => {
|
ReceiverServiceRegistry.forEach((ServiceClass, serviceName) => {
|
||||||
container.bind(ServiceClass).toSelf();
|
container.bind(ServiceClass).toSelf();
|
||||||
console.log(`Registering service handler for: ${serviceName}`);
|
console.log(`Registering service handler for: ${serviceName}`);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { Container, injectable } from "inversify";
|
import { Container, injectable } from "inversify";
|
||||||
import { NapCatCore } from "../..";
|
import { NapCatCore } from "../..";
|
||||||
|
import { TypedEventEmitter } from "./typeEvent";
|
||||||
|
|
||||||
export const container = new Container();
|
export const container = new Container();
|
||||||
|
|
||||||
@ -10,6 +11,9 @@ export abstract class ServiceBase {
|
|||||||
get core(): NapCatCore {
|
get core(): NapCatCore {
|
||||||
return container.get(NapCatCore);
|
return container.get(NapCatCore);
|
||||||
}
|
}
|
||||||
|
get event() {
|
||||||
|
return container.get(TypedEventEmitter);
|
||||||
|
}
|
||||||
|
|
||||||
abstract handler(seq: number, hex_data: string): Promise<void> | void;
|
abstract handler(seq: number, hex_data: string): Promise<void> | void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { NapProtoMsg } from "napcat-protobuf";
|
import { NapProtoMsg } from "napcat-protobuf";
|
||||||
import { appEvent } from "../packet/handler/eventList";
|
|
||||||
import { ReceiveService, ServiceBase } from "../packet/handler/serviceRegister";
|
import { ReceiveService, ServiceBase } from "../packet/handler/serviceRegister";
|
||||||
import { GroupReactNotify, PushMsg } from "../packet/transformer/proto";
|
import { GroupReactNotify, PushMsg } from "../packet/transformer/proto";
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ export class OlPushService extends ServiceBase {
|
|||||||
const code = notify.groupReactionData?.data?.data?.groupReactionDataContent?.code ?? '';
|
const code = notify.groupReactionData?.data?.data?.groupReactionDataContent?.code ?? '';
|
||||||
const count = notify.groupReactionData?.data?.data?.groupReactionDataContent?.count ?? 0;
|
const count = notify.groupReactionData?.data?.data?.groupReactionDataContent?.count ?? 0;
|
||||||
const senderUin = await this.core.apis.UserApi.getUinByUidV2(operatorUid);
|
const senderUin = await this.core.apis.UserApi.getUinByUidV2(operatorUid);
|
||||||
appEvent.emit('event:emoji_like', {
|
this.event.emit('event:emoji_like', {
|
||||||
groupId: groupCode,
|
groupId: groupCode,
|
||||||
senderUin: senderUin,
|
senderUin: senderUin,
|
||||||
emojiId: code,
|
emojiId: code,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user