Added .qn and fixed .hangman bugs

This commit is contained in:
Master Kwoth 2017-08-05 12:38:53 +02:00
parent 79d3fca7e4
commit 540209706d
6 changed files with 68 additions and 18 deletions

View File

@ -62,15 +62,14 @@ namespace NadekoBot.Modules.Games.Common.Connect4
private Timer _playerTimeoutTimer; private Timer _playerTimeoutTimer;
/* rows = 4, columns = 3, total = 12 /* [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] * [ ][ ][ ][ ][ ][ ]
* [][][][][][] */
* */
public Connect4Game(ulong userId, string userName) public Connect4Game(ulong userId, string userName)
{ {

View File

@ -67,8 +67,8 @@ namespace NadekoBot.Modules.Games.Common.Hangman
Errors++; Errors++;
if (Errors > MaxErrors) if (Errors > MaxErrors)
{ {
CurrentPhase = Phase.Ended;
var _ = OnGameEnded(this, null); var _ = OnGameEnded(this, null);
CurrentPhase = Phase.Ended;
} }
} }
@ -101,8 +101,8 @@ namespace NadekoBot.Modules.Games.Common.Hangman
if (input != Term.Word) // failed if (input != Term.Word) // failed
return; return;
CurrentPhase = Phase.Ended;
var _ = OnGameEnded?.Invoke(this, userName); var _ = OnGameEnded?.Invoke(this, userName);
CurrentPhase = Phase.Ended;
return; return;
} }
@ -128,6 +128,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman
.Where(c => char.IsLetterOrDigit(c))))) .Where(c => char.IsLetterOrDigit(c)))))
{ {
var _ = OnGameEnded.Invoke(this, userName); //if all letters are guessed var _ = OnGameEnded.Invoke(this, userName); //if all letters are guessed
CurrentPhase = Phase.Ended;
} }
else //guessed but not last letter else //guessed but not last letter
{ {

View File

@ -405,6 +405,16 @@ namespace NadekoBot.Modules.Music.Common
} }
} }
public int EnqueueNext(SongInfo song)
{
lock (locker)
{
if (Exited)
return -1;
return Queue.AddNext(song);
}
}
public void SetIndex(int index) public void SetIndex(int index)
{ {
if (index < 0) if (index < 0)

View File

@ -78,6 +78,27 @@ namespace NadekoBot.Modules.Music.Common
} }
} }
public int AddNext(SongInfo song)
{
song.ThrowIfNull(nameof(song));
lock (locker)
{
if (MaxQueueSize != 0 && Songs.Count >= MaxQueueSize)
throw new QueueFullException();
var curSong = Current.Song;
if (curSong == null)
{
Songs.AddLast(song);
return Songs.Count;
}
var songlist = Songs.ToList();
songlist.Insert(CurrentIndex + 1, song);
Songs = new LinkedList<SongInfo>(songlist);
return CurrentIndex + 1;
}
}
public void Next(int skipCount = 1) public void Next(int skipCount = 1)
{ {
lock(locker) lock(locker)

View File

@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Music
// return Task.CompletedTask; // return Task.CompletedTask;
//} //}
private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent) private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent, bool queueFirst = false)
{ {
if (songInfo == null) if (songInfo == null)
{ {
@ -110,8 +110,9 @@ namespace NadekoBot.Modules.Music
int index; int index;
try try
{ {
_log.Info("Added"); index = queueFirst
index = mp.Enqueue(songInfo); ? mp.EnqueueNext(songInfo)
: mp.Enqueue(songInfo);
} }
catch (QueueFullException) catch (QueueFullException)
{ {
@ -175,13 +176,22 @@ namespace NadekoBot.Modules.Music
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Queue([Remainder] string query) public async Task Queue([Remainder] string query)
{ {
_log.Info("Getting player");
var mp = await _service.GetOrCreatePlayer(Context); var mp = await _service.GetOrCreatePlayer(Context);
_log.Info("Resolving song");
var songInfo = await _service.ResolveSong(query, Context.User.ToString()); var songInfo = await _service.ResolveSong(query, Context.User.ToString());
_log.Info("Queueing song");
try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; } try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; }
_log.Info("--------------"); if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{
Context.Message.DeleteAfter(10);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task QueueNext([Remainder] string query)
{
var mp = await _service.GetOrCreatePlayer(Context);
var songInfo = await _service.ResolveSong(query, Context.User.ToString());
try { await InternalQueue(mp, songInfo, false, true); } catch (QueueFullException) { return; }
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages) if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{ {
Context.Message.DeleteAfter(10); Context.Message.DeleteAfter(10);

View File

@ -1539,6 +1539,15 @@
<data name="queue_usage" xml:space="preserve"> <data name="queue_usage" xml:space="preserve">
<value>`{0}q Dream Of Venice`</value> <value>`{0}q Dream Of Venice`</value>
</data> </data>
<data name="queuenext_cmd" xml:space="preserve">
<value>queuenext qn</value>
</data>
<data name="queuenext_desc" xml:space="preserve">
<value>Works the same as `{0}queue` command, except it enqueues the new song after the current one. **You must be in a voice channel**.</value>
</data>
<data name="queuenext_usage" xml:space="preserve">
<value>`{0}qn Dream Of Venice`</value>
</data>
<data name="queuesearch_cmd" xml:space="preserve"> <data name="queuesearch_cmd" xml:space="preserve">
<value>queuesearch qs yqs</value> <value>queuesearch qs yqs</value>
</data> </data>