/
d.alekseev
/
SmartMenuBot
Обзор
Документация
Войти
/
d.alekseev
/
SmartMenuBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ConsoleBot/TelegramBot/Commands/Implementations/StartCommand.cs
45 строк
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 StartCommand(ITelegramBotClient botClient, IUserService userService, ITaskLimitsManager limitsManager) : IBotCommand { public string CommandText => "/start"; 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Вы уже авторизовались ранее", replyMarkup: ReplyKeyboards.PostRegistration, cancellationToken: ct ); return; } var newUser = context.Update.Message.From; await userService.RegisterUserAsync(newUser.Id, newUser.Username, ct); await botClient.SendMessage( context.Update.Message.Chat.Id, "Добро пожаловать в систему управления обогревом загородного дома!\n", replyMarkup: ReplyKeyboards.PostRegistration, cancellationToken: ct ); await limitsManager.TryInitializeFromUserInputAsync(context); } } }