/
Laxerem
/
BaskBot
Обзор
Документация
Войти
/
Laxerem
/
BaskBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
BaskBot.Application/Bot/Controllers/UserController.cs
64 строки
3 KB
Laxerem
[SAVED]: Start creating a KeyboardBuilder
06 янв 2026, 10:06
06 янв 2026, 10:06
c92a9e7
Код
Авторство
О чём код?
using BaskBot.Application.Bot.Abstractions; using BaskBot.Application.Bot.External.Events; using BaskBot.Application.Exceptions; using BaskBot.Infrastructure.Clients; using Microsoft.Extensions.Logging; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; namespace BaskBot.Application.Bot.Controllers; public class UserController { private readonly OpenRouterClient _openRouterClient; private readonly CommandController _commandController; private readonly ILogger<UserController> _logger; public UserController(OpenRouterClient openRouterClient, CommandController commandController, ILogger<UserController> logger) { _openRouterClient = openRouterClient; _commandController = commandController; _logger = logger; } public async Task ProcessEvent(ITelegramBotClient botClient, UserEvent evt, CancellationToken ctsToken) { try { switch (evt.Type) { case UpdateType.Message: await ProcessMessage(botClient, (MessageUserEvent)evt, ctsToken); break; case UpdateType.CallbackQuery: await ProcessCallback(botClient, (CallbackQueryUserEvent)evt, ctsToken); break; default: break; } } catch (OperationCanceledException) { await botClient.SendMessage(evt.Chat, "Превышено время ожидания"); } catch (NotAuthorizedException) { await botClient.SendMessage(evt.Chat, "Похоже, вы не авторизованы!"); } catch (Exception e) { _logger.LogError(e, e.Message); await botClient.SendMessage(evt.Chat, "Неизвестная ошибка"); } } private async Task ProcessMessage(ITelegramBotClient botClient, MessageUserEvent evt, CancellationToken ctsToken) { var message = evt.GetContent(); _logger.LogInformation($"Processing message from user ({evt.Username}): {message}"); if (message.StartsWith("/")) { await _commandController.HandleCommand(botClient, evt, message); } else { var response = await _openRouterClient.GenerateModelResponse(message, "Всегда отвечай в пределах 300-350 символов. Заканчивай мысль полностью.", cancellationToken: ctsToken); await botClient.SendMessage(evt.Chat, response); } } private async Task ProcessCallback(ITelegramBotClient botClient, CallbackQueryUserEvent evt, CancellationToken ctsToken) { var callback = evt.GetContent(); _logger.LogInformation($"Processing Data from user ({evt.Username}): {callback}"); } }