/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/TelegramBot/Commands/Implementations/CancelCommand.cs
39 строк
1 KB
d.alekseev
feat: сценарии AddTask с сохранением состояния и поддержкой срока задачи
09 фев 2026, 21:39
09 фев 2026, 21:39
ed2e630
Код
Авторство
О чём код?
using Telegram.Bot; using SmartMenuBot.Core.Services.Interfaces; using SmartMenuBot.TelegramBot.Commands.Interfaces; using SmartMenuBot.TelegramBot.Scenarios.Interfaces; namespace SmartMenuBot.TelegramBot.Commands.Implementations { public class CancelCommand( ITelegramBotClient botClient, IUserService userService, IScenarioContextRepository contextRepository) : IBotCommand { public string CommandText => "/cancel"; public CommandExecutionPolicy ExecutionPolicy => CommandExecutionPolicy.Always; 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 message = context.Update.Message!; await contextRepository.ResetContext(message.From!.Id, ct); var user = await userService.GetUserAsync(message.From.Id, ct); var keyboard = user is null ? ReplyKeyboards.PreRegistration : ReplyKeyboards.PostRegistration; await botClient.SendMessage( message.Chat.Id, "Сценарий отменен.", replyMarkup: keyboard, cancellationToken: ct); } } }