-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (25 loc) · 1.19 KB
/
Program.cs
File metadata and controls
35 lines (25 loc) · 1.19 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
using bot;
using Microsoft.EntityFrameworkCore;
using var github = new Github(Environment.GetEnvironmentVariable("Github_Owner") ?? "",
Environment.GetEnvironmentVariable("Github_Repo") ?? "",
Environment.GetEnvironmentVariable("Github_Branch") ?? "");
using var telegram = new Telegram(Environment.GetEnvironmentVariable("Telegram_Bot_Token") ?? "");
using var db = new Db();
await db.Database.MigrateAsync();
var commit = await github.GetLatestCommitMessageAsync();
var newChats = (await telegram.GetAllChatsAsync())
.Where(chat => db.TelegramChats.All(dbChat => dbChat.ChatId != chat.Id))
.ToList();
db.TelegramChats.AddRange(newChats.Select(chat => new TelegramChat(chat)));
await db.SaveChangesAsync();
Console.WriteLine($"Added {newChats.Count} new chats");
var chats = db.TelegramChats
.ToList()
.Select(chat => chat.ToChat())
.ToArray();
Console.WriteLine($"Writing to {chats.Length} chats");
await telegram
.SendAsync(
$"Update 🎉:\n{commit}\n\nGet app at: https://app.eldoriantales.com/\nAs always" +
$" we appreciate ANY comments (mostly positive tho 😜)\n@Eldrin @mparchin @ParsaRashidi",
chats);