Browse Source

Remove superfluous comments, provide simpler alternative for setting the ServiceProvider.

pull/934/head
Joe4evr 7 years ago
parent
commit
72b5e6c8a1
4 changed files with 10 additions and 22 deletions
  1. +3
    -1
      docs/guides/getting_started/samples/intro/structure.cs
  2. +0
    -2
      src/Discord.Net.Commands/Builders/ModuleBuilder.cs
  3. +4
    -18
      src/Discord.Net.Commands/CommandService.cs
  4. +3
    -1
      src/Discord.Net.Commands/CommandServiceConfig.cs

+ 3
- 1
docs/guides/getting_started/samples/intro/structure.cs View File

@@ -164,7 +164,9 @@ class Program
var result = await _commands.ExecuteAsync(context, pos);

// Uncomment the following lines if you want the bot
// to send a message if it failed (not advised for most situations).
// to send a message if it failed.
// This does not catch errors from commands with 'RunMode.Async',
// subscribe a handler for '_commands.CommandExecuted' to see those.
//if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
// await msg.Channel.SendMessageAsync(result.ErrorReason);
}


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

@@ -122,8 +122,6 @@ namespace Discord.Commands.Builders

if (TypeInfo != null)
{
//keep this for safety?
//services = services ?? EmptyServiceProvider.Instance;
try
{
var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, service._serviceProvider);


+ 4
- 18
src/Discord.Net.Commands/CommandService.cs View File

@@ -43,7 +43,10 @@ namespace Discord.Commands
public CommandService() : this(new CommandServiceConfig()) { }
public CommandService(CommandServiceConfig config)
{
_serviceProvider = config.ServiceProvider ?? EmptyServiceProvider.Instance;
_serviceProvider = config.ServiceProvider
?? config.ServiceProviderFactory?.Invoke(this)
?? EmptyServiceProvider.Instance;

_caseSensitive = config.CaseSensitiveCommands;
_throwOnError = config.ThrowOnError;
_ignoreExtraArgs = config.IgnoreExtraArgs;
@@ -91,7 +94,6 @@ namespace Discord.Commands

var module = builder.Build(this, null);

//should be fine to pass null here since it'll never get checked from this path anyway
return LoadModuleInternal(module);
}
finally
@@ -149,22 +151,6 @@ namespace Discord.Commands
{
_moduleDefs.Add(module);

//if (module.TypeInfo.IsSpecified)
//{
// //keep this for safety?
// services = services ?? EmptyServiceProvider.Instance;
// try
// {
// var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(module.TypeInfo.Value, this, services);
// moduleInstance.OnModuleBuilding(this);
// }
// catch(Exception)
// {
// //unsure of what to do here
// throw;
// }
//}

foreach (var command in module.Commands)
_map.AddCommand(command);



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

@@ -21,6 +21,8 @@ namespace Discord.Commands
/// <summary> Determines whether extra parameters should be ignored. </summary>
public bool IgnoreExtraArgs { get; set; } = false;

public IServiceProvider ServiceProvider { get; set; } = EmptyServiceProvider.Instance;
public IServiceProvider ServiceProvider { get; set; }

public Func<CommandService, IServiceProvider> ServiceProviderFactory { get; set; }
}
}

Loading…
Cancel
Save