mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 05:05:44 +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';
|
||||||
@ -44,7 +45,7 @@ export enum NapCatCoreWorkingEnv {
|
|||||||
Framework = 2,
|
Framework = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadQQWrapper (QQVersion: string): WrapperNodeApi {
|
export function loadQQWrapper(QQVersion: string): WrapperNodeApi {
|
||||||
if (process.env['NAPCAT_WRAPPER_PATH']) {
|
if (process.env['NAPCAT_WRAPPER_PATH']) {
|
||||||
const wrapperPath = process.env['NAPCAT_WRAPPER_PATH'];
|
const wrapperPath = process.env['NAPCAT_WRAPPER_PATH'];
|
||||||
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
|
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
|
||||||
@ -71,7 +72,7 @@ export function loadQQWrapper (QQVersion: string): WrapperNodeApi {
|
|||||||
process.dlopen(nativemodule, wrapperNodePath);
|
process.dlopen(nativemodule, wrapperNodePath);
|
||||||
return nativemodule.exports;
|
return nativemodule.exports;
|
||||||
}
|
}
|
||||||
export function getMajorPath (QQVersion: string): string {
|
export function getMajorPath(QQVersion: string): string {
|
||||||
// major.node
|
// major.node
|
||||||
let appPath;
|
let appPath;
|
||||||
if (os.platform() === 'darwin') {
|
if (os.platform() === 'darwin') {
|
||||||
@ -104,7 +105,7 @@ export class NapCatCore {
|
|||||||
configLoader: NapCatConfigLoader;
|
configLoader: NapCatConfigLoader;
|
||||||
|
|
||||||
// 通过构造器递过去的 runtime info 应该尽量少
|
// 通过构造器递过去的 runtime info 应该尽量少
|
||||||
constructor (context: InstanceContext, selfInfo: SelfInfo) {
|
constructor(context: InstanceContext, selfInfo: SelfInfo) {
|
||||||
this.selfInfo = selfInfo;
|
this.selfInfo = selfInfo;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.util = this.context.wrapper.NodeQQNTWrapperUtil;
|
this.util = this.context.wrapper.NodeQQNTWrapperUtil;
|
||||||
@ -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}`);
|
||||||
@ -132,7 +134,7 @@ export class NapCatCore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async initCore () {
|
async initCore() {
|
||||||
this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
|
this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
|
||||||
fs.mkdirSync(this.NapCatDataPath, { recursive: true });
|
fs.mkdirSync(this.NapCatDataPath, { recursive: true });
|
||||||
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
|
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
|
||||||
@ -161,7 +163,7 @@ export class NapCatCore {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get dataPath (): string {
|
get dataPath(): string {
|
||||||
let result = this.context.wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
|
let result = this.context.wrapper.NodeQQNTWrapperUtil.getNTUserDataInfoConfig();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = path.resolve(os.homedir(), './.config/QQ');
|
result = path.resolve(os.homedir(), './.config/QQ');
|
||||||
@ -171,7 +173,7 @@ export class NapCatCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Renamed from 'InitDataListener'
|
// Renamed from 'InitDataListener'
|
||||||
async initNapCatCoreListeners () {
|
async initNapCatCoreListeners() {
|
||||||
const msgListener = new NodeIKernelMsgListener();
|
const msgListener = new NodeIKernelMsgListener();
|
||||||
|
|
||||||
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
||||||
@ -209,7 +211,7 @@ export class NapCatCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function genSessionConfig (
|
export async function genSessionConfig(
|
||||||
guid: string,
|
guid: string,
|
||||||
QQVersionAppid: string,
|
QQVersionAppid: string,
|
||||||
QQVersion: string,
|
QQVersion: string,
|
||||||
|
|||||||
@ -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