Added Module.CreateCommands, exposed a few properties and added module names.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Discord.Commands;
|
||||||
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -43,21 +44,29 @@ namespace Discord.Modules
|
|||||||
public event EventHandler<MessageEventArgs> MessageReadRemotely;
|
public event EventHandler<MessageEventArgs> MessageReadRemotely;
|
||||||
|
|
||||||
private readonly DiscordClient _client;
|
private readonly DiscordClient _client;
|
||||||
|
private readonly string _name, _id;
|
||||||
|
private readonly FilterType _filterType;
|
||||||
private readonly bool _allowServerWhitelist, _allowChannelWhitelist, _allowPrivate;
|
private readonly bool _allowServerWhitelist, _allowChannelWhitelist, _allowPrivate;
|
||||||
private readonly ConcurrentDictionary<string, Server> _enabledServers;
|
private readonly ConcurrentDictionary<string, Server> _enabledServers;
|
||||||
private readonly ConcurrentDictionary<string, Channel> _enabledChannels;
|
private readonly ConcurrentDictionary<string, Channel> _enabledChannels;
|
||||||
private readonly ConcurrentDictionary<string, int> _indirectServers;
|
private readonly ConcurrentDictionary<string, int> _indirectServers;
|
||||||
|
|
||||||
public DiscordClient Client => _client;
|
public DiscordClient Client => _client;
|
||||||
|
public string Name => _name;
|
||||||
|
public string Id => _id;
|
||||||
|
public FilterType FilterType => _filterType;
|
||||||
public IEnumerable<Server> EnabledServers => _enabledServers.Select(x => x.Value);
|
public IEnumerable<Server> EnabledServers => _enabledServers.Select(x => x.Value);
|
||||||
public IEnumerable<Channel> EnabledChannels => _enabledChannels.Select(x => x.Value);
|
public IEnumerable<Channel> EnabledChannels => _enabledChannels.Select(x => x.Value);
|
||||||
|
|
||||||
internal ModuleManager(DiscordClient client, FilterType type)
|
internal ModuleManager(DiscordClient client, string name, FilterType filterType)
|
||||||
{
|
{
|
||||||
_client = client;
|
_client = client;
|
||||||
_allowServerWhitelist = type.HasFlag(FilterType.Server);
|
_name = name;
|
||||||
_allowChannelWhitelist = type.HasFlag(FilterType.Channel);
|
_id = name.ToLowerInvariant();
|
||||||
_allowPrivate = type.HasFlag(FilterType.AllowPrivate);
|
_filterType = filterType;
|
||||||
|
_allowServerWhitelist = filterType.HasFlag(FilterType.Server);
|
||||||
|
_allowChannelWhitelist = filterType.HasFlag(FilterType.Channel);
|
||||||
|
_allowPrivate = filterType.HasFlag(FilterType.AllowPrivate);
|
||||||
|
|
||||||
_enabledServers = new ConcurrentDictionary<string, Server>();
|
_enabledServers = new ConcurrentDictionary<string, Server>();
|
||||||
_enabledChannels = new ConcurrentDictionary<string, Channel>();
|
_enabledChannels = new ConcurrentDictionary<string, Channel>();
|
||||||
@@ -98,6 +107,18 @@ namespace Discord.Modules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CreateCommands(string prefix, Action<CommandGroupBuilder> config)
|
||||||
|
{
|
||||||
|
var commandService = _client.Commands();
|
||||||
|
if (commandService == null)
|
||||||
|
throw new InvalidOperationException($"{nameof(CommandService)} must be added to DiscordClient before this property is accessed.");
|
||||||
|
commandService.CreateGroup(prefix, x =>
|
||||||
|
{
|
||||||
|
x.Category(_name);
|
||||||
|
config(x);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
public bool EnableServer(Server server)
|
public bool EnableServer(Server server)
|
||||||
{
|
{
|
||||||
if (server == null) throw new ArgumentNullException(nameof(server));
|
if (server == null) throw new ArgumentNullException(nameof(server));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Discord.Modules
|
|||||||
private DiscordClient _client;
|
private DiscordClient _client;
|
||||||
|
|
||||||
//ModuleServiceConfig Config { get; }
|
//ModuleServiceConfig Config { get; }
|
||||||
public IEnumerable<IModule> Modules => _modules.Keys;
|
public IEnumerable<ModuleManager> Modules => _modules.Values;
|
||||||
private readonly Dictionary<IModule, ModuleManager> _modules;
|
private readonly Dictionary<IModule, ModuleManager> _modules;
|
||||||
|
|
||||||
public ModuleService(/*ModuleServiceConfig config*/)
|
public ModuleService(/*ModuleServiceConfig config*/)
|
||||||
@@ -22,12 +22,12 @@ namespace Discord.Modules
|
|||||||
_client = client;
|
_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Install(IModule module, FilterType type)
|
public void Install(IModule module, string name, FilterType type)
|
||||||
{
|
{
|
||||||
if (_client == null) throw new InvalidOperationException("Service needs to be added to a DiscordClient before modules can be installed.");
|
if (_client == null) throw new InvalidOperationException("Service needs to be added to a DiscordClient before modules can be installed.");
|
||||||
if (_modules.ContainsKey(module)) throw new InvalidOperationException("This module has already been added.");
|
if (_modules.ContainsKey(module)) throw new InvalidOperationException("This module has already been added.");
|
||||||
|
|
||||||
var manager = new ModuleManager(_client, type);
|
var manager = new ModuleManager(_client, name, type);
|
||||||
_modules.Add(module, manager);
|
_modules.Add(module, manager);
|
||||||
module.Install(manager);
|
module.Install(manager);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user