Restarting plugins

This commit is contained in:
Evert Prants 2020-11-29 13:34:47 +02:00
parent 9841b7d571
commit 974fe320f0
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 20 additions and 1 deletions

View File

@ -79,7 +79,7 @@ export class SqueebotCLI {
}
private async pluginCommand(...args: any[]): Promise<void> {
const help = 'plugin install | update | uninstall | enable | disable | start | stop | list | running [<name>]';
const help = 'plugin install | update | uninstall | enable | disable | start | restart | stop | list | running [<name>]';
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.');

View File

@ -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<void> {