private static async Task UpdateStatus(LCUProvider lcu) { if (Stopping) { Log.Verborse("App", "Updating LoL status with initial message"); await lcu.StatusMessage(InitStatus); Abort(); return; } Log.Verborse("App", "Updating LoL status"); string song = ExternalProvider.ReadStatusFile(); if (song != "") { Log.Verborse("App", "Updating LoL status with External Provider"); } else { song = SpotifyProvider.Song(); if (song != "") { Log.Verborse("App", "Updating LoL status with Spotify Provider"); if (song.Length > (LIMIT_STATUS - 2)) { song = SpotifyProvider.Track(); } } else { Log.Verborse("App", "Spotify is close or stopped?"); } } if (song.Length > (LIMIT_STATUS - 2)) { song = song.Substring(0, LIMIT_STATUS - 3) + "…"; } else if (song.Length > (LIMIT_STATUS - 2)) { song = song.Substring(0, LIMIT_STATUS - 2); } if (song.Equals("") || string.IsNullOrEmpty(song)) { Log.Verborse("App", "Empty current song, updating LoL status with initial message"); await lcu.StatusMessage(InitStatus); } else if (LastSong == null || !LastSong.Equals(song)) { Log.Verborse("App", "Updating LoL status with " + song); await lcu.StatusMessage(string.Format("🎶 {0}", song)); LastSong = song; } else { Log.Verborse("App", "LoL status not update"); } }
private static async Task Run() { var lcu = new LCUProvider(); while (Started || Stopping) { int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; if (FirstTime || Stopping || (unixTimestamp % INTERVAL_UPDATE == 0)) { if (FirstTime || Stopping || !Waiting) { try { if (FirstTime || InitStatus == null) { string res = await lcu.StatusMessage(); if (res.Equals("")) { Thread.Sleep(10 * 1000); } else { var json = JObject.Parse(res); InitStatus = (string)json["statusMessage"]; Log.Verborse("App", "Initial status: " + InitStatus); await UpdateStatus(lcu); if (!Aborting) { Waiting = true; FirstTime = false; Thread.Sleep(1000); } } } else { await UpdateStatus(lcu); if (!Aborting) { Waiting = true; FirstTime = false; Thread.Sleep(1000); } } } catch (Newtonsoft.Json.JsonReaderException err) { Log.Notice("App", "JsonReaderException: " + err.Message); } catch (Exception err) { Log.Error(err.Message); } } else { Waiting = false; } } } }