Browse Source

Add a OnException hook to IModuleBase

pull/1615/head
runebaas 5 years ago
parent
commit
d9aeccb83b
No known key found for this signature in database GPG Key ID: 2677AF508D0300D6
3 changed files with 18 additions and 0 deletions
  1. +5
    -0
      src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs
  2. +3
    -0
      src/Discord.Net.Commands/IModuleBase.cs
  3. +10
    -0
      src/Discord.Net.Commands/ModuleBase.cs

+ 5
- 0
src/Discord.Net.Commands/Builders/ModuleClassBuilder.cs View File

@@ -220,6 +220,11 @@ namespace Discord.Commands
return ExecuteResult.FromSuccess();
}
}
catch (Exception exception)
{
instance.OnException(cmd, exception);
return ExecuteResult.FromError(exception);
}
finally
{
instance.AfterExecute(cmd);


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

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

namespace Discord.Commands
@@ -10,6 +11,8 @@ namespace Discord.Commands
void AfterExecute(CommandInfo command);

void OnException(CommandInfo command, Exception exception);

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

+ 10
- 0
src/Discord.Net.Commands/ModuleBase.cs View File

@@ -54,6 +54,15 @@ namespace Discord.Commands
{
}

/// <summary>
/// The method to execute when an exception is thrown
/// </summary>
/// <param name="command"></param>
/// <param name="exception"></param>
protected virtual void OnException(CommandInfo command, Exception exception)
{
}

/// <summary>
/// The method to execute when building the module.
/// </summary>
@@ -71,6 +80,7 @@ namespace Discord.Commands
}
void IModuleBase.BeforeExecute(CommandInfo command) => BeforeExecute(command);
void IModuleBase.AfterExecute(CommandInfo command) => AfterExecute(command);
void IModuleBase.OnException(CommandInfo command, Exception exception) => OnException(command, exception);
void IModuleBase.OnModuleBuilding(CommandService commandService, ModuleBuilder builder) => OnModuleBuilding(commandService, builder);
}
}

Loading…
Cancel
Save