2020-03-02 00:00:52 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using BotFramework.Attributes;
|
|
|
|
|
|
using Kruzya.TelegramBot.RichSiteSummary.Data;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
|
|
|
|
|
{
|
|
|
|
|
|
public class StatsHandler : AbstractHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
public StatsHandler(RichSiteSummaryContext dbContext) : base(dbContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-02 17:07:42 +04:00
|
|
|
|
[Command("rss_stats")]
|
2020-03-02 00:00:52 +04:00
|
|
|
|
public async Task Execute()
|
|
|
|
|
|
{
|
|
|
|
|
|
var feedCount = await _dbContext.Feeds.CountAsync();
|
|
|
|
|
|
var postsCount = await _dbContext.Posts.CountAsync();
|
|
|
|
|
|
var subscriptionsCount = await _dbContext.Subscriptions.CountAsync();
|
|
|
|
|
|
var uniqueSubscribers =
|
|
|
|
|
|
await _dbContext.Subscriptions.Select(sub => sub.SubscriberId).Distinct().CountAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var textMessage = new StringBuilder();
|
|
|
|
|
|
textMessage.Append("ℹ️ In database on this moment:\n");
|
|
|
|
|
|
textMessage.Append($"- registered <b>{feedCount} feeds</b>\n");
|
|
|
|
|
|
textMessage.Append($"- saved <b>{postsCount} posts</b> for prevent re-sending\n");
|
|
|
|
|
|
textMessage.Append(
|
|
|
|
|
|
$"- exists <b>{subscriptionsCount} subscriptions on feeds</b> (<b>unique subscribers: {uniqueSubscribers}</b>)");
|
|
|
|
|
|
|
|
|
|
|
|
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), ParseMode.Html);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|