From b42c3eaf8889aaca676db98de3cafad8049db6eb Mon Sep 17 00:00:00 2001 From: liushuyu Date: Sat, 2 May 2020 17:15:06 -0600 Subject: [PATCH] bugfixes: more robust grantDeveloper command... ... and command is now case insensitive --- src/commands/grantDeveloper.ts | 18 ++++++++++++++---- src/server.ts | 11 ++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/commands/grantDeveloper.ts b/src/commands/grantDeveloper.ts index 910ccae..ab5a208 100644 --- a/src/commands/grantDeveloper.ts +++ b/src/commands/grantDeveloper.ts @@ -1,3 +1,5 @@ +import state from '../state'; +import logger from '../logging'; import discord = require('discord.js'); export const roles = ['Admins', 'Moderators', 'CitraBot']; @@ -8,11 +10,19 @@ export function command (message: discord.Message) { const alreadyJoined = member.roles.cache.has(role); if (alreadyJoined) { - member.roles.remove(role); - message.channel.send(`${user.toString()}'s speech has been revoked in the #development channel.`); + member.roles.remove(role).then(() => { + message.channel.send(`${user.toString()}'s speech has been revoked in the #development channel.`); + }).catch(() => { + state.logChannel.send(`Error revoking ${user.toString()}'s developer speech...`); + logger.error(`Error revoking ${user} ${user.username}'s developer speech...`); + }); } else { - member.roles.add(role); - message.channel.send(`${user.toString()} has been granted speech in the #development channel.`); + member.roles.add(role).then(() => { + message.channel.send(`${user.toString()} has been granted speech in the #development channel.`); + }).catch(() => { + state.logChannel.send(`Error granting ${user.toString()}'s developer speech...`); + logger.error(`Error granting ${user} ${user.username}'s developer speech...`); + }); } }); } diff --git a/src/server.ts b/src/server.ts index 4cb18dd..03df4e2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -148,7 +148,7 @@ client.on('message', message => { const cmd = message.content.split(' ', 1)[0].slice(1); // Check by the name of the command. - let cachedModule = cachedModules[`${cmd}.js`]; + let cachedModule = cachedModules[`${cmd.toLowerCase()}`]; let quoteResponse = null; // Check by the quotes in the configuration. if (!cachedModule) quoteResponse = state.responses.quotes[cmd]; @@ -167,8 +167,8 @@ client.on('message', message => { try { if (!!cachedModule) { cachedModule.command(message); - } else if (cachedModules['quote.js']) { - cachedModules['quote.js'].command(message, quoteResponse.reply); + } else if (cachedModules['quote']) { + cachedModules['quote'].command(message, quoteResponse.reply); } } catch (err) { logger.error(err); } @@ -183,8 +183,9 @@ fs.readdirSync('./commands/').forEach(function (file) { if (file.includes('.disabled')) { logger.info(`Did not load disabled module: ${file}`); } else { - logger.info(`Loaded module: ${file}`); - cachedModules[file] = require(`./commands/${file}`); + const moduleName = path.basename(file, '.js').toLowerCase(); + logger.info(`Loaded module: ${moduleName} from ${file}`); + cachedModules[moduleName] = require(`./commands/${file}`); } } });