/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/TelegramBot/Commands/Implementations/ReportCommand.cs
46 строк
2 KB
d.alekseev
feat: миграция на Telegram.Bot с reply-клавиатурами и меню команд
08 фев 2026, 17:00
08 фев 2026, 17:00
054ee94
Код
Авторство
О чём код?
using Telegram.Bot; using SmartMenuBot.Core.Services.Interfaces; using SmartMenuBot.TelegramBot.Commands.Interfaces; namespace SmartMenuBot.TelegramBot.Commands.Implementations { public class ReportCommand(ITelegramBotClient botClient, IUserService userService, IToDoReportService reportService) : IBotCommand { public string CommandText => "/report"; private const string ReportFormat = "Статистика по задачам на {0:dd.MM.yyyy HH:mm:ss}. Всего: {1}; Завершенных: {2}; Активных: {3}"; public bool CanExecute(CommandContext context) { string? messageText = context.Update.Message?.Text; return messageText != null && messageText.StartsWith(CommandText, StringComparison.OrdinalIgnoreCase); } public async Task ExecuteAsync(CommandContext context) { var ct = context.CancellationToken; var existingUser = await userService.GetUserAsync(context.Update.Message!.From!.Id, ct); if (existingUser == null) { await botClient.SendMessage( context.Update.Message.Chat.Id, "\nДля использования этой функции необходимо авторизоваться командой /start", replyMarkup: ReplyKeyboards.PreRegistration, cancellationToken: ct ); return; } var stats = await reportService.GetUserStatsAsync(existingUser.UserId, ct); var localTime = stats.generatedAt.ToLocalTime(); var message = string.Format(ReportFormat, localTime, stats.total, stats.completed, stats.active); await botClient.SendMessage(context.Update.Message.Chat.Id, message, cancellationToken: ct); } } }