Add Parent property to ModuleInfo
This commit is contained in:
@@ -14,8 +14,7 @@ namespace Discord.Commands.Builders
|
|||||||
public CommandService Service { get; }
|
public CommandService Service { get; }
|
||||||
public ModuleBuilder Parent { get; }
|
public ModuleBuilder Parent { get; }
|
||||||
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 IReadOnlyList<CommandBuilder> Commands => _commands;
|
public IReadOnlyList<CommandBuilder> Commands => _commands;
|
||||||
public IReadOnlyList<ModuleBuilder> Modules => _submodules;
|
public IReadOnlyList<ModuleBuilder> Modules => _submodules;
|
||||||
@@ -97,13 +96,17 @@ namespace Discord.Commands.Builders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModuleInfo Build(CommandService service)
|
private ModuleInfo BuildImpl(CommandService service, ModuleInfo parent = null)
|
||||||
{
|
{
|
||||||
//Default name to first alias
|
//Default name to first alias
|
||||||
if (Name == null)
|
if (Name == null)
|
||||||
Name = _aliases[0];
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
@@ -17,14 +18,17 @@ namespace Discord.Commands
|
|||||||
public IEnumerable<CommandInfo> Commands { get; }
|
public IEnumerable<CommandInfo> Commands { get; }
|
||||||
public IReadOnlyList<PreconditionAttribute> Preconditions { get; }
|
public IReadOnlyList<PreconditionAttribute> Preconditions { get; }
|
||||||
public IReadOnlyList<ModuleInfo> Submodules { 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;
|
Service = service;
|
||||||
|
|
||||||
Name = builder.Name;
|
Name = builder.Name;
|
||||||
Summary = builder.Summary;
|
Summary = builder.Summary;
|
||||||
Remarks = builder.Remarks;
|
Remarks = builder.Remarks;
|
||||||
|
Parent = parent;
|
||||||
|
|
||||||
Aliases = BuildAliases(builder).ToImmutableArray();
|
Aliases = BuildAliases(builder).ToImmutableArray();
|
||||||
Commands = builder.Commands.Select(x => x.Build(this, service));
|
Commands = builder.Commands.Select(x => x.Build(this, service));
|
||||||
@@ -67,13 +71,13 @@ namespace Discord.Commands
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service)
|
private List<ModuleInfo> BuildSubmodules(ModuleBuilder parent, CommandService service)
|
||||||
{
|
{
|
||||||
var result = new List<ModuleInfo>();
|
var result = new List<ModuleInfo>();
|
||||||
|
|
||||||
foreach (var submodule in parent.Modules)
|
foreach (var submodule in parent.Modules)
|
||||||
{
|
{
|
||||||
result.Add(submodule.Build(service));
|
result.Add(submodule.Build(service, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -93,4 +97,4 @@ namespace Discord.Commands
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user