Added new permissions system, fixed more commands and module bugs.
This commit is contained in:
@@ -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>
|
||||
|
||||
20
src/Discord.Net.Modules/ModuleChecker.cs
Normal file
20
src/Discord.Net.Modules/ModuleChecker.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user