mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-16 13:20:33 +00:00
Add isActive property to plugin adapters
Introduces an isActive getter to OB11PluginAdapter and OB11PluginMangerAdapter, which returns true only if the adapter is enabled and has loaded plugins. Updates event emission logic to use isActive instead of isEnable, ensuring events are only sent to active adapters.
This commit is contained in:
parent
31daf41135
commit
d23785f34d
@ -21,7 +21,7 @@ export class OB11NetworkManager {
|
|||||||
|
|
||||||
async emitEvent (event: OB11EmitEventContent) {
|
async emitEvent (event: OB11EmitEventContent) {
|
||||||
return Promise.all(Array.from(this.adapters.values()).map(async adapter => {
|
return Promise.all(Array.from(this.adapters.values()).map(async adapter => {
|
||||||
if (adapter.isEnable) {
|
if (adapter.isActive) {
|
||||||
return await adapter.onEvent(event);
|
return await adapter.onEvent(event);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -34,7 +34,7 @@ export class OB11NetworkManager {
|
|||||||
async emitEventByName (names: string[], event: OB11EmitEventContent) {
|
async emitEventByName (names: string[], event: OB11EmitEventContent) {
|
||||||
return Promise.all(names.map(async name => {
|
return Promise.all(names.map(async name => {
|
||||||
const adapter = this.adapters.get(name);
|
const adapter = this.adapters.get(name);
|
||||||
if (adapter && adapter.isEnable) {
|
if (adapter && adapter.isActive) {
|
||||||
return await adapter.onEvent(event);
|
return await adapter.onEvent(event);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -43,7 +43,7 @@ export class OB11NetworkManager {
|
|||||||
async emitEventByNames (map: Map<string, OB11EmitEventContent>) {
|
async emitEventByNames (map: Map<string, OB11EmitEventContent>) {
|
||||||
return Promise.all(Array.from(map.entries()).map(async ([name, event]) => {
|
return Promise.all(Array.from(map.entries()).map(async ([name, event]) => {
|
||||||
const adapter = this.adapters.get(name);
|
const adapter = this.adapters.get(name);
|
||||||
if (adapter && adapter.isEnable) {
|
if (adapter && adapter.isActive) {
|
||||||
return await adapter.onEvent(event);
|
return await adapter.onEvent(event);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -33,6 +33,10 @@ export class OB11PluginMangerAdapter extends IOB11NetworkAdapter<PluginConfig> {
|
|||||||
private readonly pluginPath: string;
|
private readonly pluginPath: string;
|
||||||
private loadedPlugins: Map<string, LoadedPlugin> = new Map();
|
private loadedPlugins: Map<string, LoadedPlugin> = new Map();
|
||||||
declare config: PluginConfig;
|
declare config: PluginConfig;
|
||||||
|
override get isActive (): boolean {
|
||||||
|
return this.isEnable && this.loadedPlugins.size > 0;
|
||||||
|
}
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
||||||
) {
|
) {
|
||||||
@ -251,7 +255,7 @@ export class OB11PluginMangerAdapter extends IOB11NetworkAdapter<PluginConfig> {
|
|||||||
this.logger.log(`[Plugin Adapter] Unloaded plugin: ${pluginName}`);
|
this.logger.log(`[Plugin Adapter] Unloaded plugin: ${pluginName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onEvent<T extends OB11EmitEventContent>(event: T) {
|
async onEvent<T extends OB11EmitEventContent> (event: T) {
|
||||||
if (!this.isEnable) {
|
if (!this.isEnable) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -359,7 +363,7 @@ export class OB11PluginMangerAdapter extends IOB11NetworkAdapter<PluginConfig> {
|
|||||||
|
|
||||||
// 重新加载插件
|
// 重新加载插件
|
||||||
const isDirectory = fs.statSync(plugin.pluginPath).isDirectory() &&
|
const isDirectory = fs.statSync(plugin.pluginPath).isDirectory() &&
|
||||||
plugin.pluginPath !== this.pluginPath;
|
plugin.pluginPath !== this.pluginPath;
|
||||||
|
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
const dirname = path.basename(plugin.pluginPath);
|
const dirname = path.basename(plugin.pluginPath);
|
||||||
|
|||||||
@ -33,6 +33,10 @@ export class OB11PluginAdapter extends IOB11NetworkAdapter<PluginConfig> {
|
|||||||
private readonly pluginPath: string;
|
private readonly pluginPath: string;
|
||||||
private loadedPlugins: Map<string, LoadedPlugin> = new Map();
|
private loadedPlugins: Map<string, LoadedPlugin> = new Map();
|
||||||
declare config: PluginConfig;
|
declare config: PluginConfig;
|
||||||
|
override get isActive (): boolean {
|
||||||
|
return this.isEnable && this.loadedPlugins.size > 0;
|
||||||
|
}
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
name: string, core: NapCatCore, obContext: NapCatOneBot11Adapter, actions: ActionMap
|
||||||
) {
|
) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user