diff --git a/ChaosBot/Discord/Modules/AdminCommands.cs b/ChaosBot/Discord/Modules/AdminCommands.cs index f8806ec..37ebec9 100644 --- a/ChaosBot/Discord/Modules/AdminCommands.cs +++ b/ChaosBot/Discord/Modules/AdminCommands.cs @@ -3,6 +3,7 @@ using Discord; using Discord.Commands; using System.Threading.Tasks; using System.Collections.Generic; +using ChaosBot.Discord.PreConditions; using NLog; diff --git a/ChaosBot/Discord/Modules/ConfigCommands.cs b/ChaosBot/Discord/Modules/ConfigCommands.cs index d1a2fba..709d462 100644 --- a/ChaosBot/Discord/Modules/ConfigCommands.cs +++ b/ChaosBot/Discord/Modules/ConfigCommands.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using NLog; using System.Text; using ChaosBot.Database.Repository; +using ChaosBot.Discord.PreConditions; namespace ChaosBot.Discord.Modules { diff --git a/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs b/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs index f37ed61..be123d1 100644 --- a/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs +++ b/ChaosBot/Discord/PreConditions/CheckCommandPerm.cs @@ -1,46 +1,48 @@ using System; using System.Linq; using System.Threading.Tasks; -using ChaosBot; using ChaosBot.Database.Repository; using Discord.Commands; using Discord.WebSocket; -public class CheckCommandPerm : PreconditionAttribute +namespace ChaosBot.Discord.PreConditions { - private string _cmd { get; set; } - - public override Task CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) + public class CheckCommandPerm : PreconditionAttribute { - string requiredGroup = null; + private string _cmd { get; set; } - if (context.User is SocketGuildUser gUser) + public override Task CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { - var results = CommandPermissionRepository.getPerm(command.Name, Convert.ToInt64(context.Guild.Id)); + string requiredGroup = null; - Program._logger.Info(command.Name); - - if(results != null) + if (context.User is SocketGuildUser gUser) { - foreach (var perm in results) - { - if (perm.type == "role") - requiredGroup = ConfigurationRepository.GetValue($"Role:{perm.value}", context.Guild.Id) ?? perm.value; - else - requiredGroup = perm.value; + var results = CommandPermissionRepository.getPerm(command.Name, Convert.ToInt64(context.Guild.Id)); - if (gUser.Roles.Any(r => r.Name == requiredGroup)) - return Task.FromResult(PreconditionResult.FromSuccess()); + Program._logger.Info(command.Name); + + if(results != null) + { + foreach (var perm in results) + { + if (perm.type == "role") + requiredGroup = ConfigurationRepository.GetValue($"Role:{perm.value}", context.Guild.Id) ?? perm.value; + else + requiredGroup = perm.value; + + if (gUser.Roles.Any(r => r.Name == requiredGroup)) + return Task.FromResult(PreconditionResult.FromSuccess()); + } } + else + { + Program._logger.Info($"Value: Null Value"); + } + + return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command.")); } else - { - Program._logger.Info($"Value: Null Value"); - } - - return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command.")); + return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command.")); } - else - return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command.")); } } \ No newline at end of file