Merge pull request #915 from samdivaio/fixed-dev-music

Music prettier/improved, thanks to samvaio for his hard work
This commit is contained in:
Master Kwoth 2016-12-22 01:24:59 +01:00 committed by GitHub
commit 8b681c13a6
5 changed files with 206 additions and 50 deletions

View File

@ -45,16 +45,22 @@ namespace NadekoBot.Modules.Music.Classes
public string PrettyCurrentTime()
{
var time = TimeSpan.FromSeconds(bytesSent / 3840 / 50);
var str = $"{(int)time.TotalMinutes}m {time.Seconds}s / ";
//var str = $"{(int)time.TotalMinutes}m {time.Seconds}s / ";
var str = $"";
if (TotalLength == TimeSpan.Zero)
str += "**?**";
str += "(?)";
else if (TotalLength == TimeSpan.MaxValue)
str += "**∞**";
else
str += $"{(int)TotalLength.TotalMinutes}m {TotalLength.Seconds}s";
return str;
}
public string PrettyMusicPlayTime()
{
var time = TimeSpan.FromSeconds(bytesSent / 3840 / 50);
var str = $"{(int)time.TotalMinutes}m {time.Seconds}s";
return str;
}
const int milliseconds = 20;
const int samplesPerFrame = (48000 / 1000) * milliseconds;
const int frameBytes = 3840; //16-bit, 2 channels

View File

@ -98,16 +98,18 @@ namespace NadekoBot.Modules.Music
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Destroy(IUserMessage umsg)
public async Task Destroy(IUserMessage umsg)
//public Task Destroy(IUserMessage umsg)
{
var channel = (ITextChannel)umsg.Channel;
await channel.SendErrorAsync("Command is temporarily disabled.").ConfigureAwait(false);
MusicPlayer musicPlayer;
/*MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer)) return Task.CompletedTask;
if (((IGuildUser)umsg.Author).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
if(MusicPlayers.TryRemove(channel.Guild.Id, out musicPlayer))
musicPlayer.Destroy();
return Task.CompletedTask;
return Task.CompletedTask;*/
}
[NadekoCommand, Usage, Description, Aliases]
@ -168,28 +170,60 @@ namespace NadekoBot.Modules.Music
var currentSong = musicPlayer.CurrentSong;
if (currentSong == null)
{
await channel.SendErrorAsync("🎵 No active music player.").ConfigureAwait(false);
return;
}
if (currentSong.TotalLength == TimeSpan.Zero)
{
await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false);
}
//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}:` ";
if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize)
toSend += "**Song queue is full!**\n";
else
toSend += "\n";
const int itemsPerPage = 15;
//var toSend = $"🎵 Currently Playing {currentSong.PrettyName}\n";
//I did that ^ because current song, bugs when a youtube playlist is queued with more than 50 song, it more like a bug with youtube page token I believe.
const int itemsPerPage = 10;
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);
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName($"Track List: Page {page}").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithDescription(string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(10).Select(v => $"`{number++}.` **[{v.SongInfo.Title.TrimTo(70)}]({v.SongInfo.Query})**\n\t\t*{v.PrettyCurrentTime()}* **|** *{v.PrettyProvider}* **|** *{v.QueuerName}*")))
.WithFooter(ef => ef.WithText($"{musicPlayer.Playlist.Count} tracks currently queued."))
.WithColor(NadekoBot.OkColor);
if (musicPlayer.RepeatSong)
{
embed.WithTitle($"🔂 Repeating Song: {currentSong.SongInfo.Title} | {currentSong.PrettyMusicPlayTime()} / {currentSong.PrettyCurrentTime()}");
}
else if (musicPlayer.RepeatPlaylist)
{
embed.WithTitle("🔁 Repeating Playlist");
}
if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize)
{
embed.WithTitle("🎵 Song queue is full!");
}
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
//var toSend = $"test"; //this was for testing
//if (musicPlayer.RepeatSong)
//toSend += "🔂";
//else if (musicPlayer.RepeatPlaylist)
//toSend += "🔁";
//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
//toSend += "\n";
//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);
}
[NadekoCommand, Usage, Description, Aliases]
@ -206,24 +240,42 @@ namespace NadekoBot.Modules.Music
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").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png"))
.WithAuthor(eab => eab.WithName("Now Playing").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{currentSong.SongInfo.Title}")
.WithUrl($"{currentSong.SongInfo.Query}")
.WithDescription($"{currentSong.PrettyCurrentTime()}")
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.PrettyUser}"))
//.WithDescription($"{currentSong.PrettyCurrentTime()}")
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}"))
.WithColor(NadekoBot.OkColor);
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}");
//if (musicPlayer.Playlist.Count < 50)
//{
if (currentSong.TotalLength == TimeSpan.Zero)
{
await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false);
}
embed.WithDescription($"{currentSong.PrettyMusicPlayTime()} / {currentSong.PrettyCurrentTime()}");
//}
//else if (musicPlayer.Playlist.Count > 50)
//{
//embed.WithDescription($"{currentSong.PrettyMusicPlayTime()}");
//}
}
else if (currentSong.SongInfo.Provider.Equals("SoundCloud", StringComparison.OrdinalIgnoreCase))
{
embed.WithThumbnail(tn => tn.Url = $"{currentSong.SongInfo.AlbumArt}");
embed.WithUrl($"{currentSong.SongInfo.Query}");
if (currentSong.TotalLength == TimeSpan.Zero)
{
await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false);
}
embed.WithDescription($"{currentSong.PrettyMusicPlayTime()} / {currentSong.PrettyCurrentTime()}");
}
else if (currentSong.SongInfo.Provider.Equals("Local File", StringComparison.OrdinalIgnoreCase))
{
embed.WithDescription($"{currentSong.PrettyMusicPlayTime()}");
}
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
}
@ -310,17 +362,22 @@ namespace NadekoBot.Modules.Music
}
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);
foreach (var id in idArray)
{
try
{
await QueueSong(((IGuildUser)umsg.Author), channel, ((IGuildUser)umsg.Author).VoiceChannel, id, true).ConfigureAwait(false);
//await Task.Delay(2000).ConfigureAwait(false); //fixes google api error for few songs on playlist.//
}
catch (SongNotFoundException) { }
catch { break; }
}
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
}
@ -453,7 +510,13 @@ namespace NadekoBot.Modules.Music
return;
var song = (musicPlayer.Playlist as List<Song>)?[num - 1];
musicPlayer.RemoveSongAt(num - 1);
await channel.SendConfirmAsync($"🎵 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);
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName("Song Removed!").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true))
.AddField(fb => fb.WithName("**Song Name**").WithValue($"**[{song.SongInfo.Title.TrimTo(70)}]({song.SongInfo.Query})** `{song.PrettyProvider} | {song.QueuerName.TrimTo(15)}`").WithIsInline(true))
.WithColor(NadekoBot.ErrorColor);
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@ -506,7 +569,7 @@ namespace NadekoBot.Modules.Music
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"))
.WithAuthor(eab => eab.WithName("Song Moved").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true))
.AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true))
.WithColor(NadekoBot.OkColor);
@ -646,9 +709,16 @@ namespace NadekoBot.Modules.Music
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
}
await channel.SendConfirmAsync($@"🎶 **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);
var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName($"Page {num} of Saved Playlists").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithDescription(string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}**\t by **`{r.Author}`**\t ({r.Songs.Count} songs)")))
.WithColor(NadekoBot.OkColor);
await channel.EmbedAsync(embed.Build()).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
@ -750,7 +820,7 @@ namespace NadekoBot.Modules.Music
}
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
@ -758,7 +828,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.Title}**: <{curSong.SongInfo.Query}>").ConfigureAwait(false);
}
}
@ -805,10 +875,26 @@ namespace NadekoBot.Modules.Music
try
{
if (lastFinishedMessage != null)
{
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.SendConfirmAsync($"🎵 Finished {song.PrettyName}").ConfigureAwait(false); } catch { }
try { lastFinishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithAuthor(eab => eab.WithName("Finished Song").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{song.SongInfo.Title}")
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.Build())
.ConfigureAwait(false); } catch { }
}
else
{
try { lastFinishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithAuthor(eab => eab.WithName("Finished Song").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{song.SongInfo.Title}")
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.Build())
.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);
@ -822,21 +908,64 @@ namespace NadekoBot.Modules.Music
if (song.PrintStatusMessage)
{
var sender = s as MusicPlayer;
//var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`";
if (sender == null)
return;
var msgTxt = $"🎵 Playing {song.PrettyName}\t `Vol: {(int)(sender.Volume * 100)}%`";
try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
if (playingMessage != null)
{
await playingMessage.DeleteAsync().ConfigureAwait(false);
//try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
try { playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithAuthor(eab => eab.WithName("Playing Song").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{song.SongInfo.Title}")
.WithDescription($"Volume: {(int)(sender.Volume * 100)}%")
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.Build())
.ConfigureAwait(false); } catch { }
}
else
{
//try { playingMessage = await textCh.SendConfirmAsync(msgTxt).ConfigureAwait(false); } catch { }
try { playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithAuthor(eab => eab.WithName("Playing Song").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{song.SongInfo.Title}")
.WithDescription($"Volume: {(int)(sender.Volume * 100)}%")
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.Build())
.ConfigureAwait(false); } catch { }
}
}
};
IUserMessage resumemsg = null;
IUserMessage pausemsg = null;
mp.OnPauseChanged += async (paused) =>
{
try
{
if (paused)
await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false);
{
if (pausemsg != null)
{
await pausemsg.DeleteAsync().ConfigureAwait(false);
try { pausemsg = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); } catch { }
}
else
await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
{
try { pausemsg = await textCh.SendConfirmAsync("🎵 Music playback **paused**.").ConfigureAwait(false); } catch { }
}
}
else
{
if (resumemsg != null)
{
await resumemsg.DeleteAsync().ConfigureAwait(false);
try { resumemsg = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); } catch { }
}
else
{
try { resumemsg = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); } catch { }
}
}
}
catch { }
};
@ -862,7 +991,14 @@ namespace NadekoBot.Modules.Music
{
try
{
var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title.TrimTo(55)}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false);
//var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false);
var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithAuthor(eab => eab.WithName("Queued Song").WithIconUrl("http://i.imgur.com/nhKS3PT.png"))
.WithTitle($"{resolvedSong.SongInfo.Title}")
.WithDescription($"Queue #{musicPlayer.Playlist.Count + 1}")
.WithFooter(ef => ef.WithText($"{resolvedSong.PrettyProvider}"))
.Build())
.ConfigureAwait(false);
var t = Task.Run(async () =>
{
try

View File

@ -37,6 +37,7 @@ namespace NadekoBot.Modules.Searches
var rankimg = $"{model.Competitive.rank_img}";
var rank = $"{model.Competitive.rank}";
var competitiveplay = $"{model.Games.Competitive.played}";
if (string.IsNullOrWhiteSpace(rank))
{
var embed = new EmbedBuilder()
@ -72,7 +73,20 @@ namespace NadekoBot.Modules.Searches
.AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true))
.WithColor(NadekoBot.OkColor);
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
return;
}
if (string.IsNullOrWhiteSpace(competitiveplay))
{
var embed = new EmbedBuilder()
.WithAuthor(eau => eau.WithName($"{model.username}")
.WithUrl($"https://www.overbuff.com/players/pc/{battletag}")
.WithIconUrl($"{model.avatar}"))
.WithThumbnail(th => th.WithUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png"))
.AddField(fb => fb.WithName("**Level**").WithValue($"{model.level}").WithIsInline(true))
.AddField(fb => fb.WithName("**Quick Wins**").WithValue($"{model.Games.Quick.wins}").WithIsInline(true))
.AddField(fb => fb.WithName("**Competitive Playtime**").WithValue($"0 hour").WithIsInline(true))
.AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true))
.WithColor(NadekoBot.OkColor);
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
}
}
catch

View File

@ -221,7 +221,7 @@ namespace NadekoBot.Modules.Searches
if (string.IsNullOrWhiteSpace(terms))
return;
await channel.SendConfirmAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
.ConfigureAwait(false);
}

View File

@ -26,7 +26,7 @@
"target": "project"
},
"Google.Apis.Urlshortener.v1": "1.19.0.138",
"Google.Apis.YouTube.v3": "1.19.0.655",
"Google.Apis.YouTube.v3": "1.20.0.701",
"ImageSharp": "1.0.0-alpha-000079",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",