Fixed bugs, added .play command which acts as .n 1 when used without arguments or as .q command when used with serach query
This commit is contained in:
parent
5015b6ad95
commit
8e1c20624d
@ -1,9 +1,4 @@
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -134,7 +134,7 @@ namespace NadekoBot.Modules.Administration
|
||||
await user.RemoveRolesAsync(userRoles).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("rar", Format.Bold(user.ToString())).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
await ReplyErrorLocalized("rar_err").ConfigureAwait(false);
|
||||
}
|
||||
|
@ -84,7 +84,16 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent)
|
||||
{
|
||||
var qData = mp.Enqueue(songInfo);
|
||||
(bool Success, int Index) qData;
|
||||
try
|
||||
{
|
||||
qData = mp.Enqueue(songInfo);
|
||||
}
|
||||
catch (QueueFullException)
|
||||
{
|
||||
await ReplyErrorLocalized("queue_full", mp.MaxQueueSize).ConfigureAwait(false);
|
||||
throw;
|
||||
}
|
||||
if (qData.Success)
|
||||
{
|
||||
if (!silent)
|
||||
@ -111,8 +120,16 @@ namespace NadekoBot.Modules.Music
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//todo add play command. .play = .n, .play whatever = .q whatever
|
||||
//todo test play
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Play([Remainder]string query = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
try { return Queue(query); } catch (QueueFullException) { return Task.CompletedTask; }
|
||||
else
|
||||
return Next();
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@ -120,7 +137,7 @@ namespace NadekoBot.Modules.Music
|
||||
{
|
||||
var mp = await _music.GetOrCreatePlayer(Context);
|
||||
var songInfo = await _music.ResolveSong(query, Context.User.ToString());
|
||||
await InternalQueue(mp, songInfo, false);
|
||||
try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; }
|
||||
|
||||
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
|
||||
{
|
||||
@ -241,7 +258,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
var mp = await _music.GetOrCreatePlayer(Context);
|
||||
|
||||
mp.Next();
|
||||
mp.Next(skipCount);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -520,7 +537,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
}
|
||||
//todo test shuffle
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ShufflePlaylist()
|
||||
@ -747,7 +764,6 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
//}
|
||||
|
||||
//todo test smq
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task SetMaxQueue(uint size = 0)
|
||||
@ -756,7 +772,7 @@ namespace NadekoBot.Modules.Music
|
||||
return;
|
||||
var mp = await _music.GetOrCreatePlayer(Context);
|
||||
|
||||
mp.SetMaxQueueSize(size);
|
||||
mp.MaxQueueSize = size;
|
||||
|
||||
if (size == 0)
|
||||
await ReplyConfirmLocalized("max_queue_unlimited").ConfigureAwait(false);
|
||||
|
@ -212,8 +212,6 @@ namespace NadekoBot
|
||||
var pokemonService = new PokemonService();
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
//initialize Services
|
||||
Services = new NServiceProvider.ServiceProviderBuilder()
|
||||
.Add<ILocalization>(Localization)
|
||||
@ -269,7 +267,6 @@ namespace NadekoBot
|
||||
.Add<NadekoBot>(this)
|
||||
.Build();
|
||||
|
||||
|
||||
CommandHandler.AddServices(Services);
|
||||
|
||||
//setup typereaders
|
||||
|
@ -1467,6 +1467,15 @@
|
||||
<data name="next_usage" xml:space="preserve">
|
||||
<value>`{0}n` or `{0}n 5`</value>
|
||||
</data>
|
||||
<data name="play_cmd" xml:space="preserve">
|
||||
<value>play start</value>
|
||||
</data>
|
||||
<data name="play_desc" xml:space="preserve">
|
||||
<value>If no arguments are specified, acts as `{0}next 1` command. If you specify a search query, acts as a `{0}q` command</value>
|
||||
</data>
|
||||
<data name="play_usage" xml:space="preserve">
|
||||
<value>`{0}play` or `{0}play Dream Of Venice`</value>
|
||||
</data>
|
||||
<data name="stop_cmd" xml:space="preserve">
|
||||
<value>stop s</value>
|
||||
</data>
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace NadekoBot.Services.Music
|
||||
{
|
||||
public class PlaylistFullException : Exception
|
||||
public class QueueFullException : Exception
|
||||
{
|
||||
public PlaylistFullException(string message) : base(message)
|
||||
public QueueFullException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
public PlaylistFullException() : base("Queue is full.") { }
|
||||
public QueueFullException() : base("Queue is full.") { }
|
||||
}
|
||||
|
||||
public class SongNotFoundException : Exception
|
||||
|
@ -45,6 +45,11 @@ namespace NadekoBot.Services.Music
|
||||
public bool Shuffle { get; private set; }
|
||||
public bool Autoplay { get; private set; }
|
||||
public bool RepeatPlaylist { get; private set; } = true;
|
||||
public uint MaxQueueSize
|
||||
{
|
||||
get => Queue.MaxQueueSize;
|
||||
set => Queue.MaxQueueSize = value;
|
||||
}
|
||||
|
||||
private IAudioClient _audioClient;
|
||||
private readonly object locker = new object();
|
||||
@ -137,7 +142,6 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
finally
|
||||
{
|
||||
_log.Info("Next song");
|
||||
do
|
||||
{
|
||||
await Task.Delay(500);
|
||||
@ -146,7 +150,10 @@ namespace NadekoBot.Services.Music
|
||||
if (!RepeatCurrentSong) //if repeating current song, just ignore other settings, and play this song again (don't change the index)
|
||||
{
|
||||
if (Shuffle)
|
||||
{
|
||||
_log.Info("Random song");
|
||||
Queue.Random(); //if shuffle is set, set current song index to a random number
|
||||
}
|
||||
else
|
||||
{
|
||||
//if last song, and autoplay is enabled, and if it's a youtube song
|
||||
@ -155,19 +162,25 @@ namespace NadekoBot.Services.Music
|
||||
{
|
||||
try
|
||||
{
|
||||
_log.Info("Loading related song");
|
||||
//todo test autoplay
|
||||
await _musicService.TryQueueRelatedSongAsync(data.Song.Query, OutputTextChannel, VoiceChannel);
|
||||
Queue.Next();
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
_log.Info("Loading related song failed.");
|
||||
}
|
||||
}
|
||||
else if (Queue.Count == data.Index && !RepeatPlaylist)
|
||||
{
|
||||
//todo test repeatplaylist
|
||||
_log.Info("Stopping because repeatplaylist is disabled");
|
||||
Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Info("Next song");
|
||||
Queue.Next();
|
||||
}
|
||||
}
|
||||
@ -208,10 +221,11 @@ namespace NadekoBot.Services.Music
|
||||
return (true, Queue.Count);
|
||||
}
|
||||
|
||||
public void Next()
|
||||
public void Next(int skipCount)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
Queue.Next(skipCount - 1);
|
||||
Stopped = false;
|
||||
Unpause();
|
||||
CancelCurrentSong();
|
||||
@ -364,11 +378,6 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMaxQueueSize(uint size)
|
||||
{
|
||||
Queue.SetMaxQueueSize(size);
|
||||
}
|
||||
|
||||
public void SetVoiceChannel(IVoiceChannel vch)
|
||||
{
|
||||
VoiceChannel = vch;
|
||||
|
@ -50,23 +50,37 @@ namespace NadekoBot.Services.Music
|
||||
}
|
||||
}
|
||||
|
||||
public uint maxQueueSize { get; private set; }
|
||||
private uint _maxQueueSize;
|
||||
public uint MaxQueueSize
|
||||
{
|
||||
get => _maxQueueSize;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
_maxQueueSize = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(SongInfo song)
|
||||
{
|
||||
song.ThrowIfNull(nameof(song));
|
||||
lock (locker)
|
||||
{
|
||||
if(maxQueueSize !=0 && CurrentIndex >= maxQueueSize)
|
||||
throw new PlaylistFullException();
|
||||
if(MaxQueueSize != 0 && Songs.Count >= MaxQueueSize)
|
||||
throw new QueueFullException();
|
||||
Songs.AddLast(song);
|
||||
}
|
||||
}
|
||||
|
||||
public void Next()
|
||||
public void Next(int skipCount = 1)
|
||||
{
|
||||
lock(locker)
|
||||
CurrentIndex++;
|
||||
CurrentIndex += skipCount;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@ -133,16 +147,5 @@ namespace NadekoBot.Services.Music
|
||||
CurrentIndex = new NadekoRandom().Next(Songs.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMaxQueueSize(uint size)
|
||||
{
|
||||
if (size < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(size));
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
maxQueueSize = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
|
||||
Windows Guide: https://goo.gl/OjKk8F
|
||||
Linux Guide: https://goo.gl/ShjCUo");
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Info(ex);
|
||||
|
Loading…
Reference in New Issue
Block a user