public async Task Loop() { while (true) { var npReq = new PlayerCurrentlyPlayingRequest(); var nowPlaying = await spotify.Player.GetCurrentlyPlaying(npReq); var tgReq = new TLRequestUpdateProfile { FirstName = Environment.GetEnvironmentVariable("FIRST_NAME"), LastName = "" }; if (nowPlaying.IsPlaying && nowPlaying.Item.GetType() == typeof(FullTrack)) { var item = (FullTrack)nowPlaying.Item; var fullTrackName = $"{item.Artists[0].Name} — {item.Name}".Truncate(61); tgReq.LastName = $"🎵 {fullTrackName}"; } if (tgReq.LastName != lastSetName) { Console.WriteLine("new name!"); await telegram.SendRequestAsync <TLUser>(tgReq); } lastSetName = tgReq.LastName; Thread.Sleep(10000); } }
public void UpdateStatus() { var update = Task.Run(async() => { while (true) { await Task.Delay(1000); if (Ready()) { PlayerCurrentlyPlayingRequest request = new PlayerCurrentlyPlayingRequest(PlayerCurrentlyPlayingRequest.AdditionalTypes.All); CurrentlyPlaying playing = await SClient.Player.GetCurrentlyPlaying(request); if (playing != null) { if (playing.IsPlaying) { await bot.SetStatusAsync(UserStatus.Online); string song = ""; switch (playing.Item.Type) { case ItemType.Track: song = (playing.Item as FullTrack).Name; break; case ItemType.Episode: song = (playing.Item as FullEpisode).Name; break; } await bot.SetGameAsync(song, type: ActivityType.Listening); if (Queue[0].SongName == song) { Queue.RemoveAt(0); } } else { await bot.SetStatusAsync(UserStatus.DoNotDisturb); } } else { await bot.SetGameAsync($"Spotify", type: ActivityType.Listening); } } else { await bot.SetStatusAsync(UserStatus.DoNotDisturb); } } }); }
public async Task <CurrentlyPlaying> GetCurrentlyPlayingItem (ISpotifyClient client, PlayerCurrentlyPlayingRequest request) { try { var currentPlaying = await client.Player.GetCurrentlyPlaying(request); return(currentPlaying); } catch (Exception ex) { throw new Exception(ex.Message); } }
Task <CurrentlyPlaying> IPlayerClient.GetCurrentlyPlaying(PlayerCurrentlyPlayingRequest request) => throw new NotImplementedException();