Add core reference interface

This commit is contained in:
Evert Prants 2020-12-03 19:20:15 +02:00
parent d3c649f684
commit 53fc842210
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 27 additions and 10 deletions

20
src/core/coreref.ts Normal file
View File

@ -0,0 +1,20 @@
import { ChannelManager } from '../channel';
import { NPMExecutor } from '../npm';
import { PluginManager, PluginMetaLoader } from '../plugin';
import { RepositoryManager } from '../plugin/repository';
import { Configuration, IEnvironment } from '../types';
import { ScopedEventEmitter } from '../util';
export interface ISqueebotCore {
environment: IEnvironment;
npm: NPMExecutor;
stream: ScopedEventEmitter;
pluginManager: PluginManager;
repositoryManager: RepositoryManager;
channelManager: ChannelManager;
pluginLoader: PluginMetaLoader;
config: Configuration;
initialize(autostart: boolean): Promise<void>;
shutdown(): void;
}

View File

@ -1,2 +1,3 @@
export { loadEnvironment } from './environment';
export { Logger, logger } from './logger';
export * from './environment';
export * from './logger';
export * from './coreref';

View File

@ -36,7 +36,7 @@ export class Configuration {
if (key.indexOf('.') !== -1) {
const split = key.split('.');
const first = this.get(split[0], null, from);
if (first) {
if (first != null) {
return this.get(split.slice(1).join('.'), defval, first);
}
return defval;
@ -55,7 +55,7 @@ export class Configuration {
return defval;
}
if (!from[key]) {
if (from[key] == null) {
return defval;
}
@ -71,7 +71,7 @@ export class Configuration {
if (key.indexOf('.') !== -1) {
const split = key.split('.');
const first = this.get(split[0], null, from);
if (first) {
if (first != null) {
return this.set(split.slice(1).join('.'), value, first);
}
return false;
@ -90,10 +90,6 @@ export class Configuration {
return false;
}
if (!from[key]) {
return false;
}
from[key] = value;
return true;
}
@ -102,7 +98,7 @@ export class Configuration {
this.defaults = defconf;
}
private saveDefaults(): void {
public saveDefaults(): void {
this.config = this.defaults || {};
this.save();
}