diff --git a/NadekoBot/Classes/PermissionCheckers/PermissionsHandler.cs b/NadekoBot/Classes/PermissionCheckers/PermissionsHandler.cs index d8195524..2f9b074f 100644 --- a/NadekoBot/Classes/PermissionCheckers/PermissionsHandler.cs +++ b/NadekoBot/Classes/PermissionCheckers/PermissionsHandler.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Classes.Permissions { public static void SetServerModulePermission(Server server, string moduleName, bool value) { if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } var modules = _permissionsDict[server].Permissions.modules; if (modules.ContainsKey(moduleName)) @@ -40,7 +40,7 @@ namespace NadekoBot.Classes.Permissions { public static void SetServerCommandPermission(Server server, string commandName, bool value) { if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } var commands = _permissionsDict[server].Permissions.commands; if (commands.ContainsKey(commandName)) @@ -53,10 +53,10 @@ namespace NadekoBot.Classes.Permissions { public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) { var server = channel.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if(!_permissionsDict[server].ChannelPermissions.ContainsKey(channel.Id.ToString())) - _permissionsDict[server].ChannelPermissions.Add(channel.Id.ToString(), new Permissions()); + _permissionsDict[server].ChannelPermissions.Add(channel.Id.ToString(), new Permissions(channel.Name)); var modules = _permissionsDict[server].ChannelPermissions[channel.Id.ToString()].modules; @@ -70,10 +70,10 @@ namespace NadekoBot.Classes.Permissions { public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) { var server = channel.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if (!_permissionsDict[server].ChannelPermissions.ContainsKey(channel.Id.ToString())) - _permissionsDict[server].ChannelPermissions.Add(channel.Id.ToString(), new Permissions()); + _permissionsDict[server].ChannelPermissions.Add(channel.Id.ToString(), new Permissions(channel.Name)); var commands = _permissionsDict[server].ChannelPermissions[channel.Id.ToString()].commands; @@ -84,71 +84,71 @@ namespace NadekoBot.Classes.Permissions { WriteServerToJson(server); } - public static void SetRoleModulePermission(Role role, string roleName, bool value) { + public static void SetRoleModulePermission(Role role, string moduleName, bool value) { var server = role.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if (!_permissionsDict[server].RolePermissions.ContainsKey(role.Id.ToString())) - _permissionsDict[server].RolePermissions.Add(role.Id.ToString(), new Permissions()); + _permissionsDict[server].RolePermissions.Add(role.Id.ToString(), new Permissions(role.Name)); var modules = _permissionsDict[server].RolePermissions[role.Id.ToString()].modules; - if (modules.ContainsKey(roleName)) - modules[roleName] = value; + if (modules.ContainsKey(moduleName)) + modules[moduleName] = value; else - modules.Add(roleName, value); + modules.Add(moduleName, value); WriteServerToJson(server); } - public static void SetRoleCommandPermission(Role role, string roleName, bool value) { + public static void SetRoleCommandPermission(Role role, string commandName, bool value) { var server = role.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if (!_permissionsDict[server].RolePermissions.ContainsKey(role.Id.ToString())) - _permissionsDict[server].RolePermissions.Add(role.Id.ToString(), new Permissions()); + _permissionsDict[server].RolePermissions.Add(role.Id.ToString(), new Permissions(role.Name)); var commands = _permissionsDict[server].RolePermissions[role.Id.ToString()].commands; - if (commands.ContainsKey(roleName)) - commands[roleName] = value; + if (commands.ContainsKey(commandName)) + commands[commandName] = value; else - commands.Add(roleName, value); + commands.Add(commandName, value); WriteServerToJson(server); } - public static void SetUserModulePermission(User user, string userName, bool value) { + public static void SetUserModulePermission(User user, string moduleName, bool value) { var server = user.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if (!_permissionsDict[server].UserPermissions.ContainsKey(user.Id.ToString())) - _permissionsDict[server].UserPermissions.Add(user.Id.ToString(), new Permissions()); + _permissionsDict[server].UserPermissions.Add(user.Id.ToString(), new Permissions(user.Name)); var modules = _permissionsDict[server].UserPermissions[user.Id.ToString()].modules; - if (modules.ContainsKey(userName)) - modules[userName] = value; + if (modules.ContainsKey(moduleName)) + modules[moduleName] = value; else - modules.Add(userName, value); + modules.Add(moduleName, value); WriteServerToJson(server); } - public static void SetUserCommandPermission(User user, string userName, bool value) { + public static void SetUserCommandPermission(User user, string commandName, bool value) { var server = user.Server; if (!_permissionsDict.ContainsKey(server)) { - _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString())); + _permissionsDict.TryAdd(server, new ServerPermissions(server.Id.ToString(), server.Name)); } if (!_permissionsDict[server].UserPermissions.ContainsKey(user.Id.ToString())) - _permissionsDict[server].UserPermissions.Add(user.Id.ToString(), new Permissions()); + _permissionsDict[server].UserPermissions.Add(user.Id.ToString(), new Permissions(user.Name)); var commands = _permissionsDict[server].UserPermissions[user.Id.ToString()].commands; - if (commands.ContainsKey(userName)) - commands[userName] = value; + if (commands.ContainsKey(commandName)) + commands[commandName] = value; else - commands.Add(userName, value); + commands.Add(commandName, value); WriteServerToJson(server); } } @@ -156,6 +156,10 @@ namespace NadekoBot.Classes.Permissions { /// Holds a permission list /// public class Permissions { + /// + /// Name of the parent object whose permissions these are + /// + public string ParentName { get; set; } /// /// Module name with allowed/disallowed /// @@ -165,13 +169,22 @@ namespace NadekoBot.Classes.Permissions { /// public Dictionary commands { get; set; } - public Permissions() { + public Permissions(string name) { + ParentName = name; modules = new Dictionary(); commands = new Dictionary(); } } - public class PermissionsContainer { + public class ServerPermissions { + /// + /// The guy who can edit the permissions + /// + public string PermissionsControllerRoleName { get; set; } + /// + /// Does it print the error when a restriction occurs + /// + public bool Verbose { get; set; } /// /// The id of the thing (user/server/channel) /// @@ -181,29 +194,16 @@ namespace NadekoBot.Classes.Permissions { /// public Permissions Permissions { get; set; } - public PermissionsContainer(string id) { - Id = id; - Permissions = new Permissions(); - } - } - - public class ServerPermissions : PermissionsContainer { - /// - /// The guy who can edit the permissions - /// - public string PermissionsControllerRoleName { get; set; } - /// - /// Does it print the error when a restriction occurs - /// - public bool Verbose { get; set; } - public Dictionary UserPermissions { get; set; } public Dictionary ChannelPermissions { get; set; } public Dictionary RolePermissions { get; set; } - public ServerPermissions(string id) : base(id) { + public ServerPermissions(string id, string name) { + Id = id; PermissionsControllerRoleName = "PermissionsKing"; Verbose = true; + + Permissions = new Permissions(name); UserPermissions = new Dictionary(); ChannelPermissions = new Dictionary(); RolePermissions = new Dictionary();