From 0ab009451f8ffe631ac7a668f2ff6cb5cbd940bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 00:02:37 +0100 Subject: [PATCH 1/8] - fixed not being able to play file urls - fixed bot crashing after trying to display null value to current song embed --- TomatenMusic/config.json | 12 ++++++------ .../{Music => Services}/TrackProvider.cs | 2 ++ TomatenMusicCore/TomatenMusicBot.cs | 13 ++++--------- TomatenMusicCore/Util/Common.cs | 9 +++++---- 4 files changed, 17 insertions(+), 19 deletions(-) rename TomatenMusicCore/{Music => Services}/TrackProvider.cs (96%) diff --git a/TomatenMusic/config.json b/TomatenMusic/config.json index 650b90c..a61ca54 100644 --- a/TomatenMusic/config.json +++ b/TomatenMusic/config.json @@ -1,8 +1,8 @@ { - "TOKEN": "YOUR_BOT_TOKEN", - "LavaLinkPassword": " ", - "SpotifyClientId": " ", - "SpotifyClientSecret": " ", - "YoutubeApiKey": " " - + "TOKEN": "ODQwNjQ5NjU1MTAwMjQzOTY4.YJbSAA.Y0AiiFVhKLXs4b487JvobxuVk_s", + "LavaLinkPassword": "SGWaldsolms9", + "SpotifyClientId": "14b77fa47f2f492db58cbdca8f1e5d9c", + "SpotifyClientSecret": "c247625f0cfe4b72a1faa01b7c5b8eea", + "YoutubeApiKey": "AIzaSyBIcTl9JQ9jF412mX0Wfp_3Y-4a-V0SASQ" } + diff --git a/TomatenMusicCore/Music/TrackProvider.cs b/TomatenMusicCore/Services/TrackProvider.cs similarity index 96% rename from TomatenMusicCore/Music/TrackProvider.cs rename to TomatenMusicCore/Services/TrackProvider.cs index 652ca9e..3c5f389 100644 --- a/TomatenMusicCore/Music/TrackProvider.cs +++ b/TomatenMusicCore/Services/TrackProvider.cs @@ -41,6 +41,8 @@ namespace TomatenMusic.Music else loadResult = await _audioService.LoadTracksAsync(query, SearchMode.YouTube); + if (uri != null && uri.AbsolutePath.Contains(".")) + return await SearchAsync(uri); if (loadResult.LoadType == TrackLoadType.LoadFailed) throw new ArgumentException("Track loading failed"); diff --git a/TomatenMusicCore/TomatenMusicBot.cs b/TomatenMusicCore/TomatenMusicBot.cs index 7180ce7..f110dd6 100644 --- a/TomatenMusicCore/TomatenMusicBot.cs +++ b/TomatenMusicCore/TomatenMusicBot.cs @@ -126,19 +126,14 @@ namespace TomatenMusic { Services = ServiceProvider }); - /* + slash.RegisterCommands(888493810554900491); slash.RegisterCommands(888493810554900491); slash.RegisterCommands(888493810554900491); - slash.RegisterCommands(835089895092387872); - slash.RegisterCommands(835089895092387872); - slash.RegisterCommands(835089895092387872); - */ - - slash.RegisterCommands(); - slash.RegisterCommands(); - slash.RegisterCommands(); + //slash.RegisterCommands(); + //slash.RegisterCommands(); + //slash.RegisterCommands(); await client.StartAsync(); client.Ready += Client_Ready; diff --git a/TomatenMusicCore/Util/Common.cs b/TomatenMusicCore/Util/Common.cs index 4a21db9..193e26d 100644 --- a/TomatenMusicCore/Util/Common.cs +++ b/TomatenMusicCore/Util/Common.cs @@ -258,17 +258,18 @@ namespace TomatenMusic.Util FullTrackContext context = (FullTrackContext)track.Context; string progressBar = $"|{ProgressBar((int)player.Position.Position.TotalSeconds, (int)track.Duration.TotalSeconds)}|\n [{Common.GetTimestamp(player.Position.Position)}/{Common.GetTimestamp(track.Duration)}]"; - - builder.WithAuthor(track.Author, context.YoutubeAuthorUri.ToString(), context.YoutubeAuthorThumbnail.ToString()); + + builder.WithAuthor(track.Author); builder.WithTitle(track.Title); - builder.WithUrl(context.YoutubeUri); - builder.WithImageUrl(context.YoutubeThumbnail); + builder.WithUrl(track.Source); builder.WithColor(player.State == PlayerState.Paused ? DiscordColor.Orange : DiscordColor.Green); builder.AddField("Length", Common.GetTimestamp(track.Duration), true); builder.AddField("Loop", player.PlayerQueue.LoopType.ToString(), true); builder.AddField("Progress", progressBar, true); if (!context.IsFile) { + builder.WithAuthor(track.Author, context.YoutubeAuthorUri.ToString(), context.YoutubeAuthorThumbnail.ToString()); + builder.WithImageUrl(context.YoutubeThumbnail); builder.AddField("Views", $"{context.YoutubeViews:N0} Views", true); builder.AddField("Rating", $"{context.YoutubeLikes:N0} 👍", true); builder.AddField("Upload Date", $"{context.YoutubeUploadDate.ToString("dd. MMMM, yyyy")}", true); From 6258c943c59814b7dca41fb50d6a62829bcd8548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 12:18:26 +0100 Subject: [PATCH 2/8] Update GitVersion.yml --- GitVersion.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GitVersion.yml b/GitVersion.yml index ed16160..f55a7e2 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,5 +1,9 @@ mode: ContinuousDelivery -branches: {} +branches: + develop: + increment: None + main: + increment: None ignore: sha: [] merge-message-formats: {} From cce7b69871d0c2764da8e65ef767e157d6fc65e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 12:21:55 +0100 Subject: [PATCH 3/8] fix MusicBot --- TomatenMusic/config.json | 10 +++++----- TomatenMusicCore/TomatenMusicBot.cs | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/TomatenMusic/config.json b/TomatenMusic/config.json index a61ca54..f0808c5 100644 --- a/TomatenMusic/config.json +++ b/TomatenMusic/config.json @@ -1,8 +1,8 @@ { - "TOKEN": "ODQwNjQ5NjU1MTAwMjQzOTY4.YJbSAA.Y0AiiFVhKLXs4b487JvobxuVk_s", - "LavaLinkPassword": "SGWaldsolms9", - "SpotifyClientId": "14b77fa47f2f492db58cbdca8f1e5d9c", - "SpotifyClientSecret": "c247625f0cfe4b72a1faa01b7c5b8eea", - "YoutubeApiKey": "AIzaSyBIcTl9JQ9jF412mX0Wfp_3Y-4a-V0SASQ" + "TOKEN": " ", + "LavaLinkPassword": " ", + "SpotifyClientId": " ", + "SpotifyClientSecret": " ", + "YoutubeApiKey": " " } diff --git a/TomatenMusicCore/TomatenMusicBot.cs b/TomatenMusicCore/TomatenMusicBot.cs index f110dd6..33f4562 100644 --- a/TomatenMusicCore/TomatenMusicBot.cs +++ b/TomatenMusicCore/TomatenMusicBot.cs @@ -127,13 +127,13 @@ namespace TomatenMusic Services = ServiceProvider }); - slash.RegisterCommands(888493810554900491); - slash.RegisterCommands(888493810554900491); - slash.RegisterCommands(888493810554900491); + //slash.RegisterCommands(888493810554900491); + //slash.RegisterCommands(888493810554900491); + //slash.RegisterCommands(888493810554900491); - //slash.RegisterCommands(); - //slash.RegisterCommands(); - //slash.RegisterCommands(); + slash.RegisterCommands(); + slash.RegisterCommands(); + slash.RegisterCommands(); await client.StartAsync(); client.Ready += Client_Ready; From 949958641e8cb5d932f4550d4b4c1af339aa4b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 12:32:57 +0100 Subject: [PATCH 4/8] GitVersion update --- GitVersion.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index f55a7e2..ad1bdae 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,9 +1,29 @@ mode: ContinuousDelivery -branches: - develop: - increment: None +branches: main: + regex: ^master$|^main$ + mode: ContinuousDelivery + tag: '' increment: None + prevent-increment-of-merged-branch-version: true + track-merge-target: false + source-branches: [ 'develop', 'release' ] + tracks-release-branches: false + is-release-branch: true + is-mainline: true + pre-release-weight: 55000 + develop: + regex: ^dev(elop)?(ment)?$ + mode: ContinuousDeployment + tag: pre + increment: None + prevent-increment-of-merged-branch-version: false + track-merge-target: true + source-branches: [] + tracks-release-branches: true + is-release-branch: false + is-mainline: false + pre-release-weight: 0 ignore: sha: [] merge-message-formats: {} From ac41d73518214c4bde5f719f99699a88c485b4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 13:10:36 +0100 Subject: [PATCH 5/8] test --- TomatenMusic/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TomatenMusic/config.json b/TomatenMusic/config.json index f0808c5..ae2595d 100644 --- a/TomatenMusic/config.json +++ b/TomatenMusic/config.json @@ -1,5 +1,5 @@ { - "TOKEN": " ", + "TOKEN": "Bot_Token", "LavaLinkPassword": " ", "SpotifyClientId": " ", "SpotifyClientSecret": " ", From a41c73de5d8fe08e3a7c831228e5bdc378822987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 13:17:30 +0100 Subject: [PATCH 6/8] test2 --- TomatenMusicCore/TomatenMusicBot.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TomatenMusicCore/TomatenMusicBot.cs b/TomatenMusicCore/TomatenMusicBot.cs index 33f4562..6b62e2c 100644 --- a/TomatenMusicCore/TomatenMusicBot.cs +++ b/TomatenMusicCore/TomatenMusicBot.cs @@ -114,7 +114,6 @@ namespace TomatenMusic { await BuildServiceProvider(); - //_ = _host.StartAsync(); _host.Start(); var client = ServiceProvider.GetRequiredService(); From 2b9986a7fae481c3776bcff8dab38cbf1dd94bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 13:23:52 +0100 Subject: [PATCH 7/8] test 3 --- TomatenMusicCore/TomatenMusicBot.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TomatenMusicCore/TomatenMusicBot.cs b/TomatenMusicCore/TomatenMusicBot.cs index 6b62e2c..ab3b9b0 100644 --- a/TomatenMusicCore/TomatenMusicBot.cs +++ b/TomatenMusicCore/TomatenMusicBot.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging; using DSharpPlus; using DSharpPlus.EventArgs; using DSharpPlus.Entities; -using DSharpPlus.Net; using System.Linq; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.EventArgs; @@ -77,7 +76,6 @@ namespace TomatenMusic }) - // Lavalink .AddSingleton() .AddSingleton() .AddSingleton(new InactivityTrackingOptions From c9c5a4f8924640374c7c4abab2f45dacf0d12493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Sun, 20 Mar 2022 15:06:38 +0100 Subject: [PATCH 8/8] - fix spotify playlist playback - fix spotify playlist embed failing due to too long description - fix not removing current playlist after adding another - exchanged Description and Tracks field in playlist embed --- TomatenMusicCore/Commands/PlayCommandGroup.cs | 6 ++-- TomatenMusicCore/Music/PlayerQueue.cs | 4 ++- TomatenMusicCore/Services/SpotifyService.cs | 32 +++++++++++++------ TomatenMusicCore/Services/YoutubeService.cs | 9 ++++-- TomatenMusicCore/TomatenMusicBot.cs | 2 +- TomatenMusicCore/Util/Common.cs | 20 +++++++----- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/TomatenMusicCore/Commands/PlayCommandGroup.cs b/TomatenMusicCore/Commands/PlayCommandGroup.cs index 389dff6..bf8799f 100644 --- a/TomatenMusicCore/Commands/PlayCommandGroup.cs +++ b/TomatenMusicCore/Commands/PlayCommandGroup.cs @@ -206,14 +206,14 @@ namespace TomatenMusic.Commands } } - try + try { if (response.isPlaylist) { LavalinkPlaylist playlist = response.Playlist; await player.PlayPlaylistAsync(playlist); - _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( + await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( Common.AsEmbed(playlist) )); @@ -231,7 +231,7 @@ namespace TomatenMusic.Commands catch (Exception ex) { await ctx.EditResponseAsync(new DiscordWebhookBuilder() - .WithContent($"❌ An error occured while playing your Track: ``{ex.Message}``") + .WithContent($"❌ An error occured while playing your Track: ``{ex.Message}``, ```{ex.StackTrace}```") ); return; } diff --git a/TomatenMusicCore/Music/PlayerQueue.cs b/TomatenMusicCore/Music/PlayerQueue.cs index ce90a26..9ab8453 100644 --- a/TomatenMusicCore/Music/PlayerQueue.cs +++ b/TomatenMusicCore/Music/PlayerQueue.cs @@ -40,8 +40,10 @@ namespace TomatenMusic.Music { return Task.Run(() => { - if (CurrentPlaylist == null) + if (CurrentPlaylist == null && Queue.Count == 0) CurrentPlaylist = playlist; + else + CurrentPlaylist = null; _logger.LogInformation("Queued Playlist {0}", playlist.Name); foreach (LavalinkTrack track in playlist.Tracks) diff --git a/TomatenMusicCore/Services/SpotifyService.cs b/TomatenMusicCore/Services/SpotifyService.cs index 9fff28d..fe36a3e 100644 --- a/TomatenMusicCore/Services/SpotifyService.cs +++ b/TomatenMusicCore/Services/SpotifyService.cs @@ -70,7 +70,7 @@ namespace TomatenMusic.Services if (track == null) throw new ArgumentException("This Spotify Track was not found on Youtube"); - tracks.Add(await FullTrackContext.PopulateAsync(track, sTrack.Uri)); + tracks.Add(await FullTrackContext.PopulateAsync(track, sTrack.Uri.Replace("spotify:track:", ""))); } Uri uri; Uri.TryCreate(url, UriKind.Absolute, out uri); @@ -98,7 +98,7 @@ namespace TomatenMusic.Services if (track == null) throw new ArgumentException("This Spotify Track was not found on Youtube"); - tracks.Add(await FullTrackContext.PopulateAsync(track, fullTrack.Uri)); + tracks.Add(await FullTrackContext.PopulateAsync(track, fullTrack.Uri.Replace("spotify:track:", ""))); } } @@ -115,23 +115,35 @@ namespace TomatenMusic.Services public async Task PopulateSpotifyPlaylistAsync(SpotifyPlaylist playlist) { var list = await this.Playlists.Get(playlist.Identifier); - playlist.Description = list.Description; - playlist.AuthorUri = new Uri(list.Owner.Uri); + string desc = list.Description; + + playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " "); + if (playlist.Description.Length < 2) + playlist.Description = "None"; + + playlist.AuthorUri = new Uri($"https://open.spotify.com/user/{list.Owner.Id}"); playlist.AuthorName = list.Owner.DisplayName; playlist.Followers = list.Followers.Total; - playlist.Url = new Uri(list.Uri); - playlist.AuthorThumbnail = new Uri(list.Owner.Images.First().Url); + playlist.Url = new Uri($"https://open.spotify.com/playlist/{playlist.Identifier}"); + try + { + playlist.AuthorThumbnail = new Uri(list.Owner.Images.First().Url); + } + catch (Exception ex) { } + return playlist; } public async Task PopulateSpotifyAlbumAsync(SpotifyPlaylist playlist) { var list = await this.Albums.Get(playlist.Identifier); - playlist.Description = list.Label; - playlist.AuthorUri = new Uri(list.Artists.First().Uri); + string desc = list.Label; + + playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " "); + playlist.AuthorUri = new Uri($"https://open.spotify.com/user/{list.Artists.First().Uri}"); playlist.AuthorName = list.Artists.First().Name; playlist.Followers = list.Popularity; - playlist.Url = new Uri(list.Uri); + playlist.Url = new Uri($"https://open.spotify.com/album/{playlist.Identifier}"); return playlist; } @@ -147,7 +159,7 @@ namespace TomatenMusic.Services context.SpotifyAlbum = spotifyTrack.Album; context.SpotifyArtists = spotifyTrack.Artists; context.SpotifyPopularity = spotifyTrack.Popularity; - context.SpotifyUri = new Uri(spotifyTrack.Uri); + context.SpotifyUri = new Uri($"https://open.spotify.com/track/{context.SpotifyIdentifier}"); track.Context = context; return track; diff --git a/TomatenMusicCore/Services/YoutubeService.cs b/TomatenMusicCore/Services/YoutubeService.cs index 12bf269..1adfd6a 100644 --- a/TomatenMusicCore/Services/YoutubeService.cs +++ b/TomatenMusicCore/Services/YoutubeService.cs @@ -39,7 +39,9 @@ namespace TomatenMusic.Services context.YoutubeAuthorSubs = (ulong) channel.Statistics.SubscriberCount; context.YoutubeAuthorThumbnail = new Uri(channel.Snippet.Thumbnails.High.Url); context.YoutubeAuthorUri = new Uri($"https://www.youtube.com/channel/{channel.Id}"); - context.YoutubeDescription = video.Snippet.Description; + string desc = video.Snippet.Description; + + context.YoutubeDescription = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " "); if (video.Statistics.LikeCount != null) context.YoutubeLikes = (ulong) video.Statistics.LikeCount; context.YoutubeTags = video.Snippet.Tags; @@ -66,7 +68,10 @@ namespace TomatenMusic.Services string desc = list.Snippet.Description; - playlist.Description = desc.Substring(0, Math.Min(desc.Length, 4092)) + (desc.Length > 4092 ? "..." : " "); + playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " "); + if (playlist.Description == "") + playlist.Description = "None"; + playlist.Thumbnail = new Uri(list.Snippet.Thumbnails.High.Url); playlist.CreationTime = (DateTime)list.Snippet.PublishedAt; playlist.YoutubeItem = list; diff --git a/TomatenMusicCore/TomatenMusicBot.cs b/TomatenMusicCore/TomatenMusicBot.cs index ab3b9b0..c460998 100644 --- a/TomatenMusicCore/TomatenMusicBot.cs +++ b/TomatenMusicCore/TomatenMusicBot.cs @@ -186,7 +186,7 @@ namespace TomatenMusic if (e.Exception is NotFoundException) logger.LogDebug($"{ ((NotFoundException)e.Exception).JsonMessage }"); if (e.Exception is BadRequestException) - logger.LogDebug($"{ ((BadRequestException)e.Exception).JsonMessage }"); + logger.LogInformation($"{ ((BadRequestException)e.Exception).Errors }"); return Task.CompletedTask; } diff --git a/TomatenMusicCore/Util/Common.cs b/TomatenMusicCore/Util/Common.cs index 193e26d..8fbcdd3 100644 --- a/TomatenMusicCore/Util/Common.cs +++ b/TomatenMusicCore/Util/Common.cs @@ -104,9 +104,9 @@ namespace TomatenMusic.Util .WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString()) .WithTitle(playlist.Name) .WithUrl(playlist.Url) - .WithDescription(playlist.Description) + .WithDescription(TrackListString(playlist.Tracks)) .WithImageUrl(youtubePlaylist.Thumbnail) - .AddField("Tracks", TrackListString(playlist.Tracks), false) + .AddField("Description", playlist.Description, false) .AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true) .AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true) .AddField("Create Date", $"{youtubePlaylist.CreationTime:dd. MMMM, yyyy}", true); @@ -115,17 +115,21 @@ namespace TomatenMusic.Util { SpotifyPlaylist spotifyPlaylist = (SpotifyPlaylist)playlist; builder - .WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), spotifyPlaylist.AuthorThumbnail.ToString()) .WithTitle(playlist.Name) .WithUrl(playlist.Url) - .WithDescription(playlist.Description) - .AddField("Tracks", TrackListString(playlist.Tracks), false) + .WithDescription(TrackListString(playlist.Tracks)) + .AddField("Description", playlist.Description, false) .AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true) .AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true) .AddField("Spotify Followers", $"{spotifyPlaylist.Followers:N0}", true); + if (spotifyPlaylist.AuthorThumbnail != null) + { + builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), spotifyPlaylist.AuthorThumbnail.ToString()); + }else + builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString()); } - return builder; + return builder.Build(); } public static DiscordEmbed GetQueueEmbed(GuildPlayer player) @@ -161,9 +165,9 @@ namespace TomatenMusic.Util foreach (LavalinkTrack track in tracks) { FullTrackContext context = (FullTrackContext)track.Context; - if (count > 15) + if (count > 10) { - builder.Append(String.Format("***And {0} more...***", tracks.Count() - 15)); + builder.Append(String.Format("***And {0} more...***", tracks.Count() - 10)); break; }