music fixes, added !m rm # command

This commit is contained in:
Master Kwoth 2016-02-14 23:48:07 +01:00
parent 5901e25c42
commit 260f57372a
3 changed files with 52 additions and 21 deletions

View File

@ -31,7 +31,7 @@ namespace NadekoBot.Classes.Music {
public string Title { get; internal set; } = String.Empty; public string Title { get; internal set; } = String.Empty;
private string Provider { get; set; } private string Provider { get; set; }
public string FullPrettyName => $"**【 {Title.TrimTo(55)} 】**`{Provider}`"; public string FullPrettyName => $"**【 {Title.TrimTo(55)} 】**`{(Provider == null ? "-" : Provider)}`";
private MusicStreamer musicStreamer = null; private MusicStreamer musicStreamer = null;
public StreamState State => musicStreamer?.State ?? privateState; public StreamState State => musicStreamer?.State ?? privateState;
@ -74,7 +74,8 @@ namespace NadekoBot.Classes.Music {
Provider = "SoundCloud"; Provider = "SoundCloud";
uri = svideo.StreamLink; uri = svideo.StreamLink;
Console.WriteLine(uri); Console.WriteLine(uri);
} else { }
else {
if (OnResolving != null) if (OnResolving != null)
OnResolving(); OnResolving();
@ -93,7 +94,8 @@ namespace NadekoBot.Classes.Music {
Provider = "YouTube"; Provider = "YouTube";
uri = video.Uri; uri = video.Uri;
} }
} catch (Exception ex) { }
catch (Exception ex) {
privateState = StreamState.Completed; privateState = StreamState.Completed;
if (OnResolvingFailed != null) if (OnResolvingFailed != null)
OnResolvingFailed(ex.Message); OnResolvingFailed(ex.Message);
@ -134,10 +136,12 @@ namespace NadekoBot.Classes.Music {
} }
} }
await musicStreamer.StartPlayback(); await musicStreamer.StartPlayback();
} catch (TimeoutException) { }
catch (TimeoutException) {
Console.WriteLine("Resolving timed out."); Console.WriteLine("Resolving timed out.");
privateState = StreamState.Completed; privateState = StreamState.Completed;
} catch (Exception ex) { }
catch (Exception ex) {
Console.WriteLine("Error in start playback." + ex.Message); Console.WriteLine("Error in start playback." + ex.Message);
privateState = StreamState.Completed; privateState = StreamState.Completed;
} }
@ -192,7 +196,8 @@ namespace NadekoBot.Classes.Music {
try { try {
p.CancelOutputRead(); p.CancelOutputRead();
p.Close(); p.Close();
} catch { } }
catch { }
Console.WriteLine("Buffering canceled, stream is completed."); Console.WriteLine("Buffering canceled, stream is completed.");
return; return;
} }
@ -221,15 +226,18 @@ namespace NadekoBot.Classes.Music {
try { try {
p.CancelOutputRead(); p.CancelOutputRead();
p.Close(); p.Close();
} catch { } }
catch { }
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length"); Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
return; return;
} else { }
else {
++attempt; ++attempt;
await Task.Delay(20); await Task.Delay(20);
} }
} else { }
else {
attempt = 0; attempt = 0;
await buffer.WriteAsync(buf, 0, read); await buffer.WriteAsync(buf, 0, read);
} }
@ -260,7 +268,8 @@ namespace NadekoBot.Classes.Music {
if (buffer.Length > 0) { if (buffer.Length > 0) {
Console.WriteLine("Prebuffering complete."); Console.WriteLine("Prebuffering complete.");
} else { }
else {
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey."); Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
} }
@ -283,11 +292,13 @@ namespace NadekoBot.Classes.Music {
if (attempt == 4) { if (attempt == 4) {
Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]"); Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]");
break; break;
} else { }
else {
++attempt; ++attempt;
await Task.Delay(15); await Task.Delay(15);
} }
} else }
else
attempt = 0; attempt = 0;
if (State == StreamState.Completed) { if (State == StreamState.Completed) {

View File

@ -52,7 +52,10 @@ namespace NadekoBot.Commands {
if (controls.ByePM) { if (controls.ByePM) {
Greeted++; Greeted++;
await e.User.SendMessage($"`Farewell Message From {e.Server.Name}`\n" + msg); try {
await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg);
}
catch { }
} else { } else {
if (channel == null) return; if (channel == null) return;
Greeted++; Greeted++;

View File

@ -207,6 +207,23 @@ namespace NadekoBot.Modules {
mc.VoiceClient = await mc.VoiceChannel.JoinAudio(); mc.VoiceClient = await mc.VoiceChannel.JoinAudio();
}); });
cgb.CreateCommand("rm")
.Description("Removes a song by a # from the queue")
.Parameter("num",ParameterType.Required)
.Do(async e => {
var arg = e.GetArg("num");
int num;
MusicControls mc;
if (!musicPlayers.TryGetValue(e.Server, out mc) || !int.TryParse(arg, out num)) {
return;
}
if (num <= 0 || num > mc.SongQueue.Count)
return;
mc.SongQueue.RemoveAt(num - 1);
await e.Send($"🎵Song at position `{num}` has been removed.");
});
cgb.CreateCommand("debug") cgb.CreateCommand("debug")
.Description("Writes some music data to console. **BOT OWNER ONLY**") .Description("Writes some music data to console. **BOT OWNER ONLY**")
.Do(e => { .Do(e => {
@ -229,7 +246,7 @@ namespace NadekoBot.Modules {
await e.Send("Failed to create a music player for this server."); await e.Send("Failed to create a music player for this server.");
return; return;
} }
if (query == null || query.Length < 4) if (query == null || query.Length < 3)
return; return;
var player = musicPlayers[e.Server]; var player = musicPlayers[e.Server];