-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
58 lines (48 loc) · 1.69 KB
/
Program.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
using Serilog;
using System;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot;
using CalendarTelegramBot.Context;
namespace CalendarTelegramBot
{
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File("./logs/log.txt", rollingInterval: RollingInterval.Day)
.WriteTo.Console()
.CreateLogger();
var resetEvent = new ManualResetEvent(false);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
if (Environment.UserInteractive)
{
Console.OutputEncoding = Encoding.Unicode;
}
AppDomain.CurrentDomain.ProcessExit += (s, e) => resetEvent.Set();
Console.CancelKeyPress += (s, e) =>
{
Log.Warning("Program exit requested. Exiting...");
resetEvent.Set();
e.Cancel = true;
};
using(var dbContext = new DatabaseContext())
{
dbContext.Database.EnsureCreated();
}
var token = Environment.GetEnvironmentVariable("BOT_TOKEN");
if (token == null)
{
Log.Error("Bot token was not specified. Please, check your GSHOP_BOT_TOKEN environment variable");
return;
}
var client = new TelegramBotClient(token);
var bot = new CaledarBot(Log.Logger, client);
bot.Run(resetEvent);
}
}
}