Browse Source

Fixed RunMode.Sync running Async. Added ThrowOnError option.

tags/1.0-rc
RogueException 8 years ago
parent
commit
3fb21e06c2
3 changed files with 11 additions and 3 deletions
  1. +2
    -1
      src/Discord.Net.Commands/CommandService.cs
  2. +6
    -0
      src/Discord.Net.Commands/CommandServiceConfig.cs
  3. +3
    -2
      src/Discord.Net.Commands/Info/CommandInfo.cs

+ 2
- 1
src/Discord.Net.Commands/CommandService.cs View File

@@ -24,7 +24,7 @@ namespace Discord.Commands
private readonly HashSet<ModuleInfo> _moduleDefs; private readonly HashSet<ModuleInfo> _moduleDefs;
private readonly CommandMap _map; private readonly CommandMap _map;


internal readonly bool _caseSensitive;
internal readonly bool _caseSensitive, _throwOnError;
internal readonly char _separatorChar; internal readonly char _separatorChar;
internal readonly RunMode _defaultRunMode; internal readonly RunMode _defaultRunMode;
internal readonly Logger _cmdLogger; internal readonly Logger _cmdLogger;
@@ -38,6 +38,7 @@ namespace Discord.Commands
public CommandService(CommandServiceConfig config) public CommandService(CommandServiceConfig config)
{ {
_caseSensitive = config.CaseSensitiveCommands; _caseSensitive = config.CaseSensitiveCommands;
_throwOnError = config.ThrowOnError;
_separatorChar = config.SeparatorChar; _separatorChar = config.SeparatorChar;
_defaultRunMode = config.DefaultRunMode; _defaultRunMode = config.DefaultRunMode;
if (_defaultRunMode == RunMode.Default) if (_defaultRunMode == RunMode.Default)


+ 6
- 0
src/Discord.Net.Commands/CommandServiceConfig.cs View File

@@ -11,5 +11,11 @@


/// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary> /// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary>
public LogSeverity LogLevel { get; set; } = LogSeverity.Info; public LogSeverity LogLevel { get; set; } = LogSeverity.Info;

/// <summary>
/// Gets or sets whether RunMode.Sync commands should push exceptions up to the caller.
/// If false or an RunMode.Async command, exceptions are only reported in the Log event.
///</summary>
public bool ThrowOnError { get; set; } = true;
} }
} }

+ 3
- 2
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -140,7 +140,7 @@ namespace Discord.Commands
switch (RunMode) switch (RunMode)
{ {
case RunMode.Sync: //Always sync case RunMode.Sync: //Always sync
var t1 = ExecuteAsyncInternal(context, args, map);
await ExecuteAsyncInternal(context, args, map).ConfigureAwait(false);
break; break;
case RunMode.Async: //Always async case RunMode.Async: //Always async
var t2 = Task.Run(async () => var t2 = Task.Run(async () =>
@@ -168,7 +168,8 @@ namespace Discord.Commands
{ {
ex = new CommandException(this, context, ex); ex = new CommandException(this, context, ex);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false); await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
throw;
if (Module.Service._throwOnError)
throw;
} }
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false); await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
} }


Loading…
Cancel
Save