Esempio n. 1
0
        public async Task SendDailyStats(CancellationToken cancellationToken)
        {
            _log.LogInformation($"Daily stats triggered at: {DateTimeOffset.UtcNow}");
            var chats = await _statsManager.GetChatsIdsAsync(cancellationToken);

            foreach (var chatId in chats)
            {
                _log.LogInformation($"Daily stats: processing chatId: {chatId}");
                var statsString = await _statsManager.GetStatsStringAsync(new StatsCommand(chatId,
                                                                                           StatsType.Today),
                                                                          cancellationToken);

                await _telegramGateway.SendMessageAsync(chatId, statsString, cancellationToken);

                _log.LogInformation($"Daily stats sent to chatId: {chatId}");
            }
        }
        public async Task Post(Update update, CancellationToken cancellationToken)
        {
            var message = update.Message;

            if (message == null)
            {
                _log.LogError("Message is null");
                return;
            }

            if (!Commands.Commands.IsCommand(message))
            {
                try
                {
                    await _statsManager.AddToStatsAsync(update, cancellationToken);
                }
                catch (Exception ex)
                {
                    _log.LogError(ex, "Add message to stat exception");
                }
                return;
            }

            switch (message.Text)
            {
            case var text when Commands.Commands.IsStart(text):
                await _telegramGateway.SendMessageAsync(message.Chat.Id, Consts.Usage, cancellationToken);

                break;

            case var text when Commands.Commands.IsStats(text):
                await ReplyWithStatsAsync(message.Chat.Id, text, cancellationToken);

                break;

            case var text when Commands.Commands.IsRules(text):
                await _telegramGateway.SendMessageAsync(message.Chat.Id, Consts.Rules, cancellationToken);

                break;

            default:
                _log.LogInformation("Unknown command");
                break;
            }
        }