Pass interaction data into all InteractionBase hooks
This commit is contained in:
parent
01df35b12b
commit
5a520ff567
3 changed files with 21 additions and 16 deletions
|
@ -1,13 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Geekbot.Core.Interactions.Request;
|
||||||
using Geekbot.Core.Interactions.Response;
|
using Geekbot.Core.Interactions.Response;
|
||||||
|
|
||||||
namespace Geekbot.Core.Interactions
|
namespace Geekbot.Core.Interactions
|
||||||
{
|
{
|
||||||
public interface IInteractionBase
|
public interface IInteractionBase
|
||||||
{
|
{
|
||||||
void BeforeExecute();
|
void BeforeExecute(Interaction interaction);
|
||||||
void AfterExecute();
|
void AfterExecute(Interaction interaction);
|
||||||
void OnException(Exception e);
|
void OnException(Interaction interaction, Exception e);
|
||||||
InteractionResponse GetExceptionResponse();
|
InteractionResponse GetExceptionResponse(Interaction interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,23 +9,23 @@ namespace Geekbot.Core.Interactions
|
||||||
{
|
{
|
||||||
public abstract class InteractionBase : IInteractionBase
|
public abstract class InteractionBase : IInteractionBase
|
||||||
{
|
{
|
||||||
public virtual void BeforeExecute()
|
public virtual void BeforeExecute(Interaction interaction)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void AfterExecute()
|
public virtual void AfterExecute(Interaction interaction)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnException(Exception exception)
|
public virtual void OnException(Interaction interaction, Exception exception)
|
||||||
{
|
{
|
||||||
if (!SentrySdk.IsEnabled) return;
|
if (!SentrySdk.IsEnabled) return;
|
||||||
SentrySdk.CaptureException(exception);
|
SentrySdk.CaptureException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual InteractionResponse GetExceptionResponse()
|
public virtual InteractionResponse GetExceptionResponse(Interaction interaction)
|
||||||
{
|
{
|
||||||
return new InteractionResponse()
|
return new InteractionResponse()
|
||||||
{
|
{
|
||||||
|
@ -40,9 +40,13 @@ namespace Geekbot.Core.Interactions
|
||||||
public abstract Command GetCommandInfo();
|
public abstract Command GetCommandInfo();
|
||||||
public abstract Task<InteractionResponse> Exec(Interaction interaction);
|
public abstract Task<InteractionResponse> Exec(Interaction interaction);
|
||||||
|
|
||||||
void IInteractionBase.BeforeExecute() => this.BeforeExecute();
|
void IInteractionBase.BeforeExecute(Interaction interaction)
|
||||||
void IInteractionBase.AfterExecute() => this.AfterExecute();
|
=> this.BeforeExecute(interaction);
|
||||||
void IInteractionBase.OnException(Exception e) => this.OnException(e);
|
void IInteractionBase.AfterExecute(Interaction interaction)
|
||||||
InteractionResponse IInteractionBase.GetExceptionResponse() => this.GetExceptionResponse();
|
=> this.AfterExecute(interaction);
|
||||||
|
void IInteractionBase.OnException(Interaction interaction, Exception e)
|
||||||
|
=> this.OnException(interaction, e);
|
||||||
|
InteractionResponse IInteractionBase.GetExceptionResponse(Interaction interaction)
|
||||||
|
=> this.GetExceptionResponse(interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -67,17 +67,17 @@ namespace Geekbot.Core.Interactions
|
||||||
InteractionResponse response;
|
InteractionResponse response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.BeforeExecute();
|
command.BeforeExecute(interaction);
|
||||||
response = await command.Exec(interaction);
|
response = await command.Exec(interaction);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
command.OnException(e);
|
command.OnException(interaction, e);
|
||||||
response = command.GetExceptionResponse();
|
response = command.GetExceptionResponse(interaction);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
command.AfterExecute();
|
command.AfterExecute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
Loading…
Reference in a new issue