Default DependencyMap to an empty map when not supplied

This commit is contained in:
RogueException
2016-10-20 03:53:46 -03:00
parent 2cbfaa5498
commit b8102a6767
3 changed files with 10 additions and 0 deletions

View File

@@ -87,6 +87,9 @@ namespace Discord.Commands
public async Task<PreconditionResult> CheckPreconditions(CommandContext context, IDependencyMap map = null)
{
if (map == null)
map = DependencyMap.Empty;
foreach (PreconditionAttribute precondition in Module.Preconditions)
{
var result = await precondition.CheckPermissions(context, this, map).ConfigureAwait(false);
@@ -150,6 +153,9 @@ namespace Discord.Commands
}
public async Task<ExecuteResult> Execute(CommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IDependencyMap map)
{
if (map == null)
map = DependencyMap.Empty;
try
{
var args = GenerateArgs(argList, paramList);

View File

@@ -195,6 +195,8 @@ namespace Discord.Commands
=> Execute(context, context.Message.Content.Substring(argPos), dependencyMap, multiMatchHandling);
public async Task<IResult> Execute(CommandContext context, string input, IDependencyMap dependencyMap = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
{
dependencyMap = dependencyMap ?? DependencyMap.Empty;
var searchResult = Search(context, input);
if (!searchResult.IsSuccess)
return searchResult;

View File

@@ -7,6 +7,8 @@ namespace Discord.Commands
{
private Dictionary<Type, object> map;
public static DependencyMap Empty => new DependencyMap();
public DependencyMap()
{
map = new Dictionary<Type, object>();