diff --git a/NadekoBot/Classes/Permissions/PermissionChecker.cs b/NadekoBot/Classes/Permissions/PermissionChecker.cs index da173a0d..7b8a5c09 100644 --- a/NadekoBot/Classes/Permissions/PermissionChecker.cs +++ b/NadekoBot/Classes/Permissions/PermissionChecker.cs @@ -5,6 +5,7 @@ using Discord; using Discord.Commands; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq.Expressions; using NadekoBot.Classes.JSONModels; namespace NadekoBot.Classes.Permissions { @@ -98,9 +99,14 @@ namespace NadekoBot.Classes.Permissions { return false; } catch (Exception ex) { Console.WriteLine($"Exception in canrun: {ex}"); - ServerPermissions perms; - if (PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms) && perms.Verbose) //if verbose - print errors - error = ex.Message; + try { + ServerPermissions perms; + if (PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms) && perms.Verbose) + //if verbose - print errors + error = ex.Message; + } catch (Exception ex2) { + Console.WriteLine($"SERIOUS PERMISSION ERROR {ex2}\n\nUser:{user} Server: {user?.Server?.Name}/{user?.Server?.Id}"); + } return false; } } diff --git a/NadekoBot/Classes/Permissions/PermissionsHandler.cs b/NadekoBot/Classes/Permissions/PermissionsHandler.cs index f0994752..114a0d8a 100644 --- a/NadekoBot/Classes/Permissions/PermissionsHandler.cs +++ b/NadekoBot/Classes/Permissions/PermissionsHandler.cs @@ -72,10 +72,6 @@ namespace NadekoBot.Classes.Permissions { internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) { var server = user.Server; ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name)); - if (!PermissionsDict.TryGetValue(server.Id, out serverPerms)) { - serverPerms = new ServerPermissions(server.Id, server.Name); - PermissionsDict.TryAdd(server.Id, serverPerms); - } bool val; Permissions perm; //server @@ -183,7 +179,7 @@ namespace NadekoBot.Classes.Permissions { if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else - modules.Add(moduleName, value); + modules.TryAdd(moduleName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -195,7 +191,7 @@ namespace NadekoBot.Classes.Permissions { if (commands.ContainsKey(commandName)) commands[commandName] = value; else - commands.Add(commandName, value); + commands.TryAdd(commandName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -213,7 +209,7 @@ namespace NadekoBot.Classes.Permissions { if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else - modules.Add(moduleName, value); + modules.TryAdd(moduleName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -230,7 +226,7 @@ namespace NadekoBot.Classes.Permissions { if (commands.ContainsKey(commandName)) commands[commandName] = value; else - commands.Add(commandName, value); + commands.TryAdd(commandName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -247,7 +243,7 @@ namespace NadekoBot.Classes.Permissions { if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else - modules.Add(moduleName, value); + modules.TryAdd(moduleName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -264,7 +260,7 @@ namespace NadekoBot.Classes.Permissions { if (commands.ContainsKey(commandName)) commands[commandName] = value; else - commands.Add(commandName, value); + commands.TryAdd(commandName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -281,7 +277,7 @@ namespace NadekoBot.Classes.Permissions { if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else - modules.Add(moduleName, value); + modules.TryAdd(moduleName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -297,7 +293,7 @@ namespace NadekoBot.Classes.Permissions { if (commands.ContainsKey(commandName)) commands[commandName] = value; else - commands.Add(commandName, value); + commands.TryAdd(commandName, value); Task.Run(() => WriteServerToJson(serverPerms)); } @@ -369,11 +365,11 @@ namespace NadekoBot.Classes.Permissions { /// /// Module name with allowed/disallowed /// - public Dictionary Modules { get; set; } + public ConcurrentDictionary Modules { get; set; } /// /// Command name with allowed/disallowed /// - public Dictionary Commands { get; set; } + public ConcurrentDictionary Commands { get; set; } /// /// Should the bot filter invites to other discord servers (and ref links in the future) /// @@ -385,8 +381,8 @@ namespace NadekoBot.Classes.Permissions { public Permissions(string name) { Name = name; - Modules = new Dictionary(); - Commands = new Dictionary(); + Modules = new ConcurrentDictionary(); + Commands = new ConcurrentDictionary(); FilterInvites = false; FilterWords = false; } diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index 0c62be7a..e4258799 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -2,7 +2,6 @@ "DontJoinServers": false, "ForwardMessages": true, "IsRotatingStatus": false, - "SendPrivateMessageOnMention": false, "ObservingStreams": [], "RotatingStatuses": [], "CommandPrefixes": {