Remove RequireRole precondition

This commit is contained in:
Daniel_I_Am 2020-06-17 12:50:13 +02:00
parent 7f0524b947
commit dade5809fd
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 1 additions and 35 deletions

View File

@ -14,7 +14,7 @@ namespace ChaosBot.Discord.Modules
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
[Command("config")]
[RequireRole("Admin")]
[CheckCommandPerm]
public async Task setConfig(string configFlag = null, string value = null)
{
var sb = new StringBuilder();

View File

@ -1,34 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using ChaosBot;
using ChaosBot.Database.Repository;
using Discord.Commands;
using Discord.WebSocket;
public class RequireRole : PreconditionAttribute
{
private string _role { get; set; }
public RequireRole(string role) => _role = role;
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
if (context.User is SocketGuildUser gUser)
{
/*
* Owner has access to all commands
*/
if(context.Guild.OwnerId == context.User.Id) return Task.FromResult(PreconditionResult.FromSuccess());
var requiredGroup = (ConfigurationRepository.GetValue<string>($"Role:{_role}", context.Guild.Id) != null) ? ConfigurationRepository.GetValue<string>($"Role:{_role}", context.Guild.Id) : _role;
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 {requiredGroup} to run this command."));
}
else
return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command."));
}
}