private async void Run() { await LoadReminderContext(); // initial load DateTime midnightNextDay = DateTime.Today.AddDays(1); while (true) { ChannelJSON channelJSON = await TwitchApi.GetBroadcasterChannelById(_twitchClientId); string gameTitle = channelJSON.Game; TwitchGameCategory game = await _gameDirectory.GetGameId(gameTitle); if (game == null || game.Id == 0) { _gameId = null; } else { _gameId = game.Id; } // remove pending reminders Program.DelayedMessages.RemoveAll(r => r.ReminderId > 0); foreach (RemindUser reminder in _reminders.OrderBy(m => m.RemindEveryMin)) { if (IsEveryMinReminder(reminder)) { continue; } else if (IsCountdownEvent(reminder)) { continue; } else { AddDayOfReminder(reminder); } } if (_refreshReminders) { _irc.SendPublicChatMessage("Reminders refreshed!"); } // reset refresh midnightNextDay = DateTime.Today.AddDays(1); _refreshReminders = false; // wait until midnight to check reminders // unless a manual refresh was called while (DateTime.Now < midnightNextDay && !_refreshReminders) { Thread.Sleep(1000); // 1 second } } }
public async Task <ChannelJSON> GetBroadcasterChannelById() { return(await TwitchApi.GetBroadcasterChannelById(_botConfig.TwitchClientId)); }