/
Laxerem
/
BaskBot
Обзор
Документация
Войти
/
Laxerem
/
BaskBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
BaskBot.Application/Bot/Commands/CommandContext.cs
31 строка
1 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.Commands.Objects; using BaskBot.Application.Bot.External.Events; using BaskBot.Database; using Microsoft.Extensions.DependencyInjection; using Telegram.Bot; namespace BaskBot.Application.Bot.Commands; public class CommandContext { private readonly Dictionary<string, Type> _commandTypes; private readonly IServiceScopeFactory _serviceScopeFactory; public CommandContext(IServiceScopeFactory scopeFactory) { _serviceScopeFactory = scopeFactory; _commandTypes = new Dictionary<string, Type>() { { "/start", typeof(StartCommand) }, { "/register", typeof(RegisterCommand) } }; } public async Task FindAndExecute(string name, ITelegramBotClient bot, MessageUserEvent evt) { if (!_commandTypes.ContainsKey(name)) return; using var scope = _serviceScopeFactory.CreateScope(); var command = scope.ServiceProvider.GetRequiredService(_commandTypes[name]) as BaseCommand; if (command == null) return; await command.ExecuteAsync(bot, evt); } }