added !m rm all, changes to music

This commit is contained in:
Master Kwoth 2016-02-20 17:38:02 +01:00
parent a0ec4db004
commit 5da3492b12
2 changed files with 15 additions and 8 deletions

View File

@ -205,7 +205,7 @@ namespace NadekoBot.Classes.Music {
buffer.Position = newPos; buffer.Position = newPos;
} }
} }
int blockSize = 1024; int blockSize = 2048;
var buf = new byte[blockSize]; var buf = new byte[blockSize];
int read = 0; int read = 0;
read = await p.StandardOutput.BaseStream.ReadAsync(buf, 0, blockSize); read = await p.StandardOutput.BaseStream.ReadAsync(buf, 0, blockSize);
@ -213,8 +213,7 @@ namespace NadekoBot.Classes.Music {
if (read == 0) { if (read == 0) {
if (attempt == 5) { if (attempt == 5) {
try { try {
p.CancelOutputRead(); p.Dispose();
p.Close();
} }
catch { } catch { }
@ -242,7 +241,7 @@ namespace NadekoBot.Classes.Music {
if (parent.OnBuffering != null) if (parent.OnBuffering != null)
parent.OnBuffering(); parent.OnBuffering();
Task.Factory.StartNew(async () => { Task.Run(async () => {
await BufferSong(); await BufferSong();
}).ConfigureAwait(false); }).ConfigureAwait(false);
@ -301,7 +300,7 @@ namespace NadekoBot.Classes.Music {
parent.MusicControls.VoiceClient.Send(voiceBuffer, 0, readCount); parent.MusicControls.VoiceClient.Send(voiceBuffer, 0, readCount);
while (IsPaused) { while (IsPaused) {
await Task.Delay(50); await Task.Delay(100);
} }
} }
parent.MusicControls.VoiceClient.Wait(); parent.MusicControls.VoiceClient.Wait();

View File

@ -225,13 +225,21 @@ namespace NadekoBot.Modules {
}); });
cgb.CreateCommand("rm") cgb.CreateCommand("rm")
.Description("Removes a song by a # from the queue") .Description("Removes a song by a # from the queue or 'all' to remove whole queue.")
.Parameter("num",ParameterType.Required) .Parameter("num",ParameterType.Required)
.Do(async e => { .Do(async e => {
var arg = e.GetArg("num"); var arg = e.GetArg("num");
int num;
MusicControls mc; MusicControls mc;
if (!musicPlayers.TryGetValue(e.Server, out mc) || !int.TryParse(arg, out num)) { if (!musicPlayers.TryGetValue(e.Server, out mc)) {
return;
}
if (arg?.ToLower() == "all") {
mc.SongQueue?.Clear();
await e.Send($"🎵Queue cleared!");
return;
}
int num;
if (!int.TryParse(arg, out num)) {
return; return;
} }
if (num <= 0 || num > mc.SongQueue.Count) if (num <= 0 || num > mc.SongQueue.Count)