Remove RequireRole precondition
This commit is contained in:
parent
7f0524b947
commit
dade5809fd
@ -14,7 +14,7 @@ namespace ChaosBot.Discord.Modules
|
|||||||
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
|
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
|
||||||
|
|
||||||
[Command("config")]
|
[Command("config")]
|
||||||
[RequireRole("Admin")]
|
[CheckCommandPerm]
|
||||||
public async Task setConfig(string configFlag = null, string value = null)
|
public async Task setConfig(string configFlag = null, string value = null)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|||||||
@ -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."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user