Add logic to CommandService.Execute to handle basic permissions checks

This commit is contained in:
Finite Reality
2016-08-03 16:43:25 +01:00
parent 757c36ccd1
commit 023703c996

View File

@@ -208,7 +208,14 @@ namespace Discord.Commands
if (!searchResult.IsSuccess)
return searchResult;
var commands = searchResult.Commands;
// TODO: this logic is for users who don't manually search/execute: should we keep it?
IReadOnlyList<Command> commands = searchResult.Commands
.Where(x => x.CanExecute(message)).ToImmutableArray();
if (commands.Count == 0 && searchResult.Commands.Count > 0)
return ParseResult.FromError(CommandError.InvalidPermissions, "Invalid permissions");
for (int i = commands.Count - 1; i >= 0; i--)
{
var parseResult = await commands[i].Parse(message, searchResult);