using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Services;
using Remora.Results;
namespace Boyfriend.Commands.Events;
///
/// Handles error logging for slash commands that couldn't be successfully prepared.
///
[UsedImplicitly]
public class LoggingPreparationErrorEvent : IPreparationErrorEvent
{
private readonly ILogger _logger;
public LoggingPreparationErrorEvent(ILogger logger)
{
_logger = logger;
}
///
/// Logs a warning using the injected if the has not
/// succeeded.
///
/// The context of the slash command. Unused.
/// The result whose success is checked.
/// The cancellation token for this operation. Unused.
/// A result which has succeeded.
public Task PreparationFailed(
IOperationContext context, IResult preparationResult, CancellationToken ct = default)
{
_logger.LogResult(preparationResult, "Error in slash command preparation.");
return Task.FromResult(Result.FromSuccess());
}
}