From 2b66cf3d5d5262cf9b666d92213897b2943406dd Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Thu, 2 Jul 2020 01:47:21 -0500 Subject: [PATCH] Simplify command prefixing --- lib/commands/help.js | 20 +++++++++++++------- lib/commands/index.js | 1 + lib/index.js | 14 ++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/commands/help.js b/lib/commands/help.js index 1f57602..facbf28 100644 --- a/lib/commands/help.js +++ b/lib/commands/help.js @@ -1,5 +1,7 @@ 'use strict'; +const PREFIX = require('./index').COMMAND_PREFIX; + /** * !help * @param {Object} msg Discord message @@ -7,14 +9,18 @@ module.exports = (msg) => { msg.channel.send([ '```', - 'Commands: help, deals, wishlist, add, delete\n', - '-Help: !help', - ' Go help yourself to some good deals.', - '-Deals: !deals [game name]', - ' Current deals on a specific game', - '-WishList: !wishlist [game names]', - ' Current deals on multiple games, add a \'-\' for games', + 'Commands: help, deals, wishlist, ignoredsellers\n', + `- ${PREFIX}help`, + ' This command', + `- ${PREFIX}deals [game name]`, + ' Gets current deals on a specific game', + `- ${PREFIX}wishlist [game names]`, + ' Gets current deals on multiple games, add a \'-\' for games', ' with multiple words', + `- ${PREFIX}ignoredsellers`, + ' Lists all ignored sellers', + `- ${PREFIX}ignoredsellers [add|remove] [seller]`, + ' Adds or removes an ignored seller', '```' ].join('\n')); }; diff --git a/lib/commands/index.js b/lib/commands/index.js index 4b9c238..dea2772 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -1,6 +1,7 @@ 'use strict'; module.exports = { + COMMAND_PREFIX: '!', help: require('./help'), deals: require('./deals'), wishlist: require('./wishlist'), diff --git a/lib/index.js b/lib/index.js index c4c1702..e76a943 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,13 +8,11 @@ const bot = new Discord.Client(); const commands = require('./commands'); const settingsUtil = require('./util/settings'); -const COMMAND_PREFIX = '!'; -const C_HELP = `${COMMAND_PREFIX}help`; -const C_DEALS = `${COMMAND_PREFIX}deals`; -const C_WISHLIST = `${COMMAND_PREFIX}wishlist`; -const C_IGNORED_SELLERS = `${COMMAND_PREFIX}ignoredsellers`; -const C_ADD = `${COMMAND_PREFIX}add`; -const C_REMOVE = `${COMMAND_PREFIX}remove`; +const PREFIX = commands.COMMAND_PREFIX; +const C_HELP = 'help'; +const C_DEALS = 'deals'; +const C_WISHLIST = 'wishlist'; +const C_IGNORED_SELLERS = 'ignoredsellers'; let settings = settingsUtil.DEFAULT_SETTINGS; @@ -43,7 +41,7 @@ bot.on('ready', async () => { bot.on('message', async (msg) => { const [command, options] = msg.content.split(/\s+(.*)/); - switch (command) { + switch (command.substring(PREFIX.length)) { case C_HELP: commands.help(msg); break;