fixes
This commit is contained in:
parent
7976aec044
commit
ccbf487725
@ -7,7 +7,7 @@ import {
|
|||||||
} from '@squeebot/core/lib/plugin';
|
} from '@squeebot/core/lib/plugin';
|
||||||
|
|
||||||
import { IChannel } from '@squeebot/core/lib/channel';
|
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 { ISqueebotCore, logger } from '@squeebot/core/lib/core';
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@ -163,6 +163,16 @@ const ControlCommands: { [key: string]: Function } = {
|
|||||||
}
|
}
|
||||||
return p.core!.repositoryManager.uninstallRepository(repo);
|
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[]> => {
|
listRepositories: async (p: ControlPlugin): Promise<IRepository[]> => {
|
||||||
return p.core!.repositoryManager.getAll();
|
return p.core!.repositoryManager.getAll();
|
||||||
},
|
},
|
||||||
@ -394,7 +404,7 @@ class ControlPlugin extends Plugin {
|
|||||||
|
|
||||||
this.executeControlCommand(req.command, args).then((cmdData) => {
|
this.executeControlCommand(req.command, args).then((cmdData) => {
|
||||||
try {
|
try {
|
||||||
const response: any = { status: 'OK' };
|
const response: any = { status: 'OK', command: req.command };
|
||||||
if (cmdData != null) {
|
if (cmdData != null) {
|
||||||
if (Array.isArray(cmdData)) {
|
if (Array.isArray(cmdData)) {
|
||||||
response.list = cmdData;
|
response.list = cmdData;
|
||||||
@ -438,7 +448,7 @@ class ControlPlugin extends Plugin {
|
|||||||
socket.setEncoding('utf8');
|
socket.setEncoding('utf8');
|
||||||
socket.write(JSON.stringify({
|
socket.write(JSON.stringify({
|
||||||
status: 'OK',
|
status: 'OK',
|
||||||
command: Object.keys(ControlCommands),
|
commands: Object.keys(ControlCommands),
|
||||||
}) + '\r\n');
|
}) + '\r\n');
|
||||||
|
|
||||||
socket.on('data', (data) => {
|
socket.on('data', (data) => {
|
||||||
|
@ -262,7 +262,7 @@ class SqueebotCommandsAPIPlugin extends Plugin {
|
|||||||
logger.error('[%s] Command handler threw an error:', this.name, e.stack));
|
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 (Array.isArray(spec)) {
|
||||||
if (!spec.length) {
|
if (!spec.length) {
|
||||||
return false;
|
return false;
|
||||||
@ -273,13 +273,13 @@ class SqueebotCommandsAPIPlugin extends Plugin {
|
|||||||
|
|
||||||
let success = true;
|
let success = true;
|
||||||
for (const sp of spec) {
|
for (const sp of spec) {
|
||||||
if (!this.registerCommand(sp)) {
|
if (!this.registerCommand(sp, true)) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
} else {
|
} else if (!bulk) {
|
||||||
logger.log('[%s] Plugin %s registered command %s', this.name,
|
logger.log('[%s] Plugin %s registered command %s', this.name,
|
||||||
spec.plugin, spec.name);
|
spec.plugin, spec.name);
|
||||||
}
|
}
|
||||||
@ -413,10 +413,13 @@ class SqueebotCommandsAPIPlugin extends Plugin {
|
|||||||
logger.debug('[%s] shutting down..', this.name);
|
logger.debug('[%s] shutting down..', this.name);
|
||||||
this.config.save().then(() =>
|
this.config.save().then(() =>
|
||||||
this.emit('pluginUnloaded', this));
|
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;
|
module.exports = SqueebotCommandsAPIPlugin;
|
||||||
|
Loading…
Reference in New Issue
Block a user