!m smq added (setmaxqueue)

This commit is contained in:
Master Kwoth 2016-07-08 05:20:10 +02:00
parent 8044bbe978
commit adc449f765
4 changed files with 87 additions and 12 deletions

View File

@ -51,6 +51,7 @@ namespace NadekoBot.Modules.Music.Classes
public bool RepeatSong { get; private set; } = false;
public bool RepeatPlaylist { get; private set; } = false;
public bool Autoplay { get; set; } = false;
public uint MaxQueueSize { get; set; } = 0;
public MusicPlayer(Channel startingVoiceChannel, float? defaultVolume)
{
@ -172,6 +173,7 @@ namespace NadekoBot.Modules.Music.Classes
{
if (s == null)
throw new ArgumentNullException(nameof(s));
ThrowIfQueueFull();
lock (playlistLock)
{
s.MusicPlayer = this;
@ -244,5 +246,13 @@ namespace NadekoBot.Modules.Music.Classes
internal bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist;
internal bool ToggleAutoplay() => this.Autoplay = !this.Autoplay;
internal void ThrowIfQueueFull()
{
if (MaxQueueSize == 0)
return;
if (playlist.Count >= MaxQueueSize)
throw new PlaylistFullException();
}
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace NadekoBot.Modules.Music.Classes
{
class PlaylistFullException : Exception
{
public PlaylistFullException(string message) : base(message)
{
}
public PlaylistFullException() : base("Queue is full.") { }
}
}

View File

@ -230,7 +230,7 @@ namespace NadekoBot.Modules.Music
});
cgb.CreateCommand("max")
.Description("Sets the music volume to 100% (real max is actually 150%).\n**Usage**: `!m max`")
.Description("Sets the music volume to 100%.\n**Usage**: `!m max`")
.Do(e =>
{
MusicPlayer musicPlayer;
@ -296,7 +296,7 @@ namespace NadekoBot.Modules.Music
var ids = await SearchHelper.GetVideoIDs(plId, 500).ConfigureAwait(false);
if (ids == null || ids.Count == 0)
{
await e.Channel.SendMessage($"🎵`Failed to find any songs.`");
await e.Channel.SendMessage($"🎵 `Failed to find any songs.`");
return;
}
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
@ -310,6 +310,8 @@ namespace NadekoBot.Modules.Music
{
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, id, true).ConfigureAwait(false);
}
catch (PlaylistFullException)
{ break; }
catch { }
}
await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false);
@ -335,14 +337,18 @@ namespace NadekoBot.Modules.Music
foreach (var svideo in scvids.Skip(1))
{
mp.AddSong(new Song(new Classes.SongInfo
try
{
Title = svideo.FullName,
Provider = "SoundCloud",
Uri = svideo.StreamLink,
ProviderType = MusicType.Normal,
Query = svideo.TrackLink,
}), e.User.Name);
mp.AddSong(new Song(new Classes.SongInfo
{
Title = svideo.FullName,
Provider = "SoundCloud",
Uri = svideo.StreamLink,
ProviderType = MusicType.Normal,
Query = svideo.TrackLink,
}), e.User.Name);
}
catch (PlaylistFullException) { break; }
}
});
@ -362,7 +368,15 @@ namespace NadekoBot.Modules.Music
.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System));
foreach (var file in fileEnum)
{
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
try
{
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
}
catch (PlaylistFullException)
{
break;
}
catch { }
}
await e.Channel.SendMessage("🎵 `Directory queue complete.`").ConfigureAwait(false);
}
@ -481,6 +495,29 @@ namespace NadekoBot.Modules.Music
});
cgb.CreateCommand("setmaxqueue")
.Alias("smq")
.Description($"Sets a maximum queue size. Supply 0 or no argument to have no limit. \n**Usage**: `{Prefix} smq` 50 or `{Prefix} smq`")
.Parameter("size", ParameterType.Unparsed)
.Do(async e =>
{
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
{
return;
}
var sizeStr = e.GetArg("size")?.Trim();
uint size = 0;
if (string.IsNullOrWhiteSpace(sizeStr) || !uint.TryParse(sizeStr, out size))
{
size = 0;
}
musicPlayer.MaxQueueSize = size;
await e.Channel.SendMessage($"🎵 `Max queue set to {(size == 0 ? ("unlimited") : size + " tracks")}`");
});
cgb.CreateCommand("cleanup")
.Description("Cleans up hanging voice connections. **Bot Owner Only!**\n**Usage**: `!m cleanup`")
.AddCheck(SimpleCheckers.OwnerOnly())
@ -630,6 +667,10 @@ namespace NadekoBot.Modules.Music
{
await QueueSong(e.User, textCh, voiceCh, si.Query, true, (MusicType)si.ProviderType).ConfigureAwait(false);
}
catch (PlaylistFullException)
{
break;
}
catch (Exception ex)
{
Console.WriteLine($"Failed QueueSong in load playlist. {ex}");
@ -800,8 +841,19 @@ namespace NadekoBot.Modules.Music
};
return mp;
});
var resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);
musicPlayer.AddSong(resolvedSong, queuer.Name);
Song resolvedSong;
try
{
musicPlayer.ThrowIfQueueFull();
resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);
musicPlayer.AddSong(resolvedSong, queuer.Name);
}
catch (PlaylistFullException)
{
await textCh.SendMessage($"🎵 `Queue is full at {musicPlayer.MaxQueueSize}/{musicPlayer.MaxQueueSize}.` ");
throw;
}
if (!silent)
{
var queuedMessage = await textCh.SendMessage($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count}`").ConfigureAwait(false);

View File

@ -144,6 +144,7 @@
<Compile Include="Classes\FlowersHandler.cs" />
<Compile Include="Modules\Conversations\Commands\RipCommand.cs" />
<Compile Include="Modules\CustomReactions\CustomReactions.cs" />
<Compile Include="Modules\Music\Classes\PlaylistFullException.cs" />
<Compile Include="Modules\Programming\Commands\HaskellRepl.cs" />
<Compile Include="Modules\Programming\ProgrammingModule.cs" />
<Compile Include="Modules\Searches\Commands\EvalCommand.cs" />