feat: added DI to Client

This commit is contained in:
Lisoveliy
2025-05-01 20:50:14 +03:00
parent da0ca92795
commit 786c63166c
8 changed files with 149 additions and 42 deletions

View File

@@ -0,0 +1,8 @@
using Telegram.Bot.Types;
namespace JOBot.TClient.Commands;
public interface ITelegramCommand
{
public Task ExecuteAsync(Update update, CancellationToken ct);
}

View File

@@ -0,0 +1,18 @@
using JOBot.TClient.Core.Services;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace JOBot.TClient.Commands;
public class StartCommand(ITelegramBotClient bot, UserService userService) : ITelegramCommand
{
public async Task ExecuteAsync(Update update, CancellationToken ct)
{
var isRegistered = await userService.RegisterAsync(
update.Message?.Chat.Id ?? throw new Exception("Chat id is null"),
update.Message.Chat.Username);
await bot.SendMessage(chatId: update.Message.Chat.Id,
isRegistered ? "You registered" : "Not registered", cancellationToken: ct);
}
}