Cleaned up PR

This commit is contained in:
Kwoth 2016-12-27 01:35:46 +01:00
parent d08abbafd0
commit 67a6b69088
2 changed files with 44 additions and 63 deletions

View File

@ -47,25 +47,7 @@ namespace NadekoBot.Modules.Music.Classes
public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime; public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime;
//public string PrettyName => $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**"; public string PrettyName => $"**[{SongInfo.Title.TrimTo(65)}]({songUrl})**";
public string PrettyName {
get {
switch (SongInfo.ProviderType)
{
case MusicType.Normal:
return $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**";
case MusicType.Soundcloud:
return $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**";
case MusicType.Local:
return $"**{SongInfo.Title.TrimTo(70)}**";
case MusicType.Radio:
return $"**{SongInfo.Title.TrimTo(70)}**";
default:
return "";
}
}
}
public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}"; public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}";
@ -86,36 +68,35 @@ namespace NadekoBot.Modules.Music.Classes
public string Thumbnail { public string Thumbnail {
get { get {
switch (SongInfo.Provider) switch (SongInfo.ProviderType)
{ {
case "YouTube": case MusicType.Radio:
//todo have videoid in songinfo from the start //todo have videoid in songinfo from the start
var videoId = Regex.Match(SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+"); var videoId = Regex.Match(SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+");
return $"https://img.youtube.com/vi/{ videoId }/0.jpg"; return $"https://img.youtube.com/vi/{ videoId }/0.jpg";
case "SoundCloud": case MusicType.Normal:
return SongInfo.AlbumArt; return $"https://cdn.discordapp.com/attachments/155726317222887425/261850925063340032/1482522097_radio.png"; //test links
case "Local File": case MusicType.Local:
return $"https://cdn.discordapp.com/attachments/155726317222887425/261850914783100928/1482522077_music.png"; //test links return $"https://cdn.discordapp.com/attachments/155726317222887425/261850914783100928/1482522077_music.png"; //test links
case "Radio Stream": case MusicType.Soundcloud:
return $"https://cdn.discordapp.com/attachments/155726317222887425/261850925063340032/1482522097_radio.png"; //test links return SongInfo.AlbumArt;
default:
return "";
} }
return "";
} }
} }
public string songURL { private string songUrl {
get { get {
switch (SongInfo.ProviderType) switch (SongInfo.ProviderType)
{ {
case MusicType.Normal: case MusicType.Normal:
return SongInfo.Query; return SongInfo.Query;
case MusicType.Soundcloud: case MusicType.Soundcloud:
return SongInfo.Query; return SongInfo.Query;
case MusicType.Local: case MusicType.Local:
return $"https://google.com/search?q={ WebUtility.UrlEncode(SongInfo.Title).Replace(' ', '+') }"; return $"https://google.com/search?q={ WebUtility.UrlEncode(SongInfo.Title).Replace(' ', '+') }";
case MusicType.Radio: case MusicType.Radio:
return $"https://google.com/search?q={SongInfo.Title}"; return $"https://google.com/search?q={SongInfo.Title}";
default: default:
return ""; return "";
} }
@ -143,7 +124,7 @@ namespace NadekoBot.Modules.Music.Classes
{ {
var s = new Song(SongInfo); var s = new Song(SongInfo);
s.MusicPlayer = MusicPlayer; s.MusicPlayer = MusicPlayer;
s.QueuerName = QueuerName; s.QueuerName = QueuerName;
return s; return s;
} }

View File

@ -240,7 +240,7 @@ namespace NadekoBot.Modules.Music
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}")) .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}"))
.WithOkColor() .WithOkColor()
.WithThumbnail(tn => tn.Url = currentSong.Thumbnail) .WithThumbnail(tn => tn.Url = currentSong.Thumbnail)
.WithUrl(currentSong.songURL); .WithUrl(currentSong.SongUrl);
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -327,28 +327,28 @@ namespace NadekoBot.Modules.Music
var count = ids.Count(); var count = ids.Count();
var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
var cancelSource = new CancellationTokenSource(); var cancelSource = new CancellationTokenSource();
var gusr = (IGuildUser)umsg.Author; var gusr = (IGuildUser)umsg.Author;
while (ids.Any() && !cancelSource.IsCancellationRequested) while (ids.Any() && !cancelSource.IsCancellationRequested)
{ {
var tasks = Task.WhenAll(ids.Take(5).Select(async id => var tasks = Task.WhenAll(ids.Take(5).Select(async id =>
{ {
if (cancelSource.Token.IsCancellationRequested) if (cancelSource.Token.IsCancellationRequested)
return; return;
try try
{ {
await QueueSong(gusr, channel, gusr.VoiceChannel, id, true).ConfigureAwait(false); await QueueSong(gusr, channel, gusr.VoiceChannel, id, true).ConfigureAwait(false);
} }
catch (SongNotFoundException) { } catch (SongNotFoundException) { }
catch { try { cancelSource.Cancel(); } catch { } } 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));
ids = ids.Skip(5); ids = ids.Skip(5);
} }
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
} }
@ -404,7 +404,7 @@ namespace NadekoBot.Modules.Music
var dir = new DirectoryInfo(arg); var dir = new DirectoryInfo(arg);
var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories) var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories)
.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System));
var gusr = (IGuildUser)umsg.Author; var gusr = (IGuildUser)umsg.Author;
foreach (var file in fileEnum) foreach (var file in fileEnum)
{ {
try try
@ -488,7 +488,7 @@ namespace NadekoBot.Modules.Music
.AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true)) .AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true))
.AddField(fb => fb.WithName("**Song Name**").WithValue(song.PrettyName).WithIsInline(true)) .AddField(fb => fb.WithName("**Song Name**").WithValue(song.PrettyName).WithIsInline(true))
.WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}")) .WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.WithErrorColor(); .WithErrorColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -546,7 +546,7 @@ namespace NadekoBot.Modules.Music
.WithAuthor(eab => eab.WithName("Song Moved").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Song Moved").WithMusicIcon())
.AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true))
.AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true))
.WithFooter(ef => ef.WithText($"{s.PrettyProvider} | {s.QueuerName}")) .WithFooter(ef => ef.WithText($"{s.PrettyProvider} | {s.QueuerName}"))
.WithOkColor(); .WithOkColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -583,7 +583,7 @@ namespace NadekoBot.Modules.Music
.WithOkColor() .WithOkColor()
.WithAuthor(eab => eab.WithMusicIcon().WithName("🔂 Repeating track")) .WithAuthor(eab => eab.WithMusicIcon().WithName("🔂 Repeating track"))
.WithDescription(currentSong.PrettyName) .WithDescription(currentSong.PrettyName)
.WithFooter(ef => ef.WithText(currentSong.PrettyInfo)) .WithFooter(ef => ef.WithText(currentSong.PrettyInfo))
.Build()).ConfigureAwait(false); .Build()).ConfigureAwait(false);
else else
await channel.SendConfirmAsync($"🔂 Current track repeat stopped.") await channel.SendConfirmAsync($"🔂 Current track repeat stopped.")
@ -658,9 +658,9 @@ namespace NadekoBot.Modules.Music
} }
IUserMessage msg = null; 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); }
var usr = (IGuildUser)umsg.Author; var usr = (IGuildUser)umsg.Author;
foreach (var item in mpl.Songs) foreach (var item in mpl.Songs)
{ {
try try
{ {
@ -815,7 +815,7 @@ namespace NadekoBot.Modules.Music
{ {
if (finishedMessage != null) if (finishedMessage != null)
finishedMessage.DeleteAfter(0); finishedMessage.DeleteAfter(0);
finishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() finishedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Finished Song").WithMusicIcon())
.WithDescription(song.PrettyName) .WithDescription(song.PrettyName)
@ -831,13 +831,13 @@ namespace NadekoBot.Modules.Music
catch { } catch { }
}; };
IUserMessage playingMessage = null; IUserMessage playingMessage = null;
mp.OnStarted += async (player, song) => mp.OnStarted += async (player, song) =>
{ {
try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { }
var sender = player as MusicPlayer; var sender = player as MusicPlayer;
if (sender == null) if (sender == null)
return; return;
try try
{ {
if (playingMessage != null) if (playingMessage != null)
@ -846,7 +846,7 @@ namespace NadekoBot.Modules.Music
playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon())
.WithDescription(song.PrettyName) .WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText($"🔉 {(int)(sender.Volume * 100)}% | {song.PrettyInfo}")) .WithFooter(ef => ef.WithText($"🔉 {(int)(sender.Volume * 100)}% | {song.PrettyInfo}"))
.Build()) .Build())
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@ -897,7 +897,7 @@ namespace NadekoBot.Modules.Music
var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Queued Song").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Queued Song").WithMusicIcon())
.WithDescription($"{resolvedSong.PrettyName}\nQueue #{musicPlayer.Playlist.Count + 1}") .WithDescription($"{resolvedSong.PrettyName}\nQueue #{musicPlayer.Playlist.Count + 1}")
.WithThumbnail(tn => tn.Url = resolvedSong.Thumbnail) .WithThumbnail(tn => tn.Url = resolvedSong.Thumbnail)
.WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider)) .WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider))
.Build()) .Build())
.ConfigureAwait(false); .ConfigureAwait(false);