mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Remove reporting errors to admin chats
This commit is contained in:
parent
35dbb7fe78
commit
df9dd4a1f7
@ -16,7 +16,6 @@ namespace JetKarmaBot
|
|||||||
{
|
{
|
||||||
public Telegram.Bot.Types.User Me { get; private set; }
|
public Telegram.Bot.Types.User Me { get; private set; }
|
||||||
[Inject] private Logger log;
|
[Inject] private Logger log;
|
||||||
[Inject] private KarmaContextFactory Db;
|
|
||||||
[Inject] private TelegramBotClient Client { get; set; }
|
[Inject] private TelegramBotClient Client { get; set; }
|
||||||
|
|
||||||
public async Task Start()
|
public async Task Start()
|
||||||
@ -24,7 +23,7 @@ namespace JetKarmaBot
|
|||||||
Me = await Client.GetMeAsync();
|
Me = await Client.GetMeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> Execute(object sender, MessageEventArgs args)
|
public Task<bool> Execute(object sender, MessageEventArgs args)
|
||||||
{
|
{
|
||||||
log.Debug("Message received");
|
log.Debug("Message received");
|
||||||
var text = args.Message.Text;
|
var text = args.Message.Text;
|
||||||
@ -34,7 +33,7 @@ namespace JetKarmaBot
|
|||||||
{
|
{
|
||||||
// directed not at us!
|
// directed not at us!
|
||||||
log.Debug("Message not directed at us");
|
log.Debug("Message not directed at us");
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -42,35 +41,17 @@ namespace JetKarmaBot
|
|||||||
if (commands.ContainsKey(cmd.Command))
|
if (commands.ContainsKey(cmd.Command))
|
||||||
{
|
{
|
||||||
log.Debug($"Handling message via {commands[cmd.Command].GetType().Name}");
|
log.Debug($"Handling message via {commands[cmd.Command].GetType().Name}");
|
||||||
return await commands[cmd.Command].Execute(cmd, args);
|
return commands[cmd.Command].Execute(cmd, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.Error($"Error while handling command {cmd.Command}!");
|
log.Error($"Error while handling command {cmd.Command}!");
|
||||||
log.Error(e);
|
log.Error(e);
|
||||||
await ReportToAdministratorChats($"Error while handling command {cmd.Command}!\n{e.ToString()}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ReportToAdministratorChats(string text)
|
|
||||||
{
|
|
||||||
using (var db = Db.GetContext())
|
|
||||||
{
|
|
||||||
await Task.WhenAll(
|
|
||||||
(await db.Chats
|
|
||||||
.Where(x => x.IsAdministrator)
|
|
||||||
.Select(x => x.ChatId)
|
|
||||||
.ToArrayAsync())
|
|
||||||
.Select(x => Client.SendTextMessageAsync(x, text)));
|
|
||||||
foreach (long chatid in db.Chats.Where(x => x.IsAdministrator).Select(x => x.ChatId))
|
|
||||||
{
|
|
||||||
await Client.SendTextMessageAsync(chatid, text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(IChatCommand c)
|
public void Add(IChatCommand c)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user