Merge branch 'develop' into master
This commit is contained in:
commit
d32973e7ba
@ -20,6 +20,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
[Command("level")]
|
[Command("level")]
|
||||||
[Alias("xp", "exp", "experience", "lvl")]
|
[Alias("xp", "exp", "experience", "lvl")]
|
||||||
[CheckCommandPerm("User")]
|
[CheckCommandPerm("User")]
|
||||||
|
[CheckModuleEnabled("Experience")]
|
||||||
public async Task XpShowInfo()
|
public async Task XpShowInfo()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
45
ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs
Normal file
45
ChaosBot/Discord/PreConditions/CheckModuleEnabled.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ChaosBot.Models;
|
||||||
|
using ChaosBot.Repositories;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
namespace ChaosBot.Discord.PreConditions
|
||||||
|
{
|
||||||
|
public class CheckModuleEnabled : PreconditionAttribute
|
||||||
|
{
|
||||||
|
private static ILogger _logger = Program.Logger;
|
||||||
|
private readonly string _moduleName;
|
||||||
|
public CheckModuleEnabled(string moduleName) => _moduleName = moduleName;
|
||||||
|
|
||||||
|
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
|
||||||
|
{
|
||||||
|
// Debug information
|
||||||
|
_logger.Trace($"CheckModuleEnabled.CheckPermissionsAsync|Checking module enabled for module: {_moduleName}");
|
||||||
|
|
||||||
|
if (context.Guild == null) return Task.FromResult(PreconditionResult.FromError("This must be run in a guild."));
|
||||||
|
|
||||||
|
// Check if module enabled in database
|
||||||
|
bool isModuleEnabled = GetResult(context, _moduleName);
|
||||||
|
|
||||||
|
if (isModuleEnabled)
|
||||||
|
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||||
|
|
||||||
|
// Permission denied
|
||||||
|
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetResult(ICommandContext context, string moduleName)
|
||||||
|
{
|
||||||
|
if (context.Guild == null) throw new Exception("This must be run in a guild");
|
||||||
|
|
||||||
|
// Check if module enabled in database
|
||||||
|
return Convert.ToBoolean(ConfigurationRepository.GetValue<string>($"Module:{moduleName}:Enabled",
|
||||||
|
context.Guild.Id, "true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using ChaosBot.Discord.PreConditions;
|
||||||
using ChaosBot.Models;
|
using ChaosBot.Models;
|
||||||
using ChaosBot.Repositories;
|
using ChaosBot.Repositories;
|
||||||
using Discord;
|
using Discord;
|
||||||
@ -19,6 +20,8 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace ChaosBot.Services
|
|||||||
|
|
||||||
public static async Task<Boolean> IsAllowed(string key)
|
public static async Task<Boolean> IsAllowed(string key)
|
||||||
{
|
{
|
||||||
|
// TODO: List populated from DB
|
||||||
List<string> restrictedCfg = new List<string> {"Database:Host", "Database:Port", "Database:Name", "Database:User", "Database:Pass", "Bot:Version", "NLog", "WebServer", "Discord:Token"};
|
List<string> restrictedCfg = new List<string> {"Database:Host", "Database:Port", "Database:Name", "Database:User", "Database:Pass", "Bot:Version", "NLog", "WebServer", "Discord:Token"};
|
||||||
|
|
||||||
if (restrictedCfg.Contains(key))
|
if (restrictedCfg.Contains(key))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user