permission stuff started

This commit is contained in:
Master Kwoth 2016-02-11 02:14:05 +01:00
parent 5977bcd2b6
commit 358d8a86a1
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,64 @@
using Discord;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Classes {
public class PermissionsHandler {
public static ConcurrentDictionary<Server, ServerPermissions> _permissionsDict =
new ConcurrentDictionary<Server, ServerPermissions>();
public static void WriteToJson() {
Directory.CreateDirectory("data/permissions/");
foreach (var kvp in _permissionsDict) {
string pathToFile = $"data/permissions/{kvp.Key.Id}.json";
File.WriteAllText(pathToFile, Newtonsoft.Json.JsonConvert.SerializeObject(_permissionsDict[kvp.Key],Newtonsoft.Json.Formatting.Indented));
}
}
}
/// <summary>
/// Holds a permission list
/// </summary>
public class Permissions {
/// <summary>
/// Module name with allowed/disallowed
/// </summary>
public Dictionary<string, bool> modules { get; set; }
/// <summary>
/// Command name with allowed/disallowed
/// </summary>
public Dictionary<string, bool> commands { get; set; }
}
public class PermissionsContainer {
/// <summary>
/// The id of the thing (user/server/channel)
/// </summary>
public string Id { get; set; } //a string because of the role name.
/// <summary>
/// Permission object bound to the id of something/role name
/// </summary>
public Permissions Permissions { get; set; }
public PermissionsContainer() { }
}
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 List<PermissionsContainer> UserPermissions { get; set; }
public List<PermissionsContainer> ChannelPermissions { get; set; }
public List<PermissionsContainer> RolePermissions { get; set; }
}
}

View File

@ -134,6 +134,7 @@
<Compile Include="Classes\Music\SoundCloud.cs" /> <Compile Include="Classes\Music\SoundCloud.cs" />
<Compile Include="Classes\PermissionCheckers\NSWFPermissionChecker.cs" /> <Compile Include="Classes\PermissionCheckers\NSWFPermissionChecker.cs" />
<Compile Include="Classes\PermissionCheckers\PermissionChecker.cs" /> <Compile Include="Classes\PermissionCheckers\PermissionChecker.cs" />
<Compile Include="Classes\PermissionsHandler.cs" />
<Compile Include="Classes\SearchHelper.cs" /> <Compile Include="Classes\SearchHelper.cs" />
<Compile Include="Classes\_DataModels\AnnouncementModel.cs" /> <Compile Include="Classes\_DataModels\AnnouncementModel.cs" />
<Compile Include="Classes\_DataModels\CommandModel.cs" /> <Compile Include="Classes\_DataModels\CommandModel.cs" />