From 4846a15801769f65eb69c864ca3c4b14e8f452dc Mon Sep 17 00:00:00 2001 From: samvaio Date: Fri, 23 Dec 2016 03:59:25 +0530 Subject: [PATCH 1/3] few fixes --- .../Modules/Games/Commands/Acropobia.cs | 2 +- src/NadekoBot/Modules/Music/Classes/Song.cs | 4 +- src/NadekoBot/Modules/Music/Music.cs | 38 ++++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index 795c0f63..730a3d27 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -130,7 +130,7 @@ namespace NadekoBot.Modules.Games return; } - var i = 0; + //var i = 0; if (submissions.Count == 0) { await channel.SendErrorAsync("Acrophobia", "Game ended with no submissions."); diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index 4ed163fa..723c8466 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -49,6 +49,8 @@ namespace NadekoBot.Modules.Music.Classes public string PrettyName => $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**"; public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}"; + + public string PTT => $"{PrettyTotalTime}"; public string PrettyFullName => $"{PrettyName}\n\t\t*{PrettyInfo}*"; @@ -59,7 +61,7 @@ namespace NadekoBot.Modules.Music.Classes if (TotalTime == TimeSpan.Zero) return "(?)"; else if (TotalTime == TimeSpan.MaxValue) - return "**∞**"; + return "∞"; else return TotalTime.ToString(@"mm\:ss"); } diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index afc42496..1d3e7fba 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -15,7 +15,7 @@ using Newtonsoft.Json.Linq; using System.Collections.Generic; using NadekoBot.Services.Database.Models; using System.Text.RegularExpressions; -using System.Threading; +//using System.Threading; namespace NadekoBot.Modules.Music { @@ -216,14 +216,26 @@ namespace NadekoBot.Modules.Music var currentSong = musicPlayer.CurrentSong; if (currentSong == null) return; + try { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } var videoid = Regex.Match(currentSong.SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+"); var embed = new EmbedBuilder() .WithAuthor(eab => eab.WithName("Now Playing") .WithMusicIcon()) - .WithDescription(currentSong.PrettyName) - .WithFooter(ef => ef.WithText(currentSong.PrettyCurrentTime + "/" + currentSong.PrettyInfo)) + .WithTitle($"{currentSong.SongInfo.Title}") + .WithDescription(currentSong.PrettyCurrentTime + "/" + currentSong.PTT) + .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}")) .WithOkColor(); + if (currentSong.SongInfo.Provider.Equals("YouTube", StringComparison.OrdinalIgnoreCase)) + { + embed.WithThumbnail(tn => tn.Url = $"https://img.youtube.com/vi/{videoid}/0.jpg"); + embed.WithUrl($"{currentSong.SongInfo.Query}"); + } + else if (currentSong.SongInfo.Provider.Equals("SoundCloud", StringComparison.OrdinalIgnoreCase)) + { + embed.WithThumbnail(tn => tn.Url = $"{currentSong.SongInfo.AlbumArt}"); + embed.WithUrl($"{currentSong.SongInfo.Query}"); + } await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } @@ -313,7 +325,8 @@ namespace NadekoBot.Modules.Music var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); - var cancelSource = new CancellationTokenSource(); + + /*var cancelSource = new CancellationTokenSource(); var tasks = Task.WhenAll(idArray.Select(async id => { @@ -327,7 +340,17 @@ namespace NadekoBot.Modules.Music catch { try { cancelSource.Cancel(); } catch { } } })); - await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token)); + await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));*/ + + foreach (var id in idArray) + { + try + { + await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, id, true).ConfigureAwait(false); + } + catch (SongNotFoundException) { } + catch { break; } + } await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); } @@ -824,6 +847,7 @@ namespace NadekoBot.Modules.Music { if (finishedMessage != null) finishedMessage.DeleteAfter(0); + finishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon()) .WithDescription(song.PrettyName) @@ -839,8 +863,10 @@ namespace NadekoBot.Modules.Music catch { } }; IUserMessage playingMessage = null; + mp.OnStarted += async (player, song) => { + try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } try { if (playingMessage != null) @@ -870,7 +896,7 @@ namespace NadekoBot.Modules.Music pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); } if (pauseMessage != null) - pauseMessage.DeleteAfter(15); + pauseMessage.DeleteAfter(5); } catch { } }; From f5b0407392a7c9462dc90019ff4411c5a8267496 Mon Sep 17 00:00:00 2001 From: samvaio Date: Fri, 23 Dec 2016 08:06:54 +0530 Subject: [PATCH 2/3] Reverted the revert --- src/NadekoBot/Modules/Music/Music.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 1d3e7fba..d1d7f7ff 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -15,7 +15,7 @@ using Newtonsoft.Json.Linq; using System.Collections.Generic; using NadekoBot.Services.Database.Models; using System.Text.RegularExpressions; -//using System.Threading; +using System.Threading; namespace NadekoBot.Modules.Music { @@ -326,7 +326,7 @@ namespace NadekoBot.Modules.Music var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); - /*var cancelSource = new CancellationTokenSource(); + var cancelSource = new CancellationTokenSource(); var tasks = Task.WhenAll(idArray.Select(async id => { @@ -340,9 +340,9 @@ namespace NadekoBot.Modules.Music catch { try { cancelSource.Cancel(); } catch { } } })); - await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));*/ + await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token)); - foreach (var id in idArray) + /*foreach (var id in idArray) { try { @@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Music } catch (SongNotFoundException) { } catch { break; } - } + }*/ await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); } @@ -937,4 +937,4 @@ namespace NadekoBot.Modules.Music } } } -} \ No newline at end of file +} From ca658ae55ca18e4e5f0a51d1ed67ace2bf66607f Mon Sep 17 00:00:00 2001 From: samvaio Date: Fri, 23 Dec 2016 09:20:49 +0530 Subject: [PATCH 3/3] volume added to playing --- src/NadekoBot/Modules/Music/Music.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index d1d7f7ff..3a005a71 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -867,6 +867,9 @@ namespace NadekoBot.Modules.Music mp.OnStarted += async (player, song) => { try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } + var sender = player as MusicPlayer; + if (sender == null) + return; try { if (playingMessage != null) @@ -874,8 +877,8 @@ namespace NadekoBot.Modules.Music playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) - .WithDescription(song.PrettyName) - .WithFooter(ef => ef.WithText(song.PrettyInfo)) + .WithDescription($"{song.PrettyName}") + .WithFooter(ef => ef.WithText($"🔉 {(int)(sender.Volume * 100)}% | {song.PrettyInfo}")) .Build()) .ConfigureAwait(false); } @@ -937,4 +940,4 @@ namespace NadekoBot.Modules.Music } } } -} +} \ No newline at end of file