This commit is contained in:
Evert Prants 2020-12-05 12:00:55 +02:00
parent 7976aec044
commit ccbf487725
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 21 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import {
} from '@squeebot/core/lib/plugin';
import { IChannel } from '@squeebot/core/lib/channel';
import { IRepository } from '@squeebot/core/lib/plugin/repository';
import { IRepoPluginDef, IRepository } from '@squeebot/core/lib/plugin/repository';
import { ISqueebotCore, logger } from '@squeebot/core/lib/core';
import path from 'path';
@ -163,6 +163,16 @@ const ControlCommands: { [key: string]: Function } = {
}
return p.core!.repositoryManager.uninstallRepository(repo);
},
listRepositoryPlugins: async (p: ControlPlugin, repo: string): Promise<IRepoPluginDef[]> => {
if (!repo) {
throw new Error('This function takes 1 argument.');
}
const repoData = p.core!.repositoryManager.getRepoByName(repo);
if (!repoData) {
throw new Error('No such repository found.');
}
return repoData.plugins;
},
listRepositories: async (p: ControlPlugin): Promise<IRepository[]> => {
return p.core!.repositoryManager.getAll();
},
@ -394,7 +404,7 @@ class ControlPlugin extends Plugin {
this.executeControlCommand(req.command, args).then((cmdData) => {
try {
const response: any = { status: 'OK' };
const response: any = { status: 'OK', command: req.command };
if (cmdData != null) {
if (Array.isArray(cmdData)) {
response.list = cmdData;
@ -438,7 +448,7 @@ class ControlPlugin extends Plugin {
socket.setEncoding('utf8');
socket.write(JSON.stringify({
status: 'OK',
command: Object.keys(ControlCommands),
commands: Object.keys(ControlCommands),
}) + '\r\n');
socket.on('data', (data) => {

View File

@ -262,7 +262,7 @@ class SqueebotCommandsAPIPlugin extends Plugin {
logger.error('[%s] Command handler threw an error:', this.name, e.stack));
}
public registerCommand(spec: CommandSpec | CommandSpec[]): boolean {
public registerCommand(spec: CommandSpec | CommandSpec[], bulk = false): boolean {
if (Array.isArray(spec)) {
if (!spec.length) {
return false;
@ -273,13 +273,13 @@ class SqueebotCommandsAPIPlugin extends Plugin {
let success = true;
for (const sp of spec) {
if (!this.registerCommand(sp)) {
if (!this.registerCommand(sp, true)) {
success = false;
}
}
return success;
} else {
} else if (!bulk) {
logger.log('[%s] Plugin %s registered command %s', this.name,
spec.plugin, spec.name);
}
@ -413,10 +413,13 @@ class SqueebotCommandsAPIPlugin extends Plugin {
logger.debug('[%s] shutting down..', this.name);
this.config.save().then(() =>
this.emit('pluginUnloaded', this));
} else {
this.unregisterPlugin((typeof plugin === 'string' ? plugin : plugin.manifest.name));
}
}
@EventListener('pluginUnloaded')
unloadedPlugin(plugin: string | Plugin): void {
this.unregisterPlugin((typeof plugin === 'string' ? plugin : plugin.manifest.name));
}
}
module.exports = SqueebotCommandsAPIPlugin;