From 90fec3d0da15c5129aaaace2e33671cc04d86758 Mon Sep 17 00:00:00 2001 From: samvaio Date: Wed, 14 Dec 2016 20:36:53 +0530 Subject: [PATCH 1/6] reverted back to actual with keep slight changes --- src/NadekoBot/Modules/Music/Classes/Song.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index 78ed4ffd..a4447a5a 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -12,7 +12,7 @@ using System.Threading; using System.Threading.Tasks; using VideoLibrary; -namespace NadekoBot.Modules.Music.Classes//{(SongInfo.Provider ?? "-")} +namespace NadekoBot.Modules.Music.Classes { public class SongInfo { @@ -27,8 +27,10 @@ namespace NadekoBot.Modules.Music.Classes//{(SongInfo.Provider ?? "-")} } public class Song { + public StreamState State { get; set; } public string PrettyName => - $"{SongInfo.Title.TrimTo(70)}"; + $"**{SongInfo.Title.TrimTo(55)} `{(SongInfo.Provider ?? "-")} by {QueuerName}`**"; + //$"{SongInfo.Title.TrimTo(70)}"; public SongInfo SongInfo { get; } public MusicPlayer MusicPlayer { get; set; } @@ -38,7 +40,6 @@ namespace NadekoBot.Modules.Music.Classes//{(SongInfo.Provider ?? "-")} public string PrettyProvider => $"{(SongInfo.Provider ?? "No Provider")}"; - public StreamState State { get; set; } public string PrettyCurrentTime() { From 1c16838f37a4b49925284ea8f44eadabb9747b31 Mon Sep 17 00:00:00 2001 From: samvaio Date: Wed, 14 Dec 2016 21:32:51 +0530 Subject: [PATCH 2/6] swapped author with playtime --- src/NadekoBot/Modules/Music/Music.cs | 124 +++++++++++++++------------ 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index a7250d80..95b67cef 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -96,9 +96,9 @@ namespace NadekoBot.Modules.Music return; musicPlayer.TogglePause(); if (musicPlayer.Paused) - await channel.SendMessageAsync("🎵`Music Player paused.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Music Player **paused**.").ConfigureAwait(false); else - await channel.SendMessageAsync("🎵`Music Player unpaused.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Music Player **unpaused**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -137,7 +137,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) { - await channel.SendMessageAsync("🎵 No active music player.").ConfigureAwait(false); + await channel.SendErrorAsync("🎵 No active music player.").ConfigureAwait(false); return; } if (page <= 0) @@ -152,12 +152,13 @@ namespace NadekoBot.Modules.Music await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - var toSend = $"🎵`Now Playing` {currentSong.PrettyName} " + $"{currentSong.PrettyCurrentTime()}\n"; + //var toSend = $"🎵 Currently Playing {currentSong.PrettyName} " + $"`{currentSong.PrettyCurrentTime()}`\n"; + var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n"; if (musicPlayer.RepeatSong) toSend += "🔂"; else if (musicPlayer.RepeatPlaylist) toSend += "🔁"; - toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; + toSend += $" `{musicPlayer.Playlist.Count} tracks currently queued. Showing page {page}:` "; if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) toSend += "**Song queue is full!**\n"; else @@ -165,7 +166,7 @@ namespace NadekoBot.Modules.Music const int itemsPerPage = 15; int startAt = itemsPerPage * (page - 1); var number = 1 + startAt; - await channel.SendMessageAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); + await channel.SendConfirmAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -173,6 +174,7 @@ namespace NadekoBot.Modules.Music public async Task NowPlaying(IUserMessage umsg) { var channel = (ITextChannel)umsg.Channel; + MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; @@ -184,12 +186,13 @@ namespace NadekoBot.Modules.Music { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - var embed = new EmbedBuilder() - .WithAuthor(eab => eab.WithName("🎵 Now Playing")) - .WithTitle($"{currentSong.PrettyName}") - .WithDescription($"{currentSong.PrettyUser}") - .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyCurrentTime()}")) - .WithColor(NadekoBot.OkColor); + var embed = new EmbedBuilder() + .WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) + .WithTitle($"{currentSong.SongInfo.Title}") + .WithUrl($"{currentSong.SongInfo.Query}") + .WithDescription($"{currentSong.PrettyCurrentTime()}") + .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}")) + .WithColor(NadekoBot.OkColor); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } @@ -206,7 +209,7 @@ namespace NadekoBot.Modules.Music if (val < 0) return; var volume = musicPlayer.SetVolume(val); - await channel.SendMessageAsync($"🎵 `Volume set to {volume}%`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Volume set to {volume}%").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -217,7 +220,7 @@ namespace NadekoBot.Modules.Music if (val < 0 || val > 100) { - await channel.SendMessageAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); + await channel.SendErrorAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); return; } using (var uow = DbHandler.UnitOfWork()) @@ -225,7 +228,7 @@ namespace NadekoBot.Modules.Music uow.GuildConfigs.For(channel.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f; uow.Complete(); } - await channel.SendMessageAsync($"🎵 `Default volume set to {val}%`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Default volume set to {val}%").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -240,12 +243,12 @@ namespace NadekoBot.Modules.Music return; if (musicPlayer.Playlist.Count < 2) { - await channel.SendMessageAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); return; } musicPlayer.Shuffle(); - await channel.SendMessageAsync("🎵 `Songs shuffled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Songs shuffled.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -258,25 +261,25 @@ namespace NadekoBot.Modules.Music return; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 You need to be in a **voice channel** on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } var plId = (await NadekoBot.Google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault(); if (plId == null) { - await channel.SendMessageAsync("No search results for that query."); + await channel.SendErrorAsync("No search results for that query."); return; } var ids = await NadekoBot.Google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false); if (!ids.Any()) { - await channel.SendMessageAsync($"🎵 `Failed to find any songs.`").ConfigureAwait(false); + await channel.SendErrorAsync($"🎵 Failed to find any songs.").ConfigureAwait(false); return; } var idArray = ids as string[] ?? ids.ToArray(); var count = idArray.Length; var msg = - await channel.SendMessageAsync($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); foreach (var id in idArray) { try @@ -286,7 +289,7 @@ namespace NadekoBot.Modules.Music catch (SongNotFoundException) { } catch { break; } } - await msg.ModifyAsync(m => m.Content = "🎵 `Playlist queue complete.`").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -352,7 +355,7 @@ namespace NadekoBot.Modules.Music } catch { } } - await channel.SendMessageAsync("🎵 `Directory queue complete.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Directory queue complete.").ConfigureAwait(false); } catch { } } @@ -364,7 +367,7 @@ namespace NadekoBot.Modules.Music var channel = (ITextChannel)umsg.Channel; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, radio_link, musicType: MusicType.Radio).ConfigureAwait(false); @@ -418,7 +421,7 @@ namespace NadekoBot.Modules.Music return; var song = (musicPlayer.Playlist as List)?[num - 1]; musicPlayer.RemoveSongAt(num - 1); - await channel.SendMessageAsync($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Track {song.PrettyName} at position `#{num}` has been **removed**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -433,7 +436,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; musicPlayer.ClearQueue(); - await channel.SendMessageAsync($"🎵`Queue cleared!`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Queue cleared!").ConfigureAwait(false); return; } @@ -459,7 +462,7 @@ namespace NadekoBot.Modules.Music !int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 || n1 > playlist.Count || n2 > playlist.Count) { - await channel.SendMessageAsync("`Invalid input.`").ConfigureAwait(false); + await channel.SendErrorAsync("Invalid input.").ConfigureAwait(false); return; } @@ -467,8 +470,17 @@ namespace NadekoBot.Modules.Music playlist.Insert(n2 - 1, s); var nn1 = n2 < n1 ? n1 : n1 - 1; playlist.RemoveAt(nn1); + + var embed = new EmbedBuilder() + .WithTitle($"{s.SongInfo.Title.TrimTo(70)}") + .WithUrl($"{s.SongInfo.Query}") + .WithAuthor(eab => eab.WithName("Song Moved").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) + .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) + .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) + .WithColor(NadekoBot.OkColor); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); - await channel.SendMessageAsync($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); + //await channel.SendConfirmAsync($"🎵Moved {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); } @@ -484,7 +496,7 @@ namespace NadekoBot.Modules.Music return; } musicPlayer.MaxQueueSize = size; - await channel.SendMessageAsync($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`"); + await channel.SendConfirmAsync($"🎵 Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}."); } [NadekoCommand, Usage, Description, Aliases] @@ -499,9 +511,9 @@ namespace NadekoBot.Modules.Music if (currentSong == null) return; var currentValue = musicPlayer.ToggleRepeatSong(); - await channel.SendMessageAsync(currentValue ? - $"🎵🔂`Repeating track:`{currentSong.PrettyName}" : - $"🎵🔂`Current track repeat stopped.`") + await channel.SendConfirmAsync(currentValue ? + $"🔂 Repeating track: {currentSong.PrettyName}" : + $"🔂 Current track repeat stopped.") .ConfigureAwait(false); } @@ -514,7 +526,7 @@ namespace NadekoBot.Modules.Music if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; var currentValue = musicPlayer.ToggleRepeatPlaylist(); - await channel.SendMessageAsync($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🔁 Repeat playlist {(currentValue ? "**enabled**." : "**disabled**.")}").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -550,7 +562,7 @@ namespace NadekoBot.Modules.Music await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync(($"🎵 `Saved playlist as {name}.` `Id: {playlist.Id}`")).ConfigureAwait(false); + await channel.SendConfirmAsync(($"🎵 Saved playlist as **{name}**, ID: {playlist.Id}.")).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -567,11 +579,11 @@ namespace NadekoBot.Modules.Music if (mpl == null) { - await channel.SendMessageAsync("`Can't find playlist with that ID`").ConfigureAwait(false); + await channel.SendErrorAsync("Can't find playlist with that ID.").ConfigureAwait(false); return; } IUserMessage msg = null; - try { msg = await channel.SendMessageAsync($"`Attempting to load {mpl.Songs.Count} songs...`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { msg = await channel.SendMessageAsync($"🎶 Attempting to load **{mpl.Songs.Count}** songs...").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } foreach (var item in mpl.Songs) { var usr = (IGuildUser)umsg.Author; @@ -583,7 +595,7 @@ namespace NadekoBot.Modules.Music catch { break; } } if (msg != null) - await msg.ModifyAsync(m => m.Content = $"`Done loading playlist {mpl.Name}.`").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = $"✅ Done loading playlist **{mpl.Name}**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -602,9 +614,9 @@ namespace NadekoBot.Modules.Music playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); } - await channel.SendMessageAsync($@"`Page {num} of saved playlists` + await channel.SendConfirmAsync($@"🎶 **Page {num} of saved playlists:** -" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - `{r.Name}` by {r.Author} - **{r.Songs.Count}** songs"))).ConfigureAwait(false); +" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}** by __{r.Author}__ ({r.Songs.Count} songs)"))).ConfigureAwait(false); } //todo only author or owner @@ -636,9 +648,9 @@ namespace NadekoBot.Modules.Music } if (!success) - await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); + await channel.SendErrorAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); else - await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🗑 Playlist successfully **deleted**.").ConfigureAwait(false); } catch (Exception ex) { @@ -680,7 +692,7 @@ namespace NadekoBot.Modules.Music if (seconds.Length == 1) seconds = "0" + seconds; - await channel.SendMessageAsync($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false); + await channel.SendConfirmAsync($"Skipped to `{minutes}:{seconds}`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -701,12 +713,12 @@ namespace NadekoBot.Modules.Music var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1); if (selSong == null) { - await channel.SendMessageAsync("Could not select song, likely wrong index"); + await channel.SendErrorAsync("Could not select song, likely wrong index"); } else { - await channel.SendMessageAsync($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎶 Selected song **{selSong.SongInfo.Title}**: <{selSong.SongInfo.Query}>").ConfigureAwait(false); } } else @@ -714,7 +726,7 @@ namespace NadekoBot.Modules.Music var curSong = musicPlayer.CurrentSong; if (curSong == null) return; - await channel.SendMessageAsync($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎶 Current song **{curSong.SongInfo.Title}**: <{curSong.SongInfo.Query}>").ConfigureAwait(false); } } @@ -728,9 +740,9 @@ namespace NadekoBot.Modules.Music return; if (!musicPlayer.ToggleAutoplay()) - await channel.SendMessageAsync("🎶`Autoplay disabled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("❌ Autoplay disabled.").ConfigureAwait(false); else - await channel.SendMessageAsync("🎶`Autoplay enabled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("✅ Autoplay enabled.").ConfigureAwait(false); } public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) @@ -738,7 +750,7 @@ namespace NadekoBot.Modules.Music if (voiceCh == null || voiceCh.Guild != textCh.Guild) { if (!silent) - await textCh.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); + await textCh.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) @@ -752,10 +764,8 @@ namespace NadekoBot.Modules.Music vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } var mp = new MusicPlayer(voiceCh, vol); - - IUserMessage playingMessage = null; - IUserMessage lastFinishedMessage = null; + IUserMessage lastFinishedMessage = null; mp.OnCompleted += async (s, song) => { if (song.PrintStatusMessage) @@ -766,7 +776,7 @@ namespace NadekoBot.Modules.Music await lastFinishedMessage.DeleteAsync().ConfigureAwait(false); if (playingMessage != null) await playingMessage.DeleteAsync().ConfigureAwait(false); - try { lastFinishedMessage = await textCh.SendMessageAsync($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false); } catch { } + try { lastFinishedMessage = await textCh.SendConfirmAsync($"🎵 Finished {song.PrettyName}").ConfigureAwait(false); } catch { } if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") { await QueueSong(queuer.Guild.GetCurrentUser(), textCh, voiceCh, (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false); @@ -783,8 +793,8 @@ namespace NadekoBot.Modules.Music if (sender == null) return; - var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; - try { playingMessage = await textCh.SendMessageAsync(msgTxt).ConfigureAwait(false); } catch { } + var msgTxt = $"🎵 Playing {song.PrettyName}\t `Volume: {(int)(sender.Volume * 100)}%`"; + try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { } } }; return mp; @@ -802,14 +812,14 @@ namespace NadekoBot.Modules.Music } catch (PlaylistFullException) { - try { await textCh.SendMessageAsync($"🎵 `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` "); } catch { } + try { await textCh.SendConfirmAsync($"🎵 Queue is full at **{musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}**. "); } catch { } throw; } if (!silent) { try { - var queuedMessage = await textCh.SendMessageAsync($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); + var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title.TrimTo(55)}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); var t = Task.Run(async () => { try @@ -825,4 +835,4 @@ namespace NadekoBot.Modules.Music } } } -} \ No newline at end of file +} From c1ec7d9ad7ea18c28fbb7b8eaf2a020e108e00ca Mon Sep 17 00:00:00 2001 From: samvaio Date: Thu, 15 Dec 2016 00:57:07 +0530 Subject: [PATCH 3/6] kwoths music changes xD --- src/NadekoBot/Modules/Music/Music.cs | 160 +++++++++++++++------------ 1 file changed, 91 insertions(+), 69 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 95b67cef..34ef95af 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -29,9 +29,34 @@ namespace NadekoBot.Modules.Music //it can fail if its currenctly opened or doesn't exist. Either way i don't care try { Directory.Delete(MusicDataPath, true); } catch { } + NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated; + Directory.CreateDirectory(MusicDataPath); } + private Task Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState) + { + var usr = iusr as IGuildUser; + if (usr == null || + oldState.VoiceChannel == newState.VoiceChannel) + return Task.CompletedTask; + + MusicPlayer player; + if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player)) + return Task.CompletedTask; + + if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause + player.Paused && + player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1) + (player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause + !player.Paused && + player.PlaybackVoiceChannel.GetUsers().Count == 1)) + { + player.TogglePause(); + } + return Task.CompletedTask; + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public Task Next(IUserMessage umsg, int skipCount = 1) @@ -95,10 +120,6 @@ namespace NadekoBot.Modules.Music if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel) return; musicPlayer.TogglePause(); - if (musicPlayer.Paused) - await channel.SendConfirmAsync("🎵 Music Player **paused**.").ConfigureAwait(false); - else - await channel.SendConfirmAsync("🎵 Music Player **unpaused**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -137,7 +158,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) { - await channel.SendErrorAsync("🎵 No active music player.").ConfigureAwait(false); + await channel.SendMessageAsync("🎵 No active music player.").ConfigureAwait(false); return; } if (page <= 0) @@ -152,13 +173,12 @@ namespace NadekoBot.Modules.Music await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - //var toSend = $"🎵 Currently Playing {currentSong.PrettyName} " + $"`{currentSong.PrettyCurrentTime()}`\n"; - var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n"; + var toSend = $"🎵`Now Playing` {currentSong.PrettyName} " + $"{currentSong.PrettyCurrentTime()}\n"; if (musicPlayer.RepeatSong) toSend += "🔂"; else if (musicPlayer.RepeatPlaylist) toSend += "🔁"; - toSend += $" `{musicPlayer.Playlist.Count} tracks currently queued. Showing page {page}:` "; + toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) toSend += "**Song queue is full!**\n"; else @@ -166,7 +186,7 @@ namespace NadekoBot.Modules.Music const int itemsPerPage = 15; int startAt = itemsPerPage * (page - 1); var number = 1 + startAt; - await channel.SendConfirmAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); + await channel.SendMessageAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -174,7 +194,6 @@ namespace NadekoBot.Modules.Music public async Task NowPlaying(IUserMessage umsg) { var channel = (ITextChannel)umsg.Channel; - MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; @@ -186,13 +205,12 @@ namespace NadekoBot.Modules.Music { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - var embed = new EmbedBuilder() - .WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) - .WithTitle($"{currentSong.SongInfo.Title}") - .WithUrl($"{currentSong.SongInfo.Query}") - .WithDescription($"{currentSong.PrettyCurrentTime()}") - .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}")) - .WithColor(NadekoBot.OkColor); + var embed = new EmbedBuilder() + .WithAuthor(eab => eab.WithName("🎵 Now Playing")) + .WithTitle($"{currentSong.PrettyName}") + .WithDescription($"{currentSong.PrettyUser}") + .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyCurrentTime()}")) + .WithColor(NadekoBot.OkColor); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } @@ -209,7 +227,7 @@ namespace NadekoBot.Modules.Music if (val < 0) return; var volume = musicPlayer.SetVolume(val); - await channel.SendConfirmAsync($"🎵 Volume set to {volume}%").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 `Volume set to {volume}%`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -220,7 +238,7 @@ namespace NadekoBot.Modules.Music if (val < 0 || val > 100) { - await channel.SendErrorAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); + await channel.SendMessageAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); return; } using (var uow = DbHandler.UnitOfWork()) @@ -228,7 +246,7 @@ namespace NadekoBot.Modules.Music uow.GuildConfigs.For(channel.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f; uow.Complete(); } - await channel.SendConfirmAsync($"🎵 Default volume set to {val}%").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 `Default volume set to {val}%`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -243,12 +261,12 @@ namespace NadekoBot.Modules.Music return; if (musicPlayer.Playlist.Count < 2) { - await channel.SendErrorAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); + await channel.SendMessageAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); return; } musicPlayer.Shuffle(); - await channel.SendConfirmAsync("🎵 Songs shuffled.").ConfigureAwait(false); + await channel.SendMessageAsync("🎵 `Songs shuffled.`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -261,25 +279,25 @@ namespace NadekoBot.Modules.Music return; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendErrorAsync("💢 You need to be in a **voice channel** on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } var plId = (await NadekoBot.Google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault(); if (plId == null) { - await channel.SendErrorAsync("No search results for that query."); + await channel.SendMessageAsync("No search results for that query."); return; } var ids = await NadekoBot.Google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false); if (!ids.Any()) { - await channel.SendErrorAsync($"🎵 Failed to find any songs.").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 `Failed to find any songs.`").ConfigureAwait(false); return; } var idArray = ids as string[] ?? ids.ToArray(); var count = idArray.Length; var msg = - await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false); foreach (var id in idArray) { try @@ -289,7 +307,7 @@ namespace NadekoBot.Modules.Music catch (SongNotFoundException) { } catch { break; } } - await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = "🎵 `Playlist queue complete.`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -355,7 +373,7 @@ namespace NadekoBot.Modules.Music } catch { } } - await channel.SendConfirmAsync("🎵 Directory queue complete.").ConfigureAwait(false); + await channel.SendMessageAsync("🎵 `Directory queue complete.`").ConfigureAwait(false); } catch { } } @@ -367,7 +385,7 @@ namespace NadekoBot.Modules.Music var channel = (ITextChannel)umsg.Channel; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, radio_link, musicType: MusicType.Radio).ConfigureAwait(false); @@ -421,7 +439,7 @@ namespace NadekoBot.Modules.Music return; var song = (musicPlayer.Playlist as List)?[num - 1]; musicPlayer.RemoveSongAt(num - 1); - await channel.SendConfirmAsync($"🎵 Track {song.PrettyName} at position `#{num}` has been **removed**.").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -436,7 +454,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; musicPlayer.ClearQueue(); - await channel.SendConfirmAsync($"🎵 Queue cleared!").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵`Queue cleared!`").ConfigureAwait(false); return; } @@ -462,7 +480,7 @@ namespace NadekoBot.Modules.Music !int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 || n1 > playlist.Count || n2 > playlist.Count) { - await channel.SendErrorAsync("Invalid input.").ConfigureAwait(false); + await channel.SendMessageAsync("`Invalid input.`").ConfigureAwait(false); return; } @@ -470,17 +488,8 @@ namespace NadekoBot.Modules.Music playlist.Insert(n2 - 1, s); var nn1 = n2 < n1 ? n1 : n1 - 1; playlist.RemoveAt(nn1); - - var embed = new EmbedBuilder() - .WithTitle($"{s.SongInfo.Title.TrimTo(70)}") - .WithUrl($"{s.SongInfo.Query}") - .WithAuthor(eab => eab.WithName("Song Moved").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) - .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) - .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) - .WithColor(NadekoBot.OkColor); - await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); - //await channel.SendConfirmAsync($"🎵Moved {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); } @@ -496,7 +505,7 @@ namespace NadekoBot.Modules.Music return; } musicPlayer.MaxQueueSize = size; - await channel.SendConfirmAsync($"🎵 Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}."); + await channel.SendMessageAsync($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`"); } [NadekoCommand, Usage, Description, Aliases] @@ -511,9 +520,9 @@ namespace NadekoBot.Modules.Music if (currentSong == null) return; var currentValue = musicPlayer.ToggleRepeatSong(); - await channel.SendConfirmAsync(currentValue ? - $"🔂 Repeating track: {currentSong.PrettyName}" : - $"🔂 Current track repeat stopped.") + await channel.SendMessageAsync(currentValue ? + $"🎵🔂`Repeating track:`{currentSong.PrettyName}" : + $"🎵🔂`Current track repeat stopped.`") .ConfigureAwait(false); } @@ -526,7 +535,7 @@ namespace NadekoBot.Modules.Music if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; var currentValue = musicPlayer.ToggleRepeatPlaylist(); - await channel.SendConfirmAsync($"🔁 Repeat playlist {(currentValue ? "**enabled**." : "**disabled**.")}").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -562,7 +571,7 @@ namespace NadekoBot.Modules.Music await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendConfirmAsync(($"🎵 Saved playlist as **{name}**, ID: {playlist.Id}.")).ConfigureAwait(false); + await channel.SendMessageAsync(($"🎵 `Saved playlist as {name}.` `Id: {playlist.Id}`")).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -579,11 +588,11 @@ namespace NadekoBot.Modules.Music if (mpl == null) { - await channel.SendErrorAsync("Can't find playlist with that ID.").ConfigureAwait(false); + await channel.SendMessageAsync("`Can't find playlist with that ID`").ConfigureAwait(false); return; } IUserMessage msg = null; - try { msg = await channel.SendMessageAsync($"🎶 Attempting to load **{mpl.Songs.Count}** songs...").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { msg = await channel.SendMessageAsync($"`Attempting to load {mpl.Songs.Count} songs...`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } foreach (var item in mpl.Songs) { var usr = (IGuildUser)umsg.Author; @@ -595,7 +604,7 @@ namespace NadekoBot.Modules.Music catch { break; } } if (msg != null) - await msg.ModifyAsync(m => m.Content = $"✅ Done loading playlist **{mpl.Name}**.").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = $"`Done loading playlist {mpl.Name}.`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -614,9 +623,9 @@ namespace NadekoBot.Modules.Music playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); } - await channel.SendConfirmAsync($@"🎶 **Page {num} of saved playlists:** + await channel.SendMessageAsync($@"`Page {num} of saved playlists` -" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}** by __{r.Author}__ ({r.Songs.Count} songs)"))).ConfigureAwait(false); +" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - `{r.Name}` by {r.Author} - **{r.Songs.Count}** songs"))).ConfigureAwait(false); } //todo only author or owner @@ -648,9 +657,9 @@ namespace NadekoBot.Modules.Music } if (!success) - await channel.SendErrorAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); + await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); else - await channel.SendConfirmAsync("🗑 Playlist successfully **deleted**.").ConfigureAwait(false); + await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false); } catch (Exception ex) { @@ -692,7 +701,7 @@ namespace NadekoBot.Modules.Music if (seconds.Length == 1) seconds = "0" + seconds; - await channel.SendConfirmAsync($"Skipped to `{minutes}:{seconds}`").ConfigureAwait(false); + await channel.SendMessageAsync($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -713,12 +722,12 @@ namespace NadekoBot.Modules.Music var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1); if (selSong == null) { - await channel.SendErrorAsync("Could not select song, likely wrong index"); + await channel.SendMessageAsync("Could not select song, likely wrong index"); } else { - await channel.SendConfirmAsync($"🎶 Selected song **{selSong.SongInfo.Title}**: <{selSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendMessageAsync($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false); } } else @@ -726,7 +735,7 @@ namespace NadekoBot.Modules.Music var curSong = musicPlayer.CurrentSong; if (curSong == null) return; - await channel.SendConfirmAsync($"🎶 Current song **{curSong.SongInfo.Title}**: <{curSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendMessageAsync($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false); } } @@ -740,9 +749,9 @@ namespace NadekoBot.Modules.Music return; if (!musicPlayer.ToggleAutoplay()) - await channel.SendConfirmAsync("❌ Autoplay disabled.").ConfigureAwait(false); + await channel.SendMessageAsync("🎶`Autoplay disabled.`").ConfigureAwait(false); else - await channel.SendConfirmAsync("✅ Autoplay enabled.").ConfigureAwait(false); + await channel.SendMessageAsync("🎶`Autoplay enabled.`").ConfigureAwait(false); } public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) @@ -750,7 +759,7 @@ namespace NadekoBot.Modules.Music if (voiceCh == null || voiceCh.Guild != textCh.Guild) { if (!silent) - await textCh.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); + await textCh.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) @@ -764,8 +773,10 @@ namespace NadekoBot.Modules.Music vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } var mp = new MusicPlayer(voiceCh, vol); + + IUserMessage playingMessage = null; - IUserMessage lastFinishedMessage = null; + IUserMessage lastFinishedMessage = null; mp.OnCompleted += async (s, song) => { if (song.PrintStatusMessage) @@ -776,7 +787,7 @@ namespace NadekoBot.Modules.Music await lastFinishedMessage.DeleteAsync().ConfigureAwait(false); if (playingMessage != null) await playingMessage.DeleteAsync().ConfigureAwait(false); - try { lastFinishedMessage = await textCh.SendConfirmAsync($"🎵 Finished {song.PrettyName}").ConfigureAwait(false); } catch { } + try { lastFinishedMessage = await textCh.SendMessageAsync($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false); } catch { } if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") { await QueueSong(queuer.Guild.GetCurrentUser(), textCh, voiceCh, (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false); @@ -793,10 +804,21 @@ namespace NadekoBot.Modules.Music if (sender == null) return; - var msgTxt = $"🎵 Playing {song.PrettyName}\t `Volume: {(int)(sender.Volume * 100)}%`"; - try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { } + var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; + try { playingMessage = await textCh.SendMessageAsync(msgTxt).ConfigureAwait(false); } catch { } } }; + mp.OnPauseChanged += async (paused) => + { + try + { + if (paused) + await textCh.SendMessageAsync("🎵`Music playback paused.`").ConfigureAwait(false); + else + await textCh.SendMessageAsync("🎵`Music playback resumed.`").ConfigureAwait(false); + } + catch { } + }; return mp; }); Song resolvedSong; @@ -812,14 +834,14 @@ namespace NadekoBot.Modules.Music } catch (PlaylistFullException) { - try { await textCh.SendConfirmAsync($"🎵 Queue is full at **{musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}**. "); } catch { } + try { await textCh.SendMessageAsync($"🎵 `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` "); } catch { } throw; } if (!silent) { try { - var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title.TrimTo(55)}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); + var queuedMessage = await textCh.SendMessageAsync($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); var t = Task.Run(async () => { try @@ -835,4 +857,4 @@ namespace NadekoBot.Modules.Music } } } -} +} \ No newline at end of file From 8b5b49bf3c09498402976ae1c2c1177f64052858 Mon Sep 17 00:00:00 2001 From: samvaio Date: Thu, 15 Dec 2016 00:59:01 +0530 Subject: [PATCH 4/6] Music with Embeds and Album Arts --- src/NadekoBot/Modules/Music/Music.cs | 172 +++++++++++++-------------- 1 file changed, 80 insertions(+), 92 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 34ef95af..a4f348d1 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -14,6 +14,7 @@ using System.Net.Http; using Newtonsoft.Json.Linq; using System.Collections.Generic; using NadekoBot.Services.Database.Models; +using System.Text.RegularExpressions; namespace NadekoBot.Modules.Music { @@ -29,34 +30,9 @@ namespace NadekoBot.Modules.Music //it can fail if its currenctly opened or doesn't exist. Either way i don't care try { Directory.Delete(MusicDataPath, true); } catch { } - NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated; - Directory.CreateDirectory(MusicDataPath); } - private Task Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState) - { - var usr = iusr as IGuildUser; - if (usr == null || - oldState.VoiceChannel == newState.VoiceChannel) - return Task.CompletedTask; - - MusicPlayer player; - if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player)) - return Task.CompletedTask; - - if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause - player.Paused && - player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1) - (player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause - !player.Paused && - player.PlaybackVoiceChannel.GetUsers().Count == 1)) - { - player.TogglePause(); - } - return Task.CompletedTask; - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public Task Next(IUserMessage umsg, int skipCount = 1) @@ -120,6 +96,10 @@ namespace NadekoBot.Modules.Music if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel) return; musicPlayer.TogglePause(); + if (musicPlayer.Paused) + await channel.SendConfirmAsync("🎵 Music Player **paused**.").ConfigureAwait(false); + else + await channel.SendConfirmAsync("🎵 Music Player **unpaused**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -158,7 +138,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) { - await channel.SendMessageAsync("🎵 No active music player.").ConfigureAwait(false); + await channel.SendErrorAsync("🎵 No active music player.").ConfigureAwait(false); return; } if (page <= 0) @@ -173,12 +153,13 @@ namespace NadekoBot.Modules.Music await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - var toSend = $"🎵`Now Playing` {currentSong.PrettyName} " + $"{currentSong.PrettyCurrentTime()}\n"; + //var toSend = $"🎵 Currently Playing {currentSong.PrettyName} " + $"`{currentSong.PrettyCurrentTime()}`\n"; + var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n"; if (musicPlayer.RepeatSong) toSend += "🔂"; else if (musicPlayer.RepeatPlaylist) toSend += "🔁"; - toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; + toSend += $" `{musicPlayer.Playlist.Count} tracks currently queued. Showing page {page}:` "; if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) toSend += "**Song queue is full!**\n"; else @@ -186,7 +167,7 @@ namespace NadekoBot.Modules.Music const int itemsPerPage = 15; int startAt = itemsPerPage * (page - 1); var number = 1 + startAt; - await channel.SendMessageAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); + await channel.SendConfirmAsync(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -194,24 +175,35 @@ namespace NadekoBot.Modules.Music public async Task NowPlaying(IUserMessage umsg) { var channel = (ITextChannel)umsg.Channel; + MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; var currentSong = musicPlayer.CurrentSong; if (currentSong == null) return; + var videoid = Regex.Match(currentSong.SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+"); if (currentSong.TotalLength == TimeSpan.Zero) { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } - var embed = new EmbedBuilder() - .WithAuthor(eab => eab.WithName("🎵 Now Playing")) - .WithTitle($"{currentSong.PrettyName}") - .WithDescription($"{currentSong.PrettyUser}") - .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyCurrentTime()}")) - .WithColor(NadekoBot.OkColor); - await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + var embed = new EmbedBuilder() + .WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) + .WithTitle($"{currentSong.SongInfo.Title}") + .WithUrl($"{currentSong.SongInfo.Query}") + .WithDescription($"{currentSong.PrettyCurrentTime()}") + .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}")) + .WithColor(NadekoBot.OkColor); + if (currentSong.SongInfo.Provider.Equals("YouTube", StringComparison.OrdinalIgnoreCase)) + { + embed.WithThumbnail(tn => tn.Url = $"https://img.youtube.com/vi/{videoid}/0.jpg"); + } + else if (currentSong.SongInfo.Provider.Equals("SoundCloud", StringComparison.OrdinalIgnoreCase)) + { + embed.WithThumbnail(tn => tn.Url = $"{currentSong.SongInfo.AlbumArt}"); + } + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -227,7 +219,7 @@ namespace NadekoBot.Modules.Music if (val < 0) return; var volume = musicPlayer.SetVolume(val); - await channel.SendMessageAsync($"🎵 `Volume set to {volume}%`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Volume set to {volume}%").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -238,7 +230,7 @@ namespace NadekoBot.Modules.Music if (val < 0 || val > 100) { - await channel.SendMessageAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); + await channel.SendErrorAsync("Volume number invalid. Must be between 0 and 100").ConfigureAwait(false); return; } using (var uow = DbHandler.UnitOfWork()) @@ -246,7 +238,7 @@ namespace NadekoBot.Modules.Music uow.GuildConfigs.For(channel.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f; uow.Complete(); } - await channel.SendMessageAsync($"🎵 `Default volume set to {val}%`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Default volume set to {val}%").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -261,12 +253,12 @@ namespace NadekoBot.Modules.Music return; if (musicPlayer.Playlist.Count < 2) { - await channel.SendMessageAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 Not enough songs in order to perform the shuffle.").ConfigureAwait(false); return; } musicPlayer.Shuffle(); - await channel.SendMessageAsync("🎵 `Songs shuffled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Songs shuffled.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -279,25 +271,25 @@ namespace NadekoBot.Modules.Music return; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 You need to be in a **voice channel** on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } var plId = (await NadekoBot.Google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault(); if (plId == null) { - await channel.SendMessageAsync("No search results for that query."); + await channel.SendErrorAsync("No search results for that query."); return; } var ids = await NadekoBot.Google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false); if (!ids.Any()) { - await channel.SendMessageAsync($"🎵 `Failed to find any songs.`").ConfigureAwait(false); + await channel.SendErrorAsync($"🎵 Failed to find any songs.").ConfigureAwait(false); return; } var idArray = ids as string[] ?? ids.ToArray(); var count = idArray.Length; var msg = - await channel.SendMessageAsync($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`").ConfigureAwait(false); + await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); foreach (var id in idArray) { try @@ -307,7 +299,7 @@ namespace NadekoBot.Modules.Music catch (SongNotFoundException) { } catch { break; } } - await msg.ModifyAsync(m => m.Content = "🎵 `Playlist queue complete.`").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -373,7 +365,7 @@ namespace NadekoBot.Modules.Music } catch { } } - await channel.SendMessageAsync("🎵 `Directory queue complete.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🎵 Directory queue complete.").ConfigureAwait(false); } catch { } } @@ -385,7 +377,7 @@ namespace NadekoBot.Modules.Music var channel = (ITextChannel)umsg.Channel; if (((IGuildUser)umsg.Author).VoiceChannel?.Guild != channel.Guild) { - await channel.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); + await channel.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.").ConfigureAwait(false); return; } await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, radio_link, musicType: MusicType.Radio).ConfigureAwait(false); @@ -439,7 +431,7 @@ namespace NadekoBot.Modules.Music return; var song = (musicPlayer.Playlist as List)?[num - 1]; musicPlayer.RemoveSongAt(num - 1); - await channel.SendMessageAsync($"🎵**Track {song.PrettyName} at position `#{num}` has been removed.**").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Track {song.PrettyName} at position `#{num}` has been **removed**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -454,7 +446,7 @@ namespace NadekoBot.Modules.Music MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; musicPlayer.ClearQueue(); - await channel.SendMessageAsync($"🎵`Queue cleared!`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎵 Queue cleared!").ConfigureAwait(false); return; } @@ -480,7 +472,7 @@ namespace NadekoBot.Modules.Music !int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 || n1 > playlist.Count || n2 > playlist.Count) { - await channel.SendMessageAsync("`Invalid input.`").ConfigureAwait(false); + await channel.SendErrorAsync("Invalid input.").ConfigureAwait(false); return; } @@ -488,8 +480,17 @@ namespace NadekoBot.Modules.Music playlist.Insert(n2 - 1, s); var nn1 = n2 < n1 ? n1 : n1 - 1; playlist.RemoveAt(nn1); + + var embed = new EmbedBuilder() + .WithTitle($"{s.SongInfo.Title.TrimTo(70)}") + .WithUrl($"{s.SongInfo.Query}") + .WithAuthor(eab => eab.WithName("Song Moved").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) + .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) + .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) + .WithColor(NadekoBot.OkColor); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); - await channel.SendMessageAsync($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); + //await channel.SendConfirmAsync($"🎵Moved {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false); } @@ -505,7 +506,7 @@ namespace NadekoBot.Modules.Music return; } musicPlayer.MaxQueueSize = size; - await channel.SendMessageAsync($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`"); + await channel.SendConfirmAsync($"🎵 Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}."); } [NadekoCommand, Usage, Description, Aliases] @@ -520,9 +521,9 @@ namespace NadekoBot.Modules.Music if (currentSong == null) return; var currentValue = musicPlayer.ToggleRepeatSong(); - await channel.SendMessageAsync(currentValue ? - $"🎵🔂`Repeating track:`{currentSong.PrettyName}" : - $"🎵🔂`Current track repeat stopped.`") + await channel.SendConfirmAsync(currentValue ? + $"🔂 Repeating track: {currentSong.PrettyName}" : + $"🔂 Current track repeat stopped.") .ConfigureAwait(false); } @@ -535,7 +536,7 @@ namespace NadekoBot.Modules.Music if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return; var currentValue = musicPlayer.ToggleRepeatPlaylist(); - await channel.SendMessageAsync($"🎵🔁`Repeat playlist {(currentValue ? "enabled" : "disabled")}`").ConfigureAwait(false); + await channel.SendConfirmAsync($"🔁 Repeat playlist {(currentValue ? "**enabled**." : "**disabled**.")}").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -571,7 +572,7 @@ namespace NadekoBot.Modules.Music await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync(($"🎵 `Saved playlist as {name}.` `Id: {playlist.Id}`")).ConfigureAwait(false); + await channel.SendConfirmAsync(($"🎵 Saved playlist as **{name}**, ID: {playlist.Id}.")).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -588,11 +589,11 @@ namespace NadekoBot.Modules.Music if (mpl == null) { - await channel.SendMessageAsync("`Can't find playlist with that ID`").ConfigureAwait(false); + await channel.SendErrorAsync("Can't find playlist with that ID.").ConfigureAwait(false); return; } IUserMessage msg = null; - try { msg = await channel.SendMessageAsync($"`Attempting to load {mpl.Songs.Count} songs...`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { msg = await channel.SendMessageAsync($"🎶 Attempting to load **{mpl.Songs.Count}** songs...").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } foreach (var item in mpl.Songs) { var usr = (IGuildUser)umsg.Author; @@ -604,7 +605,7 @@ namespace NadekoBot.Modules.Music catch { break; } } if (msg != null) - await msg.ModifyAsync(m => m.Content = $"`Done loading playlist {mpl.Name}.`").ConfigureAwait(false); + await msg.ModifyAsync(m => m.Content = $"✅ Done loading playlist **{mpl.Name}**.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -623,9 +624,9 @@ namespace NadekoBot.Modules.Music playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); } - await channel.SendMessageAsync($@"`Page {num} of saved playlists` + await channel.SendConfirmAsync($@"🎶 **Page {num} of saved playlists:** -" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - `{r.Name}` by {r.Author} - **{r.Songs.Count}** songs"))).ConfigureAwait(false); +" + string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}** by __{r.Author}__ ({r.Songs.Count} songs)"))).ConfigureAwait(false); } //todo only author or owner @@ -657,9 +658,9 @@ namespace NadekoBot.Modules.Music } if (!success) - await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); + await channel.SendErrorAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false); else - await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false); + await channel.SendConfirmAsync("🗑 Playlist successfully **deleted**.").ConfigureAwait(false); } catch (Exception ex) { @@ -701,7 +702,7 @@ namespace NadekoBot.Modules.Music if (seconds.Length == 1) seconds = "0" + seconds; - await channel.SendMessageAsync($"`Skipped to {minutes}:{seconds}`").ConfigureAwait(false); + await channel.SendConfirmAsync($"Skipped to `{minutes}:{seconds}`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -722,12 +723,12 @@ namespace NadekoBot.Modules.Music var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1); if (selSong == null) { - await channel.SendMessageAsync("Could not select song, likely wrong index"); + await channel.SendErrorAsync("Could not select song, likely wrong index"); } else { - await channel.SendMessageAsync($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎶 Selected song **{selSong.SongInfo.Title}**: <{selSong.SongInfo.Query}>").ConfigureAwait(false); } } else @@ -735,7 +736,7 @@ namespace NadekoBot.Modules.Music var curSong = musicPlayer.CurrentSong; if (curSong == null) return; - await channel.SendMessageAsync($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false); + await channel.SendConfirmAsync($"🎶 Current song **{curSong.SongInfo.Title}**: <{curSong.SongInfo.Query}>").ConfigureAwait(false); } } @@ -749,9 +750,9 @@ namespace NadekoBot.Modules.Music return; if (!musicPlayer.ToggleAutoplay()) - await channel.SendMessageAsync("🎶`Autoplay disabled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("❌ Autoplay disabled.").ConfigureAwait(false); else - await channel.SendMessageAsync("🎶`Autoplay enabled.`").ConfigureAwait(false); + await channel.SendConfirmAsync("✅ Autoplay enabled.").ConfigureAwait(false); } public static async Task QueueSong(IGuildUser queuer, ITextChannel textCh, IVoiceChannel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) @@ -759,7 +760,7 @@ namespace NadekoBot.Modules.Music if (voiceCh == null || voiceCh.Guild != textCh.Guild) { if (!silent) - await textCh.SendMessageAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); + await textCh.SendErrorAsync("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.").ConfigureAwait(false); throw new ArgumentNullException(nameof(voiceCh)); } if (string.IsNullOrWhiteSpace(query) || query.Length < 3) @@ -773,10 +774,8 @@ namespace NadekoBot.Modules.Music vol = uow.GuildConfigs.For(textCh.Guild.Id, set => set).DefaultMusicVolume; } var mp = new MusicPlayer(voiceCh, vol); - - IUserMessage playingMessage = null; - IUserMessage lastFinishedMessage = null; + IUserMessage lastFinishedMessage = null; mp.OnCompleted += async (s, song) => { if (song.PrintStatusMessage) @@ -787,7 +786,7 @@ namespace NadekoBot.Modules.Music await lastFinishedMessage.DeleteAsync().ConfigureAwait(false); if (playingMessage != null) await playingMessage.DeleteAsync().ConfigureAwait(false); - try { lastFinishedMessage = await textCh.SendMessageAsync($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false); } catch { } + try { lastFinishedMessage = await textCh.SendConfirmAsync($"🎵 Finished {song.PrettyName}").ConfigureAwait(false); } catch { } if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") { await QueueSong(queuer.Guild.GetCurrentUser(), textCh, voiceCh, (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false); @@ -804,21 +803,10 @@ namespace NadekoBot.Modules.Music if (sender == null) return; - var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; - try { playingMessage = await textCh.SendMessageAsync(msgTxt).ConfigureAwait(false); } catch { } + var msgTxt = $"🎵 Playing {song.PrettyName}\t `Volume: {(int)(sender.Volume * 100)}%`"; + try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { } } }; - mp.OnPauseChanged += async (paused) => - { - try - { - if (paused) - await textCh.SendMessageAsync("🎵`Music playback paused.`").ConfigureAwait(false); - else - await textCh.SendMessageAsync("🎵`Music playback resumed.`").ConfigureAwait(false); - } - catch { } - }; return mp; }); Song resolvedSong; @@ -834,14 +822,14 @@ namespace NadekoBot.Modules.Music } catch (PlaylistFullException) { - try { await textCh.SendMessageAsync($"🎵 `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` "); } catch { } + try { await textCh.SendConfirmAsync($"🎵 Queue is full at **{musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}**. "); } catch { } throw; } if (!silent) { try { - var queuedMessage = await textCh.SendMessageAsync($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); + var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title.TrimTo(55)}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); var t = Task.Run(async () => { try @@ -857,4 +845,4 @@ namespace NadekoBot.Modules.Music } } } -} \ No newline at end of file +} From 367451207356e0abf10c9903b2624c22de25c419 Mon Sep 17 00:00:00 2001 From: samvaio Date: Thu, 15 Dec 2016 01:18:44 +0530 Subject: [PATCH 5/6] Music with Embeds and cool Avatars --- src/NadekoBot/Modules/Music/Music.cs | 43 ++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index a4f348d1..4a8e4829 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -29,9 +29,34 @@ namespace NadekoBot.Modules.Music { //it can fail if its currenctly opened or doesn't exist. Either way i don't care try { Directory.Delete(MusicDataPath, true); } catch { } + + NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated; Directory.CreateDirectory(MusicDataPath); } + + private Task Client_UserVoiceStateUpdated(IUser iusr, IVoiceState oldState, IVoiceState newState) + { + var usr = iusr as IGuildUser; + if (usr == null || + oldState.VoiceChannel == newState.VoiceChannel) + return Task.CompletedTask; + + MusicPlayer player; + if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player)) + return Task.CompletedTask; + + if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause + player.Paused && + player.PlaybackVoiceChannel.GetUsers().Count == 2) || // keep in mind bot is in the channel (+1) + (player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause + !player.Paused && + player.PlaybackVoiceChannel.GetUsers().Count == 1)) + { + player.TogglePause(); + } + return Task.CompletedTask; + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] @@ -96,10 +121,7 @@ namespace NadekoBot.Modules.Music if (((IGuildUser)umsg.Author).VoiceChannel != musicPlayer.PlaybackVoiceChannel) return; musicPlayer.TogglePause(); - if (musicPlayer.Paused) - await channel.SendConfirmAsync("🎵 Music Player **paused**.").ConfigureAwait(false); - else - await channel.SendConfirmAsync("🎵 Music Player **unpaused**.").ConfigureAwait(false); + } [NadekoCommand, Usage, Description, Aliases] @@ -803,10 +825,21 @@ namespace NadekoBot.Modules.Music if (sender == null) return; - var msgTxt = $"🎵 Playing {song.PrettyName}\t `Volume: {(int)(sender.Volume * 100)}%`"; + var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`"; try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { } } }; + mp.OnPauseChanged += async (paused) => + { + try + { + if (paused) + await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); + else + await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); + } + catch { } + }; return mp; }); Song resolvedSong; From 07962f9e2eaa1014ac3b52d8dbf85b5579e7bd9d Mon Sep 17 00:00:00 2001 From: samvaio Date: Thu, 15 Dec 2016 01:20:37 +0530 Subject: [PATCH 6/6] reverted back 01private's changes added 1 for avatars --- src/NadekoBot/Modules/Music/Classes/Song.cs | 3 +++ src/NadekoBot/Modules/Music/Classes/SoundCloud.cs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index a4447a5a..2623f680 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -24,6 +24,7 @@ namespace NadekoBot.Modules.Music.Classes public string Query { get; set; } public string Title { get; set; } public string Uri { get; set; } + public string AlbumArt { get; set; } } public class Song { @@ -319,6 +320,7 @@ namespace NadekoBot.Modules.Music.Classes Uri = svideo.StreamLink, ProviderType = musicType, Query = svideo.TrackLink, + AlbumArt = svideo.artwork_url, }) { TotalLength = TimeSpan.FromMilliseconds(svideo.Duration) }; } @@ -333,6 +335,7 @@ namespace NadekoBot.Modules.Music.Classes Uri = svideo.StreamLink, ProviderType = MusicType.Normal, Query = svideo.TrackLink, + AlbumArt = svideo.artwork_url, }) { TotalLength = TimeSpan.FromMilliseconds(svideo.Duration) }; } diff --git a/src/NadekoBot/Modules/Music/Classes/SoundCloud.cs b/src/NadekoBot/Modules/Music/Classes/SoundCloud.cs index 8da2a13b..98399363 100644 --- a/src/NadekoBot/Modules/Music/Classes/SoundCloud.cs +++ b/src/NadekoBot/Modules/Music/Classes/SoundCloud.cs @@ -73,6 +73,7 @@ namespace NadekoBot.Modules.Music.Classes public int Duration { get; set; } [JsonProperty("permalink_url")] public string TrackLink { get; set; } = ""; + public string artwork_url { get; set; } = ""; [JsonIgnore] public string StreamLink => $"https://api.soundcloud.com/tracks/{Id}/stream?client_id={NadekoBot.Credentials.SoundCloudClientId}"; }