Basic error telegram logging support

Signed-off-by: Basique Evangelist <basiqueevangelist@yandex.ru>
This commit is contained in:
Basique Evangelist 2019-05-16 20:25:18 +03:00
parent 48be616899
commit 737063d2dc
Signed by untrusted user: BasiqueEvangelist
GPG Key ID: B370219149301706

View File

@ -1,21 +1,23 @@
using JetKarmaBot.Commands;
using JetKarmaBot.Services;
using NLog;
using Perfusion;
using System;
using System.Collections.Generic;
using System.Linq;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
namespace JetKarmaBot
{
public class ChatCommandRouter
{
User BotUser { get; }
[Inject]
private Logger log;
Telegram.Bot.Types.User BotUser { get; }
[Inject] private Logger log;
[Inject] private KarmaContextFactory Db;
[Inject] private TelegramBotClient Client { get; set; }
public ChatCommandRouter(User botUser)
public ChatCommandRouter(Telegram.Bot.Types.User botUser)
{
BotUser = botUser;
}
@ -45,13 +47,23 @@ namespace JetKarmaBot
{
log.Error($"Error while handling command {cmd.Command}!");
log.Error(e);
ReportToAdministratorChats($"Error while handling command {cmd.Command}!\n{e.ToString()}");
}
}
return false;
}
public void ReportToAdministratorChats(string text)
{
using (var db = Db.GetContext())
{
foreach (long chatid in db.Chats.Where(x => x.IsAdministrator).Select(x => x.ChatId))
{
Client.SendTextMessageAsync(chatid, text);
}
}
}
public void Add(IChatCommand c)
{