diff --git a/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs b/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs index 0c6bc173..0ba9acb8 100644 --- a/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs @@ -62,15 +62,14 @@ namespace NadekoBot.Modules.Games.Common.Connect4 private Timer _playerTimeoutTimer; - /* rows = 4, columns = 3, total = 12 - * [][][][][][] - * [][][][][][] - * [][][][][][] - * [][][][][][] - * [][][][][][] - * [][][][][][] - * [][][][][][] - * */ + /* [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + * [ ][ ][ ][ ][ ][ ] + */ public Connect4Game(ulong userId, string userName) { diff --git a/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs b/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs index 94f14835..6c91edc1 100644 --- a/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs +++ b/src/NadekoBot/Modules/Games/Common/Hangman/Hangman.cs @@ -67,8 +67,8 @@ namespace NadekoBot.Modules.Games.Common.Hangman Errors++; if (Errors > MaxErrors) { - CurrentPhase = Phase.Ended; var _ = OnGameEnded(this, null); + CurrentPhase = Phase.Ended; } } @@ -101,8 +101,8 @@ namespace NadekoBot.Modules.Games.Common.Hangman if (input != Term.Word) // failed return; - CurrentPhase = Phase.Ended; var _ = OnGameEnded?.Invoke(this, userName); + CurrentPhase = Phase.Ended; return; } @@ -128,6 +128,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman .Where(c => char.IsLetterOrDigit(c))))) { var _ = OnGameEnded.Invoke(this, userName); //if all letters are guessed + CurrentPhase = Phase.Ended; } else //guessed but not last letter { diff --git a/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs index 00e38c98..b578904f 100644 --- a/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicPlayer.cs @@ -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) { if (index < 0) diff --git a/src/NadekoBot/Modules/Music/Common/MusicQueue.cs b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs index 4927b21e..81241adf 100644 --- a/src/NadekoBot/Modules/Music/Common/MusicQueue.cs +++ b/src/NadekoBot/Modules/Music/Common/MusicQueue.cs @@ -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(songlist); + return CurrentIndex + 1; + } + } + public void Next(int skipCount = 1) { lock(locker) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 6b5499f3..5f1a99b3 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Music // 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) { @@ -110,8 +110,9 @@ namespace NadekoBot.Modules.Music int index; try { - _log.Info("Added"); - index = mp.Enqueue(songInfo); + index = queueFirst + ? mp.EnqueueNext(songInfo) + : mp.Enqueue(songInfo); } catch (QueueFullException) { @@ -175,13 +176,22 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task Queue([Remainder] string query) { - _log.Info("Getting player"); var mp = await _service.GetOrCreatePlayer(Context); - _log.Info("Resolving song"); var songInfo = await _service.ResolveSong(query, Context.User.ToString()); - _log.Info("Queueing song"); 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) { Context.Message.DeleteAfter(10); diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 994ad981..ab6beaa3 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1539,6 +1539,15 @@ `{0}q Dream Of Venice` + + queuenext qn + + + Works the same as `{0}queue` command, except it enqueues the new song after the current one. **You must be in a voice channel**. + + + `{0}qn Dream Of Venice` + queuesearch qs yqs