2017-07-20 03:10:39 +00:00
using System.Linq ;
2017-07-17 19:42:36 +00:00
using System.Threading.Tasks ;
2017-05-29 23:53:16 +00:00
using Discord ;
using Discord.WebSocket ;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Collections ;
using NadekoBot.Common.ModuleBehaviors ;
using NadekoBot.Services ;
2017-05-27 23:51:22 +00:00
2017-07-17 19:42:36 +00:00
namespace NadekoBot.Modules.Permissions.Services
2017-05-27 23:51:22 +00:00
{
2017-07-15 03:04:16 +00:00
public class GlobalPermissionService : ILateBlocker , INService
2017-05-27 23:51:22 +00:00
{
public readonly ConcurrentHashSet < string > BlockedModules ;
public readonly ConcurrentHashSet < string > BlockedCommands ;
2017-07-20 03:10:39 +00:00
public GlobalPermissionService ( IBotConfigProvider bc )
2017-05-27 23:51:22 +00:00
{
2017-07-20 03:10:39 +00:00
BlockedModules = new ConcurrentHashSet < string > ( bc . BotConfig . BlockedModules . Select ( x = > x . Name ) ) ;
BlockedCommands = new ConcurrentHashSet < string > ( bc . BotConfig . BlockedCommands . Select ( x = > x . Name ) ) ;
2017-05-27 23:51:22 +00:00
}
2017-05-29 23:53:16 +00:00
2017-06-19 13:42:10 +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 ;
}
2017-05-27 23:51:22 +00:00
}
}