geekbot/Geekbot.net/Lib/ErrorHandler.cs

33 lines
1,005 B
C#
Raw Normal View History

2017-09-26 22:09:57 +02:00
using System;
using Discord.Commands;
using Serilog;
namespace Geekbot.net.Lib
{
public class ErrorHandler : IErrorHandler
{
2017-10-19 21:43:37 +02:00
private readonly ILogger _logger;
2017-09-26 22:09:57 +02:00
2017-10-19 21:43:37 +02:00
public ErrorHandler(ILogger logger)
2017-09-26 22:09:57 +02:00
{
2017-10-19 21:43:37 +02:00
_logger = logger;
2017-09-26 22:09:57 +02:00
}
2017-10-03 21:47:09 +02:00
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:")
2017-09-26 22:09:57 +02:00
{
var errorMsg =
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\" in \"{Context.Guild.Name}/{Context.Channel.Name}\"";
2017-10-19 21:43:37 +02:00
_logger.Error(e, errorMsg);
2017-09-28 18:55:57 +02:00
if (!string.IsNullOrEmpty(errorMessage))
{
Context.Channel.SendMessageAsync(errorMessage);
}
2017-10-19 21:43:37 +02:00
2017-09-26 22:09:57 +02:00
}
}
public interface IErrorHandler
{
2017-10-03 21:47:09 +02:00
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:");
2017-09-26 22:09:57 +02:00
}
}