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] - 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);