mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Basic error telegram logging support
Signed-off-by: Nikolay Kochulin <porez0xfeedface@gmail.com>
This commit is contained in:
parent
45b94e7561
commit
7bef7255f8
@ -1,21 +1,23 @@
|
|||||||
using JetKarmaBot.Commands;
|
using JetKarmaBot.Commands;
|
||||||
|
using JetKarmaBot.Services;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Perfusion;
|
using Perfusion;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Args;
|
using Telegram.Bot.Args;
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace JetKarmaBot
|
namespace JetKarmaBot
|
||||||
{
|
{
|
||||||
public class ChatCommandRouter
|
public class ChatCommandRouter
|
||||||
{
|
{
|
||||||
User BotUser { get; }
|
Telegram.Bot.Types.User BotUser { get; }
|
||||||
[Inject]
|
[Inject] private Logger log;
|
||||||
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;
|
BotUser = botUser;
|
||||||
}
|
}
|
||||||
@ -45,13 +47,23 @@ namespace JetKarmaBot
|
|||||||
{
|
{
|
||||||
log.Error($"Error while handling command {cmd.Command}!");
|
log.Error($"Error while handling command {cmd.Command}!");
|
||||||
log.Error(e);
|
log.Error(e);
|
||||||
|
ReportToAdministratorChats($"Error while handling command {cmd.Command}!\n{e.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
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)
|
public void Add(IChatCommand c)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user