Browse Source

Allow GetExecutableCommandsAsync(ModuleInfo) to recurse properly to all submodules.

pull/1037/head
Alex Gravely 7 years ago
parent
commit
c9039d1524
2 changed files with 15 additions and 4 deletions
  1. +3
    -0
      src/Discord.Net.Commands/Discord.Net.Commands.csproj
  2. +12
    -4
      src/Discord.Net.Commands/Extensions/CommandServiceExtensions.cs

+ 3
- 0
src/Discord.Net.Commands/Discord.Net.Commands.csproj View File

@@ -6,6 +6,9 @@
<Description>A Discord.Net extension adding support for bot commands.</Description>
<TargetFrameworks>netstandard1.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.1|AnyCPU'">
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" />
</ItemGroup>


+ 12
- 4
src/Discord.Net.Commands/Extensions/CommandServiceExtensions.cs View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Discord.Commands
@@ -10,7 +9,7 @@ namespace Discord.Commands
public static async Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this IEnumerable<CommandInfo> commands, ICommandContext context, IServiceProvider provider)
{
var executableCommands = new List<CommandInfo>();
foreach (var command in commands)
{
var result = await command.CheckPreconditionsAsync(context, provider).ConfigureAwait(false);
@@ -22,7 +21,16 @@ namespace Discord.Commands
}
public static Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this CommandService commandService, ICommandContext context, IServiceProvider provider)
=> GetExecutableCommandsAsync(commandService.Commands, context, provider);
public static Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandAsync(this ModuleInfo module, ICommandContext context, IServiceProvider provider)
=> GetExecutableCommandsAsync(module.Commands.Concat(module.Submodules.SelectMany(sm => sm.Commands)), context, provider);
public static async Task<IReadOnlyCollection<CommandInfo>> GetExecutableCommandsAsync(this ModuleInfo module, ICommandContext context, IServiceProvider provider)
{
var executableCommands = new List<CommandInfo>();

executableCommands.AddRange(await module.Commands.GetExecutableCommandsAsync(context, provider).ConfigureAwait(false));

foreach (var subModule in module.Submodules)
executableCommands.AddRange(await subModule.GetExecutableCommandsAsync(context, provider).ConfigureAwait(false));
return executableCommands;
}
}
}

Loading…
Cancel
Save