Merge pull request #377 from RogueException/issue/368
Add CommandServiceConfig, DefaultRunMode
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Discord.Commands
|
|||||||
public class CommandAttribute : Attribute
|
public class CommandAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
public RunMode RunMode { get; set; } = RunMode.Sync;
|
public RunMode RunMode { get; set; }
|
||||||
|
|
||||||
public CommandAttribute()
|
public CommandAttribute()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Discord.Commands.Builders
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Summary { get; set; }
|
public string Summary { get; set; }
|
||||||
public string Remarks { get; set; }
|
public string Remarks { get; set; }
|
||||||
public RunMode RunMode { get; set; }
|
public RunMode? RunMode { get; set; }
|
||||||
public int Priority { get; set; }
|
public int Priority { get; set; }
|
||||||
|
|
||||||
public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions;
|
public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions;
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ namespace Discord.Commands
|
|||||||
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
private readonly ConcurrentBag<ModuleInfo> _moduleDefs;
|
||||||
private readonly CommandMap _map;
|
private readonly CommandMap _map;
|
||||||
|
|
||||||
|
internal readonly RunMode _defaultRunMode;
|
||||||
|
|
||||||
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value);
|
public IEnumerable<ModuleInfo> Modules => _typedModuleDefs.Select(x => x.Value);
|
||||||
public IEnumerable<CommandInfo> Commands => _typedModuleDefs.SelectMany(x => x.Value.Commands);
|
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);
|
_moduleLock = new SemaphoreSlim(1, 1);
|
||||||
_typedModuleDefs = new ConcurrentDictionary<Type, ModuleInfo>();
|
_typedModuleDefs = new ConcurrentDictionary<Type, ModuleInfo>();
|
||||||
@@ -64,6 +67,7 @@ namespace Discord.Commands
|
|||||||
[typeof(IGroupUser)] = new UserTypeReader<IGroupUser>(),
|
[typeof(IGroupUser)] = new UserTypeReader<IGroupUser>(),
|
||||||
[typeof(IGuildUser)] = new UserTypeReader<IGuildUser>(),
|
[typeof(IGuildUser)] = new UserTypeReader<IGuildUser>(),
|
||||||
};
|
};
|
||||||
|
_defaultRunMode = config.DefaultRunMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Modules
|
//Modules
|
||||||
|
|||||||
8
src/Discord.Net.Commands/CommandServiceConfig.cs
Normal file
8
src/Discord.Net.Commands/CommandServiceConfig.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ namespace Discord.Commands
|
|||||||
Summary = builder.Summary;
|
Summary = builder.Summary;
|
||||||
Remarks = builder.Remarks;
|
Remarks = builder.Remarks;
|
||||||
|
|
||||||
RunMode = builder.RunMode;
|
RunMode = builder.RunMode ?? service._defaultRunMode;
|
||||||
Priority = builder.Priority;
|
Priority = builder.Priority;
|
||||||
|
|
||||||
if (module.Aliases.Count != 0)
|
if (module.Aliases.Count != 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user