-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (44 loc) · 1.6 KB
/
Program.cs
File metadata and controls
49 lines (44 loc) · 1.6 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
using DotNetEnv;
using FluentScheduler;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
namespace BirthdaysBot
{
internal class Program
{
static void Main(string[] args)
{
// Load config
var stream = File.OpenRead(".env");
Env.Load(stream);
var token = Env.GetString("TELEGRAM_BOT_TOKEN");
stream.Close();
if (string.IsNullOrEmpty(token))
{
Console.WriteLine("Add Telegram bot's token to .env (refer to .env.example)");
Environment.Exit(1);
}
// Fire up
Bot.Initialize(token);
Database.Initialize("BirthdaysBot");
// Schedule daily messages
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
var registry = new Registry();
registry.Schedule(() =>
{
foreach (KeyValuePair<Int64, string> birthday in Database.GetTodaysBirthdays())
{
var birthdayNotification = $"\ud83e\udd73 {birthday.Value} празднует сегодня День рождения. Не порти себе карму, поздравь человека.";
Bot.SendMessage(birthday.Key, birthdayNotification);
}
}).ToRunEvery(1).Days().At(10, 0);
JobManager.Initialize(registry);
// Manual break
Console.WriteLine("Press any key to stop the bot");
Console.ReadKey();
}
}
}