NadekoBot/src/NadekoBot/Services/Permissions/GlobalPermissionService.cs

38 lines
1.4 KiB
C#
Raw Normal View History

2017-05-29 23:53:16 +00:00
using NadekoBot.DataStructures.ModuleBehaviors;
using NadekoBot.Services.Database.Models;
using System.Collections.Concurrent;
using System.Linq;
2017-05-29 23:53:16 +00:00
using Discord;
using Discord.WebSocket;
using System.Threading.Tasks;
namespace NadekoBot.Services.Permissions
{
public class GlobalPermissionService : ILateBlocker, INService
{
public readonly ConcurrentHashSet<string> BlockedModules;
public readonly ConcurrentHashSet<string> BlockedCommands;
public GlobalPermissionService(BotConfig bc)
{
BlockedModules = new ConcurrentHashSet<string>(bc.BlockedModules.Select(x => x.Name));
BlockedCommands = new ConcurrentHashSet<string>(bc.BlockedCommands.Select(x => x.Name));
}
2017-05-29 23:53:16 +00:00
public async Task<bool> TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName)
2017-05-29 23:53:16 +00:00
{
await Task.Yield();
commandName = commandName.ToLowerInvariant();
if (commandName != "resetglobalperms" &&
(BlockedCommands.Contains(commandName) ||
BlockedModules.Contains(moduleName.ToLowerInvariant())))
{
return true;
//return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"Command or module is blocked globally by the bot owner."));
}
return false;
}
}
}