2023-07-20 02:01:53 +05:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Remora.Discord.Commands.Contexts;
|
|
|
|
using Remora.Discord.Commands.Services;
|
|
|
|
using Remora.Results;
|
2024-05-16 20:34:26 +05:00
|
|
|
using TeamOctolings.Octobot.Extensions;
|
2023-07-20 02:01:53 +05:00
|
|
|
|
2024-05-16 20:34:26 +05:00
|
|
|
namespace TeamOctolings.Octobot.Commands.Events;
|
2023-07-20 02:01:53 +05:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handles error logging for slash commands that couldn't be successfully prepared.
|
|
|
|
/// </summary>
|
|
|
|
[UsedImplicitly]
|
2024-05-23 17:47:51 +05:00
|
|
|
public sealed class LoggingPreparationErrorEvent : IPreparationErrorEvent
|
2023-08-03 01:51:16 +05:00
|
|
|
{
|
2023-07-20 02:01:53 +05:00
|
|
|
private readonly ILogger<LoggingPreparationErrorEvent> _logger;
|
|
|
|
|
2023-08-03 01:51:16 +05:00
|
|
|
public LoggingPreparationErrorEvent(ILogger<LoggingPreparationErrorEvent> logger)
|
|
|
|
{
|
2023-07-20 02:01:53 +05:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Logs a warning using the injected <see cref="ILogger" /> if the <paramref name="preparationResult" /> has not
|
|
|
|
/// succeeded.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context">The context of the slash command. Unused.</param>
|
|
|
|
/// <param name="preparationResult">The result whose success is checked.</param>
|
|
|
|
/// <param name="ct">The cancellation token for this operation. Unused.</param>
|
|
|
|
/// <returns>A result which has succeeded.</returns>
|
|
|
|
public Task<Result> PreparationFailed(
|
2023-08-03 01:51:16 +05:00
|
|
|
IOperationContext context, IResult preparationResult, CancellationToken ct = default)
|
|
|
|
{
|
2023-08-05 23:02:40 +05:00
|
|
|
_logger.LogResult(preparationResult, "Error in slash command preparation.");
|
2023-07-20 02:01:53 +05:00
|
|
|
|
2024-03-21 20:55:34 +05:00
|
|
|
return Task.FromResult(Result.Success);
|
2023-07-20 02:01:53 +05:00
|
|
|
}
|
|
|
|
}
|