From 974fe320f0e71c9ef66786ba6281dfe779df51e3 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sun, 29 Nov 2020 13:34:47 +0200 Subject: [PATCH] Restarting plugins --- src/cli.ts | 17 ++++++++++++++++- src/core.ts | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index b7184ca..69fac5a 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -79,7 +79,7 @@ export class SqueebotCLI { } private async pluginCommand(...args: any[]): Promise { - const help = 'plugin install | update | uninstall | enable | disable | start | stop | list | running []'; + const help = 'plugin install | update | uninstall | enable | disable | start | restart | stop | list | running []'; if (!args[0] || args[0] === 'help' || (!args[1] && args[0] !== 'list' && args[0] !== 'running')) { logger.log(help); return; @@ -126,8 +126,23 @@ export class SqueebotCLI { logger.log('Started plugin "%s" successfully.', name); } break; + case 'restart': + case 'reload': + for (const name of args.slice(1)) { + const plugin = this.bot.pluginManager.getAvailableByName(name); + if (!plugin) { + logger.error('"%s" is not available. Maybe try installing it? plugin install', name, name); + return; + } + + logger.log('Scheduling restart for', name); + + await this.bot.pluginManager.restart(plugin); + } + break; case 'stop': case 'kill': + case 'unload': for (const name of args.slice(1)) { if (!this.bot.pluginManager.getAvailableByName(name)) { logger.error('No such plugin is available.'); diff --git a/src/core.ts b/src/core.ts index 1543ec2..facf12e 100644 --- a/src/core.ts +++ b/src/core.ts @@ -76,6 +76,10 @@ export class Squeebot { // Start enabled plugins await this.startPlugins(); } + + // Send core on request + this.stream.on('core', 'request-core', (pl: string) => + this.stream.emitTo(pl, 'core', this)); } public async startPlugins(): Promise {