Music format

This commit is contained in:
Kwoth 2016-12-21 13:14:24 +01:00
parent ed505a7809
commit 1d2e44c7be

View File

@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using NadekoBot.Services.Database.Models;
using System.Text.RegularExpressions;
using System.Threading;
namespace NadekoBot.Modules.Music
{
@ -100,7 +101,7 @@ namespace NadekoBot.Modules.Music
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) return Task.CompletedTask;
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
if(MusicPlayers.TryRemove(Context.Guild.Id, out musicPlayer))
if (MusicPlayers.TryRemove(Context.Guild.Id, out musicPlayer))
musicPlayer.Destroy();
return Task.CompletedTask;
}
@ -298,15 +299,22 @@ namespace NadekoBot.Modules.Music
var count = idArray.Length;
var msg =
await Context.Channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
foreach (var id in idArray)
var cancelSource = new CancellationTokenSource();
var tasks = Task.WhenAll(idArray.Select(async id =>
{
if (cancelSource.Token.IsCancellationRequested)
return;
try
{
await QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, id, true).ConfigureAwait(false);
}
catch (SongNotFoundException) { }
catch { break; }
}
catch { try { cancelSource.Cancel(); } catch { } }
}));
await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
}
@ -557,7 +565,8 @@ namespace NadekoBot.Modules.Music
var curSong = musicPlayer.CurrentSong;
var songs = musicPlayer.Playlist.Append(curSong)
.Select(s=> new PlaylistSong() {
.Select(s => new PlaylistSong()
{
Provider = s.SongInfo.Provider,
ProviderType = s.SongInfo.ProviderType,
Title = s.SongInfo.Title,
@ -677,8 +686,6 @@ namespace NadekoBot.Modules.Music
[RequireContext(ContextType.Guild)]
public async Task Goto(int time)
{
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))
return;