Browse Source

Include the ModuleBuilder in OnModuleBuilding

This allows modules hooking into OnModuleBuilding method to mutate
theirselves at runtime.
pull/946/head
Christopher F 7 years ago
parent
commit
60c7c31d44
3 changed files with 7 additions and 7 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Builders/ModuleBuilder.cs
  2. +3
    -1
      src/Discord.Net.Commands/IModuleBase.cs
  3. +3
    -5
      src/Discord.Net.Commands/ModuleBase.cs

+ 1
- 1
src/Discord.Net.Commands/Builders/ModuleBuilder.cs View File

@@ -126,7 +126,7 @@ namespace Discord.Commands.Builders
try
{
var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, services);
moduleInstance.OnModuleBuilding(service);
moduleInstance.OnModuleBuilding(service, this);
}
catch (Exception)
{


+ 3
- 1
src/Discord.Net.Commands/IModuleBase.cs View File

@@ -1,3 +1,5 @@
using Discord.Commands.Builders;

namespace Discord.Commands
{
internal interface IModuleBase
@@ -8,6 +10,6 @@ namespace Discord.Commands
void AfterExecute(CommandInfo command);

void OnModuleBuilding(CommandService commandService);
void OnModuleBuilding(CommandService commandService, ModuleBuilder builder);
}
}

+ 3
- 5
src/Discord.Net.Commands/ModuleBase.cs View File

@@ -1,3 +1,4 @@
using Discord.Commands.Builders;
using System;
using System.Threading.Tasks;

@@ -23,7 +24,7 @@ namespace Discord.Commands
{
}

protected virtual void OnModuleBuilding(CommandService commandService)
protected virtual void OnModuleBuilding(CommandService commandService, ModuleBuilder builder)
{
}

@@ -33,11 +34,8 @@ namespace Discord.Commands
var newValue = context as T;
Context = newValue ?? throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}");
}

void IModuleBase.BeforeExecute(CommandInfo command) => BeforeExecute(command);

void IModuleBase.AfterExecute(CommandInfo command) => AfterExecute(command);

void IModuleBase.OnModuleBuilding(CommandService commandService) => OnModuleBuilding(commandService);
void IModuleBase.OnModuleBuilding(CommandService commandService, ModuleBuilder builder) => OnModuleBuilding(commandService, builder);
}
}

Loading…
Cancel
Save