diff --git a/TomatenMusicCore/Music/GuildPlayer.cs b/TomatenMusicCore/Music/GuildPlayer.cs index c877454..9687114 100644 --- a/TomatenMusicCore/Music/GuildPlayer.cs +++ b/TomatenMusicCore/Music/GuildPlayer.cs @@ -203,7 +203,6 @@ namespace TomatenMusic.Music public async override Task OnTrackEndAsync(TrackEndEventArgs eventArgs) { DisconnectOnStop = false; - YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService(); var oldTrack = CurrentTrack; if (eventArgs.Reason != TrackEndReason.Finished) @@ -226,12 +225,8 @@ namespace TomatenMusic.Music return; } - TomatenMusicTrack newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); - _logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}"); await base.OnTrackEndAsync(eventArgs); - PlayerQueue.LastTrack = newTrack; - await newTrack.Play(this); - QueuePrompt.UpdateFor(GuildId); + _ = OnAutoPlay(oldTrack); } } @@ -239,6 +234,21 @@ namespace TomatenMusic.Music } + public async Task OnAutoPlay(LavalinkTrack oldTrack) + { + YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService(); + + TomatenMusicTrack newTrack; + if (oldTrack.Source != "YouTube" ) + newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Source == "YouTube").TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); + else + newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); + _logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}"); + PlayerQueue.LastTrack = newTrack; + await newTrack.Play(this); + QueuePrompt.UpdateFor(GuildId); + } + public async Task GetChannelAsync() { EnsureConnected();