Added new permissions system, fixed more commands and module bugs.

This commit is contained in:
RogueException
2015-11-09 00:55:17 -04:00
parent 7cd1119ab7
commit 093095e410
23 changed files with 443 additions and 100 deletions

View File

@@ -7,7 +7,7 @@
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>01584e8a-78da-486f-9ef9-a894e435841b</ProjectGuid>
<RootNamespace>Discord</RootNamespace>
<RootNamespace>Discord.Modules</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

View File

@@ -0,0 +1,20 @@
using Discord.Commands;
using Discord.Commands.Permissions;
namespace Discord.Modules
{
public class ModuleChecker : IPermissionChecker
{
private readonly ModuleManager _manager;
internal ModuleChecker(ModuleManager manager)
{
_manager = manager;
}
public bool CanRun(Command command, User user, Channel channel)
{
return _manager.FilterType.HasFlag(FilterType.Unrestricted) || _manager.HasChannel(channel);
}
}
}

View File

@@ -64,8 +64,8 @@ namespace Discord.Modules
_name = name;
_id = name.ToLowerInvariant();
_filterType = filterType;
_allowServerWhitelist = filterType.HasFlag(FilterType.Server);
_allowChannelWhitelist = filterType.HasFlag(FilterType.Channel);
_allowServerWhitelist = filterType.HasFlag(FilterType.ServerWhitelist);
_allowChannelWhitelist = filterType.HasFlag(FilterType.ChannelWhitelist);
_allowPrivate = filterType.HasFlag(FilterType.AllowPrivate);
_enabledServers = new ConcurrentDictionary<string, Server>();
@@ -115,6 +115,7 @@ namespace Discord.Modules
commandService.CreateGroup(prefix, x =>
{
x.Category(_name);
x.AddCheck(new ModuleChecker(this));
config(x);
});
@@ -244,12 +245,12 @@ namespace Discord.Modules
DisableAllChannels();
}
private bool HasServer(Server server) =>
internal bool HasServer(Server server) =>
_allowServerWhitelist && _enabledServers.ContainsKey(server.Id);
private bool HasIndirectServer(Server server) =>
internal bool HasIndirectServer(Server server) =>
(_allowServerWhitelist && _enabledServers.ContainsKey(server.Id)) ||
(_allowChannelWhitelist && _indirectServers.ContainsKey(server.Id));
private bool HasChannel(Channel channel)
internal bool HasChannel(Channel channel)
{
if (channel.IsPrivate) return _allowPrivate;

View File

@@ -5,12 +5,12 @@ namespace Discord.Modules
[Flags]
public enum FilterType
{
/// <summary> Disables the event filter. </summary>
Disabled = 0x0,
/// <summary> Uses the server whitelist to filter events. </summary>
Server = 0x1,
/// <summary> Uses the channel whitelist to filter events. </summary>
Channel = 0x2,
/// <summary> Disables the event and command filtesr. </summary>
Unrestricted = 0x0,
/// <summary> Uses the server whitelist to filter events and commands. </summary>
ServerWhitelist = 0x1,
/// <summary> Uses the channel whitelist to filter events and commands. </summary>
ChannelWhitelist = 0x2,
/// <summary> Enables this module in all private messages. </summary>
AllowPrivate = 0x4
}