static async Task Main(string[] args) { string botToken; if (args == null || args.Length == 0) { Console.WriteLine("Please enter your Bot Token. Alternatively you can also use it as startup parameter"); botToken = Console.ReadLine(); } else { botToken = args[0]; } bot = new TelegramBotClient(botToken); bot.OnMessage += Bot_OnMessage; bot.OnCallbackQuery += Bot_OnCallbackQuery; bot.StartReceiving(); botUser = await bot.GetMeAsync(); SteamDB.OnFreeGameReturnedEvent += OnFreeGameReturnedEvent; while (true) { SteamDB.Crawl(); var timeOfDay = DateTime.Now.TimeOfDay; var nextFullHour = TimeSpan.FromHours(Math.Ceiling(timeOfDay.Add(TimeSpan.FromMinutes(-1)).TotalHours)).Add(TimeSpan.FromMinutes(1)); //One Minute after next full hour int delta = (int)((nextFullHour - timeOfDay).TotalMilliseconds); Thread.Sleep(delta); //Sleep until next hour + 1 minute (High chance to catch new sales early) } }
static void SendFreeGameMessages() { games = SteamDB.GetFreeGames(); DatabaseContext db = new DatabaseContext(); Subscribers[] subs = db.subscribers.Where(s => s.wantsDlcInfo || s.wantsGameInfo).ToArray(); foreach (Subscribers sub in subs) { Thread messageThread = new Thread(() => SendFreeGameMessage(sub)); messageThread.Start(); Thread.Sleep(10); } }