-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (40 loc) · 1.4 KB
/
Program.cs
File metadata and controls
54 lines (40 loc) · 1.4 KB
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
using TeleBot;
using Telegram.Bot;
using TeleBotConfiguration;
using Telegram.Bot.Extensions.Polling;
using Telegram.Bot.Types;
namespace TeleBotRun;
public static class Program
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
private static TelegramBotClient? Bot;
public static async Task Main()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
Bot = new TelegramBotClient(Configuration.BotToken);
User me = await Bot.GetMeAsync();
Console.Title = me.Username ?? "BOT";
using var cts = new CancellationTokenSource();
ReceiverOptions receiverOptions = new() { AllowedUpdates = { } };
Bot.StartReceiving(BotHandlers.HandleUpdateAsync,
BotHandlers.HandleErrorAsync,
receiverOptions,
cts.Token);
try
{
await Bot.SendTextMessageAsync(Configuration.AccesschatID, "🖥 PC is online!");
}
catch (Exception)
{
MessageBox.Show($"Invalid chat id : {Configuration.AccesschatID}");
}
Console.ReadLine();
cts.Cancel();
}
}