Added custom error to AddCheck(lambda)
This commit is contained in:
@@ -75,9 +75,9 @@ namespace Discord.Commands
|
||||
_checks.Add(check);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -140,9 +140,9 @@ namespace Discord.Commands
|
||||
{
|
||||
_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)
|
||||
|
||||
@@ -5,15 +5,17 @@ namespace Discord.Commands.Permissions
|
||||
internal class GenericPermissionChecker : IPermissionChecker
|
||||
{
|
||||
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;
|
||||
_error = 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user