Added custom error to AddCheck(lambda)

This commit is contained in:
RogueException
2015-12-26 02:35:12 -04:00
parent 53cf815d1a
commit f61b9febfb
2 changed files with 8 additions and 6 deletions

View File

@@ -75,9 +75,9 @@ namespace Discord.Commands
_checks.Add(check); _checks.Add(check);
return this; return this;
} }
public CommandBuilder AddCheck(Func<Command, User, Channel, bool> checkFunc) public CommandBuilder AddCheck(Func<Command, User, Channel, bool> checkFunc, string errorMsg = null)
{ {
_checks.Add(new GenericPermissionChecker(checkFunc)); _checks.Add(new GenericPermissionChecker(checkFunc, errorMsg));
return this; return this;
} }
@@ -140,9 +140,9 @@ namespace Discord.Commands
{ {
_checks.Add(checker); _checks.Add(checker);
} }
public void AddCheck(Func<Command, User, Channel, bool> checkFunc) public void AddCheck(Func<Command, User, Channel, bool> checkFunc, string errorMsg = null)
{ {
_checks.Add(new GenericPermissionChecker(checkFunc)); _checks.Add(new GenericPermissionChecker(checkFunc, errorMsg));
} }
public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config = null) public CommandGroupBuilder CreateGroup(string cmd, Action<CommandGroupBuilder> config = null)

View File

@@ -5,15 +5,17 @@ namespace Discord.Commands.Permissions
internal class GenericPermissionChecker : IPermissionChecker internal class GenericPermissionChecker : IPermissionChecker
{ {
private readonly Func<Command, User, Channel, bool> _checkFunc; private readonly Func<Command, User, Channel, bool> _checkFunc;
private readonly string _error;
public GenericPermissionChecker(Func<Command, User, Channel, bool> checkFunc) public GenericPermissionChecker(Func<Command, User, Channel, bool> checkFunc, string error = null)
{ {
_checkFunc = checkFunc; _checkFunc = checkFunc;
_error = error;
} }
public bool CanRun(Command command, User user, Channel channel, out string error) public bool CanRun(Command command, User user, Channel channel, out string error)
{ {
error = null; //Use default error text. error = _error;
return _checkFunc(command, user, channel); return _checkFunc(command, user, channel);
} }
} }