geekbot/Geekbot.net/Lib/ErrorHandler.cs

36 lines
1.2 KiB
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
{
private readonly ILogger logger;
// private readonly IDMChannel botOwnerDmChannel;
public ErrorHandler(ILogger logger /*, IDMChannel botOwnerDmChannel*/)
{
this.logger = logger;
// this.botOwnerDmChannel = botOwnerDmChannel;
}
2017-09-28 18:55:57 +02:00
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "")
2017-09-26 22:09:57 +02:00
{
var errorMsg =
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\", complete message was \"{Context.Message}\"";
2017-09-26 22:09:57 +02:00
logger.Error(e, errorMsg);
2017-09-28 18:55:57 +02:00
if (!string.IsNullOrEmpty(errorMessage))
{
Context.Channel.SendMessageAsync(errorMessage);
}
2017-09-26 22:09:57 +02:00
// await botOwnerDmChannel.SendMessageAsync($"{errorMsg}```{e.StackTrace}```");
// await Context.Channel.SendMessageAsync("Something went wrong...");
}
}
public interface IErrorHandler
{
2017-09-28 18:55:57 +02:00
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "");
2017-09-26 22:09:57 +02:00
}
}