Skip to content

Commit

Permalink
fix(discord): guild-only commands error in DM and don't show in help now
Browse files Browse the repository at this point in the history
They are hidden from general help & have a new field in the command-specific help that says it's
guild only
  • Loading branch information
dsevillamartin committed Jul 16, 2017
1 parent 1ea56ad commit 8e28ea7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/Discord/Commands/Conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ConfCommand extends Command {
};
this.setConf({
permLevel: 1,
guildOnly: true,
});
}
run(msg, args) {
Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Commands/GitlabInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GitlabInitCommand extends Command {
this.setConf({
permLevel: 1,
aliases: ['initialize'],
guildOnly: true,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Commands/GitlabInitOrg.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GitlabInitOrgCommand extends Command {
this.setConf({
permLevel: 1,
aliases: ['initializeorg'],
guildOnly: true,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Commands/GitlabIssue.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class GitlabIssue extends Command {

this.setConf({
aliases: ['issues'],
guildOnly: true,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Commands/GitlabMergeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GitlabIssue extends Command {
'mergerequest',
'merge',
],
guildOnly: true,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Commands/GitlabRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GitlabRemoveCommand extends Command {

this.setConf({
permLevel: 1,
guildOnly: true,
});
}

Expand Down
20 changes: 13 additions & 7 deletions lib/Discord/Commands/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command>\` for details\n\u200B`)
Expand All @@ -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 });
}
Expand Down
1 change: 1 addition & 0 deletions lib/Discord/Modules/RunCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8e28ea7

Please sign in to comment.