From 021528afd1a783e45c9c30435646a9afc25af778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Thu, 24 Mar 2022 21:46:22 +0100 Subject: [PATCH] Fix BasicTrackInfo having wrong TrackID Add Character Limit to TrackList Method to fix tracklists being to big for messages --- TomatenMusic/Models/BasicTrackInfo.cs | 2 +- .../Implementation/SongListActionPrompt.cs | 2 +- .../Implementation/SongSelectorPrompt.cs | 2 +- .../Prompt/Model/DiscordPromptBase.cs | 1 + .../Prompt/Option/IPromptOption.cs | 3 --- TomatenMusicCore/Util/Common.cs | 20 +++++++++++-------- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/TomatenMusic/Models/BasicTrackInfo.cs b/TomatenMusic/Models/BasicTrackInfo.cs index dd245ac..50efc3c 100644 --- a/TomatenMusic/Models/BasicTrackInfo.cs +++ b/TomatenMusic/Models/BasicTrackInfo.cs @@ -27,7 +27,7 @@ namespace TomatenMusic_Api.Models Name = track.Title; Platform = ctx.SpotifyIdentifier == null ? TrackPlatform.YOUTUBE : TrackPlatform.SPOTIFY; - YoutubeId = track.Identifier; + YoutubeId = track.TrackIdentifier; SpotifyId = ctx.SpotifyIdentifier; URL = ctx.YoutubeUri; } diff --git a/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs b/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs index 776adf6..e05fd59 100644 --- a/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs @@ -32,7 +32,7 @@ namespace TomatenMusic.Prompt.Implementation DiscordEmbedBuilder builder = new DiscordEmbedBuilder() .WithTitle("What do you want to do with these Tracks?"); - builder.WithDescription(Common.TrackListString(Tracks)); + builder.WithDescription(Common.TrackListString(Tracks, 1000)); return Task.FromResult(new DiscordMessageBuilder().WithEmbed(builder.Build())); } diff --git a/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs b/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs index 2f075c4..5baf916 100644 --- a/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs @@ -87,7 +87,7 @@ namespace TomatenMusic.Prompt.Implementation { builder.WithTitle(Title); - builder.WithDescription(Common.TrackListString(PageManager.GetPage(CurrentPage))); + builder.WithDescription(Common.TrackListString(PageManager.GetPage(CurrentPage), 4000)); List embeds = new List(); embeds.Add(builder.Build()); diff --git a/TomatenMusicCore/Prompt/Model/DiscordPromptBase.cs b/TomatenMusicCore/Prompt/Model/DiscordPromptBase.cs index 8a214d4..e3fa18b 100644 --- a/TomatenMusicCore/Prompt/Model/DiscordPromptBase.cs +++ b/TomatenMusicCore/Prompt/Model/DiscordPromptBase.cs @@ -164,6 +164,7 @@ namespace TomatenMusic.Prompt.Model _client = client.GetShard((ulong)interaction.GuildId); _client.ComponentInteractionCreated += Discord_ComponentInteractionCreated; + ActivePrompts.Add(this); AddGuids(); DiscordWebhookBuilder builder = await GetWebhookMessageAsync(); diff --git a/TomatenMusicCore/Prompt/Option/IPromptOption.cs b/TomatenMusicCore/Prompt/Option/IPromptOption.cs index ed77dd2..26e85d1 100644 --- a/TomatenMusicCore/Prompt/Option/IPromptOption.cs +++ b/TomatenMusicCore/Prompt/Option/IPromptOption.cs @@ -19,8 +19,5 @@ namespace TomatenMusic.Prompt.Option public Func> UpdateMethod { get; set; } public Func Run { get; set; } - - - } } diff --git a/TomatenMusicCore/Util/Common.cs b/TomatenMusicCore/Util/Common.cs index 531cf59..6f2048d 100644 --- a/TomatenMusicCore/Util/Common.cs +++ b/TomatenMusicCore/Util/Common.cs @@ -104,7 +104,7 @@ namespace TomatenMusic.Util builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString()); builder.WithTitle(playlist.Name); builder.WithUrl(playlist.Url); - builder.WithDescription(TrackListString(playlist.Tracks)); + builder.WithDescription(TrackListString(playlist.Tracks, 4000)); builder.WithImageUrl(youtubePlaylist.Thumbnail); builder.AddField("Description", playlist.Description, false); builder.AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true); @@ -117,7 +117,7 @@ namespace TomatenMusic.Util builder.WithTitle(playlist.Name); builder.WithUrl(playlist.Url); - builder.WithDescription(TrackListString(playlist.Tracks)); + builder.WithDescription(TrackListString(playlist.Tracks, 4000)); builder.AddField("Description", playlist.Description, false); builder.AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true); builder.AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true); @@ -136,7 +136,7 @@ namespace TomatenMusic.Util { DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); - builder.WithDescription(TrackListString(player.PlayerQueue.Queue)); + builder.WithDescription(TrackListString(player.PlayerQueue.Queue, 4000)); builder.WithTitle("Current Queue"); builder.WithAuthor($"{player.PlayerQueue.Queue.Count} Songs"); @@ -154,24 +154,28 @@ namespace TomatenMusic.Util builder.AddField("Current Playlist", $"[{player.PlayerQueue.CurrentPlaylist.Name}]({player.PlayerQueue.CurrentPlaylist.Url})", true); if (player.PlayerQueue.PlayedTracks.Any()) - builder.AddField("History", TrackListString(player.PlayerQueue.PlayedTracks), true); + builder.AddField("History", TrackListString(player.PlayerQueue.PlayedTracks, 1000), true); return builder; } - public static string TrackListString(IEnumerable tracks) + public static string TrackListString(IEnumerable tracks, int maxCharacters) { StringBuilder builder = new StringBuilder(); + string lastString = " "; int count = 1; foreach (LavalinkTrack track in tracks) { - FullTrackContext context = (FullTrackContext)track.Context; - if (count > 10) + if (builder.ToString().Length > maxCharacters) { - builder.Append(String.Format("***And {0} more...***", tracks.Count() - 10)); + builder = new StringBuilder(lastString); + builder.Append(String.Format("***And {0} more...***", tracks.Count() - count)); break; } + FullTrackContext context = (FullTrackContext)track.Context; + + lastString = builder.ToString(); builder.Append(count).Append(": ").Append($"[{track.Title}]({context.YoutubeUri})").Append(" [").Append(Common.GetTimestamp(track.Duration)).Append("] | "); builder.Append($"[{track.Author}]({context.YoutubeAuthorUri})").Append("\n\n"); count++;