This commit is contained in:
Kwoth 2016-12-25 06:11:58 +01:00
parent 1c9e6b3a4a
commit 824916a41e
2 changed files with 56 additions and 3 deletions

View File

@ -30,6 +30,17 @@ namespace NadekoBot.Modules.Music.Classes
{ {
private IAudioClient audioClient { get; set; } private IAudioClient audioClient { get; set; }
/// <summary>
/// Player will prioritize different queuer name
/// over the song position in the playlist
/// </summary>
public bool FairPlay { get; set; } = false;
/// <summary>
/// Users who recently got their music wish
/// </summary>
private ConcurrentHashSet<string> recentlyPlayedUsers { get; } = new ConcurrentHashSet<string>();
private readonly List<Song> playlist = new List<Song>(); private readonly List<Song> playlist = new List<Song>();
public IReadOnlyCollection<Song> Playlist => playlist; public IReadOnlyCollection<Song> Playlist => playlist;
@ -107,11 +118,13 @@ namespace NadekoBot.Modules.Music.Classes
} }
CurrentSong = GetNextSong(); CurrentSong = GetNextSong();
RemoveSongAt(0);
if (CurrentSong == null) if (CurrentSong == null)
continue; continue;
var index = playlist.IndexOf(CurrentSong);
if (index != -1)
RemoveSongAt(index);
OnStarted(this, CurrentSong); OnStarted(this, CurrentSong);
await CurrentSong.Play(audioClient, cancelToken); await CurrentSong.Play(audioClient, cancelToken);
@ -183,8 +196,26 @@ namespace NadekoBot.Modules.Music.Classes
return volume; return volume;
} }
private Song GetNextSong() => private Song GetNextSong()
playlist.FirstOrDefault(); {
if (!FairPlay)
{
return playlist.FirstOrDefault();
}
var song = playlist.FirstOrDefault(c => !recentlyPlayedUsers.Contains(c.QueuerName))
?? playlist.FirstOrDefault();
if (song == null)
return null;
if (recentlyPlayedUsers.Contains(song.QueuerName))
{
recentlyPlayedUsers.Clear();
}
recentlyPlayedUsers.Add(song.QueuerName);
return song ?? playlist.FirstOrDefault();
}
public void Shuffle() public void Shuffle()
{ {

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Searches.Commands.Models
{
public struct GoogleSearchResult
{
public string Title { get; }
public string Link { get; }
public string Text { get; }
public GoogleSearchResult(string title, string link, string text)
{
this.Title = title;
this.Link = link;
this.Text = text;
}
}
}