Add Parent property to ModuleInfo

This commit is contained in:
james7132
2016-11-27 01:28:11 -08:00
parent aceac76d1d
commit 0771fcce63
2 changed files with 15 additions and 8 deletions

View File

@@ -14,8 +14,7 @@ namespace Discord.Commands.Builders
public CommandService Service { get; }
public ModuleBuilder Parent { get; }
public string Name { get; set; }
public string Summary { get; set; }
public string Remarks { get; set; }
public string Summary { get; set; } public string Remarks { get; set; }
public IReadOnlyList<CommandBuilder> Commands => _commands;
public IReadOnlyList<ModuleBuilder> Modules => _submodules;
@@ -97,13 +96,17 @@ namespace Discord.Commands.Builders
return this;
}
public ModuleInfo Build(CommandService service)
private ModuleInfo BuildImpl(CommandService service, ModuleInfo parent = null)
{
//Default name to first alias
if (Name == null)
Name = _aliases[0];
return new ModuleInfo(this, service);
return new ModuleInfo(this, service, parent);
}
public ModuleInfo Build(CommandService service) => BuildImpl(service);
internal ModuleInfo Build(CommandService service, ModuleInfo parent) => BuildImpl(service, parent);
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -17,14 +18,17 @@ namespace Discord.Commands
public IEnumerable<CommandInfo> Commands { get; }
public IReadOnlyList<PreconditionAttribute> Preconditions { get; }
public IReadOnlyList<ModuleInfo> Submodules { get; }
public ModuleInfo Parent { get; }
public bool IsSubmodule => Parent == null;
internal ModuleInfo(ModuleBuilder builder, CommandService service)
internal ModuleInfo(ModuleBuilder builder, CommandService service, ModuleInfo parent = null)
{
Service = service;
Name = builder.Name;
Summary = builder.Summary;
Remarks = builder.Remarks;
Parent = parent;
Aliases = BuildAliases(builder).ToImmutableArray();
Commands = builder.Commands.Select(x => x.Build(this, service));
@@ -67,13 +71,13 @@ namespace Discord.Commands
return result;
}
private static List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service)
private List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service)
{
var result = new List<ModuleInfo>();
foreach (var submodule in parent.Modules)
{
result.Add(submodule.Build(service));
result.Add(submodule.Build(service, this));
}
return result;
@@ -93,4 +97,4 @@ namespace Discord.Commands
return result;
}
}
}
}