Skip to content

Commit

Permalink
fix: custom commands not being accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Sep 16, 2018
1 parent e9b6cf8 commit 504c48e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/CommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const fs = require('fs');
const path = require('path');
const decache = require('decache');

const BaseCommand = require('./models/Command');

const commandDir = path.join(__dirname, 'commands');

/**
Expand Down Expand Up @@ -48,6 +50,10 @@ class CommandManager {
return this.commandCache[manifest.id];
}

if (manifest instanceof BaseCommand) {
return manifest;
}

// eslint-disable-next-line global-require, import/no-dynamic-require
const Command = require(path.join(commandDir, manifest.path));
const command = new Command(this.bot);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CustomCommands/AddCustomCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AddCustomCommand extends Command {
return this.messageManager.statuses.FAILURE;
}
await this.settings.addCustomCommand(message, params[1], encodeURIComponent(params[2]));
await this.commandHandler.loadCustomCommands();
await this.commandManager.loadCustomCommands();
await this.messageManager.notifySettingsChange(message, true, true);
return this.messageManager.statuses.SUCCESS;
}
Expand Down
11 changes: 9 additions & 2 deletions src/commands/CustomCommands/ListCustomCommand.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Command = require('../../models/Command.js');
const { createGroupedArray } = require('../../CommonFunctions.js');
const { createGroupedArray, createPageCollector } = require('../../CommonFunctions.js');

class ListCustomCommand extends Command {
constructor(bot) {
Expand All @@ -22,9 +22,16 @@ class ListCustomCommand extends Command {
}
});
const metaGroups = createGroupedArray(ccs, 10);
const pages = [];
metaGroups.forEach((metaGroup) => {
this.messageManager.embed(message, { color: 0x301934, fields: metaGroup }, true, false);
pages.push({ color: 0x301934, fields: metaGroup, title: 'Custom Commands' });
});
if (pages.length) {
const msg = await this.messageManager.embed(message, pages[0], false, false);
await createPageCollector(msg, pages, message.author);
} else {
await this.messageManager.embed(message, { color: 0x301934, description: 'No Custom Commands', title: 'Custom Commands' }, true, true);
}

return this.messageManager.statuses.SUCCESS;
}
Expand Down
4 changes: 3 additions & 1 deletion src/eventHandlers/CommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CommandHandler extends Handler {

this.statuses = this.bot.messageManager.statuses;
this.commandManager = this.bot.commandManager;
this.logger = bot.logger;
}

/**
Expand Down Expand Up @@ -69,10 +70,11 @@ class CommandHandler extends Handler {
if (checkOnlyInlines) {
commands = this.commandManager.inlineCommands;
} else if (ctx.allowCustom) {
commands = this.commandManager.commands.concat(this.customCommands);
commands = this.commandManager.commands.concat(this.commandManager.customCommands);
} else {
({ commands } = this.commandManager);
}
commands = commands.filter(command => command);

if (content.startsWith(ctx.prefix)) {
content = content.replace(ctx.prefix, '');
Expand Down

0 comments on commit 504c48e

Please sign in to comment.