Updating Role -> Name
This commit is contained in:
parent
d7c997f0cf
commit
4e2f03bf4c
@ -8,33 +8,35 @@ using Discord.WebSocket;
|
||||
|
||||
public class RequireRole : PreconditionAttribute
|
||||
{
|
||||
private string _name { get; set; }
|
||||
private string _role { get; set; }
|
||||
|
||||
public RequireRole(string name) => _name = name;
|
||||
public RequireRole(string role) => _role = role;
|
||||
|
||||
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||
{
|
||||
string requiredGroup;
|
||||
|
||||
if (context.User is SocketGuildUser gUser)
|
||||
{
|
||||
switch (_name)
|
||||
switch (_role)
|
||||
{
|
||||
case "Admin":
|
||||
_name = ConfigurationRepository.GetValue<string>("Role:Admin", context.Guild.Id);
|
||||
requiredGroup = ConfigurationRepository.GetValue<string>("Role:Admin", context.Guild.Id);
|
||||
break;
|
||||
case "Officer":
|
||||
_name = ConfigurationRepository.GetValue<string>("Role:Officer", context.Guild.Id);
|
||||
requiredGroup = ConfigurationRepository.GetValue<string>("Role:Officer", context.Guild.Id);
|
||||
break;
|
||||
case "Member":
|
||||
_name = ConfigurationRepository.GetValue<string>("Role:Member", context.Guild.Id);
|
||||
requiredGroup = ConfigurationRepository.GetValue<string>("Role:Member", context.Guild.Id);
|
||||
break;
|
||||
default:
|
||||
return Task.FromResult(PreconditionResult.FromError($"{_name} is not a valid Permission Node."));
|
||||
return Task.FromResult(PreconditionResult.FromError($"{_role} is not a valid Permission Node."));
|
||||
}
|
||||
|
||||
if (gUser.Roles.Any(r => r.Name == _name))
|
||||
if (gUser.Roles.Any(r => r.Name == requiredGroup))
|
||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||
else
|
||||
return Task.FromResult(PreconditionResult.FromError($"You must have a role named {_name} to run this command."));
|
||||
return Task.FromResult(PreconditionResult.FromError($"You must have a role named {requiredGroup} to run this command."));
|
||||
}
|
||||
else
|
||||
return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command."));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user