weird fixes

This commit is contained in:
Master Kwoth 2016-03-14 15:33:28 +01:00
parent 12feb9ee2a
commit 1e679ff0c6
3 changed files with 21 additions and 20 deletions

View File

@ -5,6 +5,7 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
namespace NadekoBot.Classes.Permissions { namespace NadekoBot.Classes.Permissions {
@ -98,9 +99,14 @@ namespace NadekoBot.Classes.Permissions {
return false; return false;
} catch (Exception ex) { } catch (Exception ex) {
Console.WriteLine($"Exception in canrun: {ex}"); Console.WriteLine($"Exception in canrun: {ex}");
ServerPermissions perms; try {
if (PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms) && perms.Verbose) //if verbose - print errors ServerPermissions perms;
error = ex.Message; 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; return false;
} }
} }

View File

@ -72,10 +72,6 @@ namespace NadekoBot.Classes.Permissions {
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) { internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) {
var server = user.Server; var server = user.Server;
ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name)); 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; bool val;
Permissions perm; Permissions perm;
//server //server
@ -183,7 +179,7 @@ namespace NadekoBot.Classes.Permissions {
if (modules.ContainsKey(moduleName)) if (modules.ContainsKey(moduleName))
modules[moduleName] = value; modules[moduleName] = value;
else else
modules.Add(moduleName, value); modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -195,7 +191,7 @@ namespace NadekoBot.Classes.Permissions {
if (commands.ContainsKey(commandName)) if (commands.ContainsKey(commandName))
commands[commandName] = value; commands[commandName] = value;
else else
commands.Add(commandName, value); commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -213,7 +209,7 @@ namespace NadekoBot.Classes.Permissions {
if (modules.ContainsKey(moduleName)) if (modules.ContainsKey(moduleName))
modules[moduleName] = value; modules[moduleName] = value;
else else
modules.Add(moduleName, value); modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -230,7 +226,7 @@ namespace NadekoBot.Classes.Permissions {
if (commands.ContainsKey(commandName)) if (commands.ContainsKey(commandName))
commands[commandName] = value; commands[commandName] = value;
else else
commands.Add(commandName, value); commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -247,7 +243,7 @@ namespace NadekoBot.Classes.Permissions {
if (modules.ContainsKey(moduleName)) if (modules.ContainsKey(moduleName))
modules[moduleName] = value; modules[moduleName] = value;
else else
modules.Add(moduleName, value); modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -264,7 +260,7 @@ namespace NadekoBot.Classes.Permissions {
if (commands.ContainsKey(commandName)) if (commands.ContainsKey(commandName))
commands[commandName] = value; commands[commandName] = value;
else else
commands.Add(commandName, value); commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -281,7 +277,7 @@ namespace NadekoBot.Classes.Permissions {
if (modules.ContainsKey(moduleName)) if (modules.ContainsKey(moduleName))
modules[moduleName] = value; modules[moduleName] = value;
else else
modules.Add(moduleName, value); modules.TryAdd(moduleName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -297,7 +293,7 @@ namespace NadekoBot.Classes.Permissions {
if (commands.ContainsKey(commandName)) if (commands.ContainsKey(commandName))
commands[commandName] = value; commands[commandName] = value;
else else
commands.Add(commandName, value); commands.TryAdd(commandName, value);
Task.Run(() => WriteServerToJson(serverPerms)); Task.Run(() => WriteServerToJson(serverPerms));
} }
@ -369,11 +365,11 @@ namespace NadekoBot.Classes.Permissions {
/// <summary> /// <summary>
/// Module name with allowed/disallowed /// Module name with allowed/disallowed
/// </summary> /// </summary>
public Dictionary<string, bool> Modules { get; set; } public ConcurrentDictionary<string, bool> Modules { get; set; }
/// <summary> /// <summary>
/// Command name with allowed/disallowed /// Command name with allowed/disallowed
/// </summary> /// </summary>
public Dictionary<string, bool> Commands { get; set; } public ConcurrentDictionary<string, bool> Commands { get; set; }
/// <summary> /// <summary>
/// Should the bot filter invites to other discord servers (and ref links in the future) /// Should the bot filter invites to other discord servers (and ref links in the future)
/// </summary> /// </summary>
@ -385,8 +381,8 @@ namespace NadekoBot.Classes.Permissions {
public Permissions(string name) { public Permissions(string name) {
Name = name; Name = name;
Modules = new Dictionary<string, bool>(); Modules = new ConcurrentDictionary<string, bool>();
Commands = new Dictionary<string, bool>(); Commands = new ConcurrentDictionary<string, bool>();
FilterInvites = false; FilterInvites = false;
FilterWords = false; FilterWords = false;
} }

View File

@ -2,7 +2,6 @@
"DontJoinServers": false, "DontJoinServers": false,
"ForwardMessages": true, "ForwardMessages": true,
"IsRotatingStatus": false, "IsRotatingStatus": false,
"SendPrivateMessageOnMention": false,
"ObservingStreams": [], "ObservingStreams": [],
"RotatingStatuses": [], "RotatingStatuses": [],
"CommandPrefixes": { "CommandPrefixes": {