Fixed song spam for good

This commit is contained in:
Master Kwoth 2017-07-07 09:54:25 +02:00
parent 8331af2870
commit 793cbdf608
2 changed files with 19 additions and 1 deletions

View File

@ -113,6 +113,8 @@ namespace NadekoBot.Services.Music
private bool newVoiceChannel = false; private bool newVoiceChannel = false;
private readonly IGoogleApiService _google; private readonly IGoogleApiService _google;
private bool cancel = false;
private ConcurrentHashSet<string> RecentlyPlayedUsers { get; } = new ConcurrentHashSet<string>(); private ConcurrentHashSet<string> RecentlyPlayedUsers { get; } = new ConcurrentHashSet<string>();
public TimeSpan TotalPlaytime public TimeSpan TotalPlaytime
{ {
@ -148,6 +150,7 @@ namespace NadekoBot.Services.Music
while (!Exited) while (!Exited)
{ {
_bytesSent = 0; _bytesSent = 0;
cancel = false;
CancellationToken cancelToken; CancellationToken cancelToken;
(int Index, SongInfo Song) data; (int Index, SongInfo Song) data;
lock (locker) lock (locker)
@ -210,6 +213,7 @@ namespace NadekoBot.Services.Music
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
_log.Info("Song Canceled"); _log.Info("Song Canceled");
cancel = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -230,6 +234,13 @@ namespace NadekoBot.Services.Music
} }
OnCompleted?.Invoke(this, data.Song); OnCompleted?.Invoke(this, data.Song);
if (_bytesSent == 0 && !cancel)
{
lock (locker)
Queue.RemoveSong(data.Song);
_log.Info("Song removed because it can't play");
}
} }
} }
try try
@ -319,7 +330,6 @@ namespace NadekoBot.Services.Music
} }
do do
{ {
_log.Info("Waiting for something to happen");
await Task.Delay(500); await Task.Delay(500);
} }
while ((Queue.Count == 0 || Stopped) && !Exited); while ((Queue.Count == 0 || Stopped) && !Exited);

View File

@ -163,5 +163,13 @@ namespace NadekoBot.Services.Music
return s; return s;
} }
} }
public void RemoveSong(SongInfo song)
{
lock (locker)
{
Songs.Remove(song);
}
}
} }
} }