Merge pull request #377 from RogueException/issue/368

Add CommandServiceConfig, DefaultRunMode
This commit is contained in:
RogueException
2016-11-25 23:24:48 -04:00
committed by GitHub
5 changed files with 16 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ namespace Discord.Commands
public class CommandAttribute : Attribute
{
public string Text { get; }
public RunMode RunMode { get; set; } = RunMode.Sync;
public RunMode RunMode { get; set; }
public CommandAttribute()
{

View File

@@ -17,7 +17,7 @@ namespace Discord.Commands.Builders
public string Name { get; set; }
public string Summary { get; set; }
public string Remarks { get; set; }
public RunMode RunMode { get; set; }
public RunMode? RunMode { get; set; }
public int Priority { get; set; }
public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions;

View File

@@ -19,10 +19,13 @@ namespace Discord.Commands
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
private readonly CommandMap _map;
internal readonly RunMode _defaultRunMode;
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value);
public IEnumerable<CommandInfo> Commands => _typedModuleDefs.SelectMany(x => x.Value.Commands);
public CommandService()
public CommandService() : this(new CommandServiceConfig()) { }
public CommandService(CommandServiceConfig config)
{
_moduleLock = new SemaphoreSlim(1, 1);
_typedModuleDefs = new ConcurrentDictionary<Type, ModuleInfo>();
@@ -64,6 +67,7 @@ namespace Discord.Commands
[typeof(IGroupUser)] = new UserTypeReader<IGroupUser>(),
[typeof(IGuildUser)] = new UserTypeReader<IGuildUser>(),
};
_defaultRunMode = config.DefaultRunMode;
}
//Modules

View File

@@ -0,0 +1,8 @@
namespace Discord.Commands
{
public class CommandServiceConfig
{
/// <summary> The default RunMode commands should have, if one is not specified on the Command attribute or builder. </summary>
public RunMode DefaultRunMode { get; set; } = RunMode.Mixed;
}
}

View File

@@ -37,7 +37,7 @@ namespace Discord.Commands
Summary = builder.Summary;
Remarks = builder.Remarks;
RunMode = builder.RunMode;
RunMode = builder.RunMode ?? service._defaultRunMode;
Priority = builder.Priority;
if (module.Aliases.Count != 0)