-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.cs
62 lines (48 loc) · 1.75 KB
/
Bot.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
namespace MigrationBot
{
internal class Bot
{
private static string token = Data.Strings.Tokens.BotToken;
internal static long Admin_Chat = 479020307;
//debug == true => windows
// debug == false => UNIX
public static bool DEBUG = true;
//internal static long Admin_Chat = 477686161;
private static TelegramBotClient bot = new TelegramBotClient(token);
public static async Task Start()
{
Console.WriteLine("Запущен бот " + bot.GetMeAsync().Result.FirstName);
while (true)
{
try
{
var cancellationToken = CancellationToken.None;
var receiverOptions = new ReceiverOptions
{
AllowedUpdates = { }, // receive all update types
};
var updateReceiver = new QueuedUpdateReceiver(bot, receiverOptions);
try
{
await foreach (Update update in updateReceiver.WithCancellation(cancellationToken))
{
_ = Task.Run(() =>
{
_ = UpdateHandlers.HandleUpdateAsync(update, bot);
return Task.CompletedTask;
});
}
}
catch (OperationCanceledException exception)
{
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
}