From 8e28ea7f67ccb82426902a1906d19ecac988570c Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Sun, 16 Jul 2017 08:41:08 -0400 Subject: [PATCH] fix(discord): guild-only commands error in DM and don't show in help now They are hidden from general help & have a new field in the command-specific help that says it's guild only --- lib/Discord/Commands/Conf.js | 1 + lib/Discord/Commands/GitlabInit.js | 1 + lib/Discord/Commands/GitlabInitOrg.js | 1 + lib/Discord/Commands/GitlabIssue.js | 1 + lib/Discord/Commands/GitlabMergeRequest.js | 1 + lib/Discord/Commands/GitlabRemove.js | 1 + lib/Discord/Commands/Help.js | 20 +++++++++++++------- lib/Discord/Modules/RunCommand.js | 1 + 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/Discord/Commands/Conf.js b/lib/Discord/Commands/Conf.js index 2903e9e..2684ec7 100644 --- a/lib/Discord/Commands/Conf.js +++ b/lib/Discord/Commands/Conf.js @@ -19,6 +19,7 @@ class ConfCommand extends Command { }; this.setConf({ permLevel: 1, + guildOnly: true, }); } run(msg, args) { diff --git a/lib/Discord/Commands/GitlabInit.js b/lib/Discord/Commands/GitlabInit.js index 8ad0c40..364c64e 100644 --- a/lib/Discord/Commands/GitlabInit.js +++ b/lib/Discord/Commands/GitlabInit.js @@ -23,6 +23,7 @@ class GitlabInitCommand extends Command { this.setConf({ permLevel: 1, aliases: ['initialize'], + guildOnly: true, }); } diff --git a/lib/Discord/Commands/GitlabInitOrg.js b/lib/Discord/Commands/GitlabInitOrg.js index da1d3fe..c76abfe 100644 --- a/lib/Discord/Commands/GitlabInitOrg.js +++ b/lib/Discord/Commands/GitlabInitOrg.js @@ -19,6 +19,7 @@ class GitlabInitOrgCommand extends Command { this.setConf({ permLevel: 1, aliases: ['initializeorg'], + guildOnly: true, }); } diff --git a/lib/Discord/Commands/GitlabIssue.js b/lib/Discord/Commands/GitlabIssue.js index cd60aa4..6e7ebdb 100644 --- a/lib/Discord/Commands/GitlabIssue.js +++ b/lib/Discord/Commands/GitlabIssue.js @@ -20,6 +20,7 @@ class GitlabIssue extends Command { this.setConf({ aliases: ['issues'], + guildOnly: true, }); } diff --git a/lib/Discord/Commands/GitlabMergeRequest.js b/lib/Discord/Commands/GitlabMergeRequest.js index 9a48093..612c9cf 100644 --- a/lib/Discord/Commands/GitlabMergeRequest.js +++ b/lib/Discord/Commands/GitlabMergeRequest.js @@ -23,6 +23,7 @@ class GitlabIssue extends Command { 'mergerequest', 'merge', ], + guildOnly: true, }); } diff --git a/lib/Discord/Commands/GitlabRemove.js b/lib/Discord/Commands/GitlabRemove.js index 30358b3..b2970da 100644 --- a/lib/Discord/Commands/GitlabRemove.js +++ b/lib/Discord/Commands/GitlabRemove.js @@ -19,6 +19,7 @@ class GitlabRemoveCommand extends Command { this.setConf({ permLevel: 1, + guildOnly: true, }); } diff --git a/lib/Discord/Commands/Help.js b/lib/Discord/Commands/Help.js index b24b851..7157b18 100644 --- a/lib/Discord/Commands/Help.js +++ b/lib/Discord/Commands/Help.js @@ -11,14 +11,18 @@ class HelpCommand extends Command { this.props.conf.aliases = ['support']; } run(msg, args) { - let commandName = args[0]; + const commandName = args[0]; if (!commandName) { - let commands = this.bot.commands; + const commands = this.bot.commands; let commandsForEveryone = commands.filter(e => !e.conf.permLevel || e.conf.permLevel === 0); let commandsForAdmin = commands.filter(e => e.conf.permLevel === 1); let commandsForOwner = commands.filter(e => e.conf.permLevel === 2); - let embed = new this.embed() + if (msg.channel.type === 'dm') { + commandsForEveryone = commandsForEveryone.filter(e => !e.conf.guildOnly); + } + + const embed = new this.embed() .setColor('#84F139') .setTitle(`Commands List`) .setDescription(`Use \`${this.bot.prefix}help \` for details\n\u200B`) @@ -43,21 +47,23 @@ class HelpCommand extends Command { return msg.channel.send({ embed }); } else if (commandName) { - let command = this.bot.commands.get(commandName) || (this.bot.aliases.has(commandName) ? this.bot.commands.get(this.bot.aliases.get(commandName)) : null); + const command = this.bot.commands.get(commandName) || (this.bot.aliases.has(commandName) ? this.bot.commands.get(this.bot.aliases.get(commandName)) : null); if (!command) return this.commandError(msg, `Command \`${commandName}\` doesn't exist`); - let embed = new this.embed() + const embed = new this.embed() .setColor('#84F139') .setTitle(`Command \`${command.help.name}\``) .setDescription(`${command.help.description || command.help.summary}\n\u200B`) .setFooter(this.bot.user.username, this.bot.user.avatarURL) - .addField('Usage', `\`${this.bot.prefix}${command.help.usage}\``); + .addField('Usage', `\`${this.bot.prefix}${command.help.usage}\``, true); if (command.conf.aliases && command.conf.aliases.length) embed.addField('Aliases', command.conf.aliases.map(e => `\`${e}\``).join(', '), true); if (command.help.examples && command.help.examples.length) { embed.addField('Examples', command.help.examples.map(e => `\`${this.bot.prefix}${e}\``).join('\n'), true); } - embed.addField('Permission', `${this._permLevelToWord(command.conf.permLevel)}\n\u200B`); + + embed.addField('Permission', `${this._permLevelToWord(command.conf.permLevel)}\n\u200B`, true) + .addField('Guild Only', command.conf.guildOnly ? 'Yes' : 'No', true); return msg.channel.send({ embed }); } diff --git a/lib/Discord/Modules/RunCommand.js b/lib/Discord/Modules/RunCommand.js index 5d9ef89..b416f01 100644 --- a/lib/Discord/Modules/RunCommand.js +++ b/lib/Discord/Modules/RunCommand.js @@ -19,6 +19,7 @@ class RunCommandModule extends Module { } if (perms < cmd.conf.permLevel) return cmd.commandError(msg, `Insufficient permissions! Must be **${cmd._permLevelToWord(cmd.conf.permLevel)}** or higher`); + if (msg.channel.type === 'dm' && cmd.conf.guildOnly) return cmd.commandError(msg, `You can only run **${cmd.help.name}** in a guild.`); try { let commandRun = cmd.run(msg, args);