From a71f65de55b2a6bcd6e18f23f1c77ff499f98091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Wed, 6 Apr 2022 21:32:43 +0200 Subject: [PATCH 1/4] update package sources --- TomatenMusic/TomatenMusic.csproj | 4 ---- TomatenMusicCore/TomatenMusicCore.csproj | 12 ++++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/TomatenMusic/TomatenMusic.csproj b/TomatenMusic/TomatenMusic.csproj index 453b8d7..d793b10 100644 --- a/TomatenMusic/TomatenMusic.csproj +++ b/TomatenMusic/TomatenMusic.csproj @@ -5,10 +5,6 @@ enable enable TomatenMusic_Api - - https://api.nuget.org/v3/index.json; - https://nuget.emzi0767.com/api/v3/index.json - diff --git a/TomatenMusicCore/TomatenMusicCore.csproj b/TomatenMusicCore/TomatenMusicCore.csproj index 620cb46..36d5b2e 100644 --- a/TomatenMusicCore/TomatenMusicCore.csproj +++ b/TomatenMusicCore/TomatenMusicCore.csproj @@ -4,17 +4,13 @@ net6.0 enable enable - - https://api.nuget.org/v3/index.json; - https://nuget.emzi0767.com/api/v3/index.json - - - - - + + + + From fcd376bdcbe6a2f10be6f084531a5bb6717f2a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Wed, 13 Apr 2022 11:24:59 +0200 Subject: [PATCH 2/4] fix Queue Loop Current track not prepending on enable but appending --- TomatenMusicCore/Music/PlayerQueue.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TomatenMusicCore/Music/PlayerQueue.cs b/TomatenMusicCore/Music/PlayerQueue.cs index b8ca3cf..b3802f8 100644 --- a/TomatenMusicCore/Music/PlayerQueue.cs +++ b/TomatenMusicCore/Music/PlayerQueue.cs @@ -157,8 +157,7 @@ namespace TomatenMusic.Music if (type == LoopType.QUEUE) { - QueueLoopList = new List(Queue); - QueueLoopList.Add(LastTrack); + QueueLoopList = new List(QueueLoopList.Prepend(LastTrack)); } } } From 47bffbff7f59f9a1e54773c42d7f5f976b66abf1 Mon Sep 17 00:00:00 2001 From: EkiciLP Date: Thu, 14 Apr 2022 12:13:39 +0200 Subject: [PATCH 3/4] fix Bot throwing an error when tryimg to autoplay tracks from non youtube sources --- TomatenMusicCore/Music/GuildPlayer.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) 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(); From ac0f6e18ed36468414bc86724ce41d7803b5b0c0 Mon Sep 17 00:00:00 2001 From: EkiciLP Date: Fri, 15 Apr 2022 02:28:20 +0200 Subject: [PATCH 4/4] fixed stage channel speaking requests fixed several bugs regarding autoplay fixed skip autoplay not working --- TomatenMusicCore/Music/GuildPlayer.cs | 25 ++++++++++--------- TomatenMusicCore/Music/PlayerQueue.cs | 5 ++-- .../Prompt/Implementation/QueuePrompt.cs | 17 +++++++++++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/TomatenMusicCore/Music/GuildPlayer.cs b/TomatenMusicCore/Music/GuildPlayer.cs index 9687114..d2db34a 100644 --- a/TomatenMusicCore/Music/GuildPlayer.cs +++ b/TomatenMusicCore/Music/GuildPlayer.cs @@ -89,17 +89,12 @@ namespace TomatenMusic.Music MusicActionResponse response; try { - response = PlayerQueue.NextTrack(true); + response = PlayerQueue.NextTrack(true, Autoplay); }catch (Exception ex) { if (Autoplay) { - YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService(); - LavalinkTrack newTrack = await youtube.GetRelatedTrackAsync(CurrentTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier)); - - _logger.LogInformation($"Skipped Track {CurrentTrack.Title} for Autoplayed Track {newTrack.Title}"); - await PlayAsync(newTrack); - QueuePrompt.UpdateFor(GuildId); + _ = OnAutoPlay(CurrentTrack); return; } throw ex; @@ -164,10 +159,16 @@ namespace TomatenMusic.Music if (channel.Type == ChannelType.Stage) { - DiscordStageInstance stageInstance = await channel.GetStageInstanceAsync(); + DiscordStageInstance stageInstance; + try + { + stageInstance = await channel.GetStageInstanceAsync(); - if (stageInstance == null) + }catch (Exception ex) + { stageInstance = await channel.CreateStageInstanceAsync("Music"); + } + await stageInstance.Channel.UpdateCurrentUserVoiceStateAsync(false); } @@ -239,13 +240,13 @@ namespace TomatenMusic.Music 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)); + if (oldTrack.Provider != StreamProvider.YouTube) + newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Provider == StreamProvider.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); + await newTrack.PlayNow(this, withoutQueuePrepend: true); QueuePrompt.UpdateFor(GuildId); } diff --git a/TomatenMusicCore/Music/PlayerQueue.cs b/TomatenMusicCore/Music/PlayerQueue.cs index b3802f8..0a3d646 100644 --- a/TomatenMusicCore/Music/PlayerQueue.cs +++ b/TomatenMusicCore/Music/PlayerQueue.cs @@ -92,10 +92,11 @@ namespace TomatenMusic.Music } - public MusicActionResponse NextTrack(bool ignoreLoop = false) + public MusicActionResponse NextTrack(bool ignoreLoop = false, bool autoplay = false) { if (LastTrack != null) - PlayedTracks = new Queue(PlayedTracks.Prepend(new TomatenMusicTrack(LastTrack.WithPosition(TimeSpan.Zero)))); + if (LoopType != LoopType.NONE && Queue.Count == 0 || autoplay) + PlayedTracks = new Queue(PlayedTracks.Prepend(new TomatenMusicTrack(LastTrack.WithPosition(TimeSpan.Zero)))); switch (LoopType) { diff --git a/TomatenMusicCore/Prompt/Implementation/QueuePrompt.cs b/TomatenMusicCore/Prompt/Implementation/QueuePrompt.cs index fb087d8..0677813 100644 --- a/TomatenMusicCore/Prompt/Implementation/QueuePrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/QueuePrompt.cs @@ -98,7 +98,10 @@ namespace TomatenMusic.Prompt.Implementation await Player.RewindAsync(); }catch (Exception ex) { - + _ = args.Interaction.CreateResponseAsync( + DSharpPlus.InteractionResponseType.ChannelMessageWithSource, + new DiscordInteractionResponseBuilder() + .WithContent($"An Error occurred during this Interaction {ex.Message}")); } } } @@ -131,8 +134,18 @@ namespace TomatenMusic.Prompt.Implementation _ = args.Interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().WithContent("Please connect to the bots Channel to use this Interaction")); return; } + try + { + await Player.SkipAsync(); - await Player.SkipAsync(); + } + catch (Exception ex) + { + _ = args.Interaction.CreateResponseAsync( + DSharpPlus.InteractionResponseType.ChannelMessageWithSource, + new DiscordInteractionResponseBuilder() + .WithContent($"An Error occurred during this Interaction {ex.Message}")); + } System.Timers.Timer timer = new System.Timers.Timer(800); timer.Elapsed += (s, args) =>