feat: added DI to Client
This commit is contained in:
8
JOBot.TClient/Commands/ITelegramCommand.cs
Normal file
8
JOBot.TClient/Commands/ITelegramCommand.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace JOBot.TClient.Commands;
|
||||
|
||||
public interface ITelegramCommand
|
||||
{
|
||||
public Task ExecuteAsync(Update update, CancellationToken ct);
|
||||
}
|
||||
18
JOBot.TClient/Commands/StartCommand.cs
Normal file
18
JOBot.TClient/Commands/StartCommand.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user