@@ -164,7 +164,9 @@ class Program | |||||
var result = await _commands.ExecuteAsync(context, pos); | var result = await _commands.ExecuteAsync(context, pos); | ||||
// Uncomment the following lines if you want the bot | // 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) | //if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) | ||||
// await msg.Channel.SendMessageAsync(result.ErrorReason); | // await msg.Channel.SendMessageAsync(result.ErrorReason); | ||||
} | } | ||||
@@ -122,8 +122,6 @@ namespace Discord.Commands.Builders | |||||
if (TypeInfo != null) | if (TypeInfo != null) | ||||
{ | { | ||||
//keep this for safety? | |||||
//services = services ?? EmptyServiceProvider.Instance; | |||||
try | try | ||||
{ | { | ||||
var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, service._serviceProvider); | var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, service._serviceProvider); | ||||
@@ -43,7 +43,10 @@ namespace Discord.Commands | |||||
public CommandService() : this(new CommandServiceConfig()) { } | public CommandService() : this(new CommandServiceConfig()) { } | ||||
public CommandService(CommandServiceConfig config) | public CommandService(CommandServiceConfig config) | ||||
{ | { | ||||
_serviceProvider = config.ServiceProvider ?? EmptyServiceProvider.Instance; | |||||
_serviceProvider = config.ServiceProvider | |||||
?? config.ServiceProviderFactory?.Invoke(this) | |||||
?? EmptyServiceProvider.Instance; | |||||
_caseSensitive = config.CaseSensitiveCommands; | _caseSensitive = config.CaseSensitiveCommands; | ||||
_throwOnError = config.ThrowOnError; | _throwOnError = config.ThrowOnError; | ||||
_ignoreExtraArgs = config.IgnoreExtraArgs; | _ignoreExtraArgs = config.IgnoreExtraArgs; | ||||
@@ -91,7 +94,6 @@ namespace Discord.Commands | |||||
var module = builder.Build(this, null); | 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); | return LoadModuleInternal(module); | ||||
} | } | ||||
finally | finally | ||||
@@ -149,22 +151,6 @@ namespace Discord.Commands | |||||
{ | { | ||||
_moduleDefs.Add(module); | _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) | foreach (var command in module.Commands) | ||||
_map.AddCommand(command); | _map.AddCommand(command); | ||||
@@ -21,6 +21,8 @@ namespace Discord.Commands | |||||
/// <summary> Determines whether extra parameters should be ignored. </summary> | /// <summary> Determines whether extra parameters should be ignored. </summary> | ||||
public bool IgnoreExtraArgs { get; set; } = false; | 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; } | |||||
} | } | ||||
} | } |