Add CheckCommandPerm to correct namespace
This commit is contained in:
parent
dade5809fd
commit
9fba590893
@ -3,6 +3,7 @@ using Discord;
|
||||
using Discord.Commands;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using ChaosBot.Discord.PreConditions;
|
||||
using NLog;
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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<PreconditionResult> 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<PreconditionResult> 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<string>($"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<string>($"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."));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user