Add and use interaction command hooks for BeforeExecute, AfterExecute, OnException and GetExceptionResponse

This commit is contained in:
Daan Boerlage 2021-10-30 14:43:57 +02:00
parent 9a2bf84a05
commit 24749d9009
Signed by: daan
GPG key ID: FCE070E1E4956606
3 changed files with 43 additions and 7 deletions

View file

@ -40,8 +40,23 @@ namespace Geekbot.Core.Interactions
{
var type = _commands[interaction.Data.Name];
var command = (InteractionBase)Activator.CreateInstance(type);
return await command.Exec(interaction);
InteractionResponse response;
command.BeforeExecute();
try
{
response = await command.Exec(interaction);
}
catch (Exception e)
{
command.OnException(e);
response = command.GetExceptionResponse();
}
finally
{
command.AfterExecute();
}
return response;
}
}
}