-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateHandlers.cs
75 lines (57 loc) · 2.27 KB
/
UpdateHandlers.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace MigrationBot
{
internal class UpdateHandlers
{
private static void Logger(Update update)
{
Console.WriteLine(DateTime.Now.ToShortTimeString());
Console.WriteLine($"{update.Type}\n");
if (update.Type == UpdateType.Message)
{
if (string.IsNullOrEmpty(update.Message.Text) == false)
Console.WriteLine($"Message: {update.Message.Text}\nFrom: {update.Message.From.Id}");
}
else
{
Console.WriteLine($"Querry: {update.CallbackQuery.Data}\nText: {update.CallbackQuery.Message.Text}\nFrom: {update.CallbackQuery.From.Id}");
}
Console.WriteLine();
}
public static async Task HandleUpdateAsync(Update update, TelegramBotClient bot)
{
if (update != null)
{
Logger(update);
if (update.Type == UpdateType.Message)
{
Message message = update.Message;
if (message.Type == MessageType.Text)
{
await TextHandler(message, bot);
}
}
else if (update.Type == UpdateType.CallbackQuery)
{
await CallBackHandler(update, bot);
if(!update.CallbackQuery.Data.Contains("Admin_answer"))
await bot.DeleteMessageAsync(update.CallbackQuery.From.Id, update.CallbackQuery.Message.MessageId);
}
}
}
private static async Task TextHandler(Message message, TelegramBotClient bot)
{
long chatId = message.From.Id;
string message_text = message.Text;
await bot.SendChatActionAsync(chatId, ChatAction.Typing);
await ComandExecutor.Execute(message_text, chatId, bot, message);
}
private static async Task CallBackHandler(Update update, TelegramBotClient bot)
{
long chatId = update.CallbackQuery.From.Id;
string query = update.CallbackQuery.Data;
await bot.SendChatActionAsync(chatId, ChatAction.Typing);
await QueryExecutor.Execute(query, chatId, bot);
}
}
}