fixes and improvements for a more readable json
This commit is contained in:
parent
e0fb86a43e
commit
8d4d7252ec
@ -28,7 +28,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
|
|
||||||
public static void SetServerModulePermission(Server server, string moduleName, bool value) {
|
public static void SetServerModulePermission(Server server, string moduleName, bool value) {
|
||||||
if (!_permissionsDict.ContainsKey(server)) {
|
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;
|
var modules = _permissionsDict[server].Permissions.modules;
|
||||||
if (modules.ContainsKey(moduleName))
|
if (modules.ContainsKey(moduleName))
|
||||||
@ -40,7 +40,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
|
|
||||||
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
|
public static void SetServerCommandPermission(Server server, string commandName, bool value) {
|
||||||
if (!_permissionsDict.ContainsKey(server)) {
|
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;
|
var commands = _permissionsDict[server].Permissions.commands;
|
||||||
if (commands.ContainsKey(commandName))
|
if (commands.ContainsKey(commandName))
|
||||||
@ -53,10 +53,10 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
|
public static void SetChannelModulePermission(Channel channel, string moduleName, bool value) {
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
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) {
|
public static void SetChannelCommandPermission(Channel channel, string commandName, bool value) {
|
||||||
var server = channel.Server;
|
var server = channel.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
var commands = _permissionsDict[server].ChannelPermissions[channel.Id.ToString()].commands;
|
||||||
|
|
||||||
@ -84,71 +84,71 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
WriteServerToJson(server);
|
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;
|
var server = role.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
var modules = _permissionsDict[server].RolePermissions[role.Id.ToString()].modules;
|
||||||
|
|
||||||
if (modules.ContainsKey(roleName))
|
if (modules.ContainsKey(moduleName))
|
||||||
modules[roleName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(roleName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
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;
|
var server = role.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
var commands = _permissionsDict[server].RolePermissions[role.Id.ToString()].commands;
|
||||||
|
|
||||||
if (commands.ContainsKey(roleName))
|
if (commands.ContainsKey(commandName))
|
||||||
commands[roleName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(roleName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
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;
|
var server = user.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
var modules = _permissionsDict[server].UserPermissions[user.Id.ToString()].modules;
|
||||||
|
|
||||||
if (modules.ContainsKey(userName))
|
if (modules.ContainsKey(moduleName))
|
||||||
modules[userName] = value;
|
modules[moduleName] = value;
|
||||||
else
|
else
|
||||||
modules.Add(userName, value);
|
modules.Add(moduleName, value);
|
||||||
WriteServerToJson(server);
|
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;
|
var server = user.Server;
|
||||||
if (!_permissionsDict.ContainsKey(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()))
|
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;
|
var commands = _permissionsDict[server].UserPermissions[user.Id.ToString()].commands;
|
||||||
|
|
||||||
if (commands.ContainsKey(userName))
|
if (commands.ContainsKey(commandName))
|
||||||
commands[userName] = value;
|
commands[commandName] = value;
|
||||||
else
|
else
|
||||||
commands.Add(userName, value);
|
commands.Add(commandName, value);
|
||||||
WriteServerToJson(server);
|
WriteServerToJson(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,6 +156,10 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
/// Holds a permission list
|
/// Holds a permission list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the parent object whose permissions these are
|
||||||
|
/// </summary>
|
||||||
|
public string ParentName { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Module name with allowed/disallowed
|
/// Module name with allowed/disallowed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -165,13 +169,22 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, bool> commands { get; set; }
|
public Dictionary<string, bool> commands { get; set; }
|
||||||
|
|
||||||
public Permissions() {
|
public Permissions(string name) {
|
||||||
|
ParentName = name;
|
||||||
modules = new Dictionary<string, bool>();
|
modules = new Dictionary<string, bool>();
|
||||||
commands = new Dictionary<string, bool>();
|
commands = new Dictionary<string, bool>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PermissionsContainer {
|
public class ServerPermissions {
|
||||||
|
/// <summary>
|
||||||
|
/// The guy who can edit the permissions
|
||||||
|
/// </summary>
|
||||||
|
public string PermissionsControllerRoleName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Does it print the error when a restriction occurs
|
||||||
|
/// </summary>
|
||||||
|
public bool Verbose { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The id of the thing (user/server/channel)
|
/// The id of the thing (user/server/channel)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -181,29 +194,16 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Permissions Permissions { get; set; }
|
public Permissions Permissions { get; set; }
|
||||||
|
|
||||||
public PermissionsContainer(string id) {
|
|
||||||
Id = id;
|
|
||||||
Permissions = new Permissions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ServerPermissions : PermissionsContainer {
|
|
||||||
/// <summary>
|
|
||||||
/// The guy who can edit the permissions
|
|
||||||
/// </summary>
|
|
||||||
public string PermissionsControllerRoleName { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Does it print the error when a restriction occurs
|
|
||||||
/// </summary>
|
|
||||||
public bool Verbose { get; set; }
|
|
||||||
|
|
||||||
public Dictionary<string, Permissions> UserPermissions { get; set; }
|
public Dictionary<string, Permissions> UserPermissions { get; set; }
|
||||||
public Dictionary<string, Permissions> ChannelPermissions { get; set; }
|
public Dictionary<string, Permissions> ChannelPermissions { get; set; }
|
||||||
public Dictionary<string, Permissions> RolePermissions { get; set; }
|
public Dictionary<string, Permissions> RolePermissions { get; set; }
|
||||||
|
|
||||||
public ServerPermissions(string id) : base(id) {
|
public ServerPermissions(string id, string name) {
|
||||||
|
Id = id;
|
||||||
PermissionsControllerRoleName = "PermissionsKing";
|
PermissionsControllerRoleName = "PermissionsKing";
|
||||||
Verbose = true;
|
Verbose = true;
|
||||||
|
|
||||||
|
Permissions = new Permissions(name);
|
||||||
UserPermissions = new Dictionary<string, Permissions>();
|
UserPermissions = new Dictionary<string, Permissions>();
|
||||||
ChannelPermissions = new Dictionary<string, Permissions>();
|
ChannelPermissions = new Dictionary<string, Permissions>();
|
||||||
RolePermissions = new Dictionary<string, Permissions>();
|
RolePermissions = new Dictionary<string, Permissions>();
|
||||||
|
Loading…
Reference in New Issue
Block a user