-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceLanguageSetterCommand.cs
49 lines (40 loc) · 1.72 KB
/
SourceLanguageSetterCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Text.Json;
using Telegram.Bot;
using TranslatorTelegramBot.Models.Enums;
using TranslatorTelegramBot.Services.Abstractions;
using TranslatorTelegramBot.Utils;
namespace TranslatorTelegramBot.Commands;
public class SourceLanguageSetterCommand : ICommand
{
public static string CommandName => "/set_source_language";
private readonly ILanguageManager languageManager;
private readonly JsonSerializerOptions serializerOptions;
private readonly int replyKeyboardColumns;
public SourceLanguageSetterCommand(ILanguageManager languageManager,
JsonSerializerOptions serializerOptions, int replyKeyboardColumns)
{
this.languageManager = languageManager;
this.serializerOptions = serializerOptions;
this.replyKeyboardColumns = replyKeyboardColumns;
}
public async Task HandleCommand(ITelegramBotClient botClient,
long chatId,
CancellationToken cancellationToken,
string? arguments = null)
{
var messageId = (await botClient.SendTextMessageAsync(chatId: chatId, text: "Processing...",
cancellationToken: cancellationToken)).MessageId;
var languages = await languageManager.GetLanguageCollectionAsync();
var replyMarkup =
TelegramUtilities.ParseLanguageCollectionAsKeyboardMarkup(languages, replyKeyboardColumns,
LanguageDirection.Source,
messageId, serializerOptions);
await botClient.EditMessageTextAsync(
chatId: chatId,
messageId: messageId,
text: "Choose a source language",
replyMarkup: replyMarkup,
cancellationToken: cancellationToken);
}
public string GetCommandName() => CommandName;
}