diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 8d3c7c64..5bee59b7 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Classes.Music { public string Title { get; internal set; } = String.Empty; 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; public StreamState State => musicStreamer?.State ?? privateState; @@ -74,7 +74,8 @@ namespace NadekoBot.Classes.Music { Provider = "SoundCloud"; uri = svideo.StreamLink; Console.WriteLine(uri); - } else { + } + else { if (OnResolving != null) OnResolving(); @@ -89,11 +90,12 @@ namespace NadekoBot.Classes.Music { if (video == null) // do something with this error throw new Exception("Could not load any video elements based on the query."); - Title = video.Title.Substring(0,video.Title.Length-10); // removing trailing "- You Tube" + Title = video.Title.Substring(0, video.Title.Length - 10); // removing trailing "- You Tube" Provider = "YouTube"; uri = video.Uri; } - } catch (Exception ex) { + } + catch (Exception ex) { privateState = StreamState.Completed; if (OnResolvingFailed != null) OnResolvingFailed(ex.Message); @@ -134,10 +136,12 @@ namespace NadekoBot.Classes.Music { } } await musicStreamer.StartPlayback(); - } catch (TimeoutException) { + } + catch (TimeoutException) { Console.WriteLine("Resolving timed out."); privateState = StreamState.Completed; - } catch (Exception ex) { + } + catch (Exception ex) { Console.WriteLine("Error in start playback." + ex.Message); privateState = StreamState.Completed; } @@ -169,7 +173,7 @@ namespace NadekoBot.Classes.Music { $"Server: {parent.Server.Name}\n" + $"Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State}\n" + "--------------------------------\n"; - + private async Task BufferSong() { //start feeding the buffer var p = Process.Start(new ProcessStartInfo { @@ -192,7 +196,8 @@ namespace NadekoBot.Classes.Music { try { p.CancelOutputRead(); p.Close(); - } catch { } + } + catch { } Console.WriteLine("Buffering canceled, stream is completed."); return; } @@ -221,15 +226,18 @@ namespace NadekoBot.Classes.Music { try { p.CancelOutputRead(); 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; - } else { + } + else { ++attempt; await Task.Delay(20); } - } else { + } + else { attempt = 0; await buffer.WriteAsync(buf, 0, read); } @@ -254,16 +262,17 @@ namespace NadekoBot.Classes.Music { await Task.Delay(waitPerAttempt); } if (prebufferingComplete) { - Console.WriteLine($"Prebuffering finished in {bufferAttempts*500}"); + Console.WriteLine($"Prebuffering finished in {bufferAttempts * 500}"); } // prebuffering wait stuff end - + if (buffer.Length > 0) { Console.WriteLine("Prebuffering complete."); - } else { + } + else { Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey."); } - + int blockSize = 1920 * NadekoBot.client.Services.Get().Config.Channels; byte[] voiceBuffer = new byte[blockSize]; @@ -274,7 +283,7 @@ namespace NadekoBot.Classes.Music { while (!IsCanceled) { int readCount = 0; //adjust volume - + lock (_bufferLock) { readCount = buffer.Read(voiceBuffer, 0, voiceBuffer.Length); } @@ -283,11 +292,13 @@ namespace NadekoBot.Classes.Music { if (attempt == 4) { Console.WriteLine($"Failed to read {attempt} times. Breaking out. [{DateTime.Now.Second}]"); break; - } else { + } + else { ++attempt; await Task.Delay(15); } - } else + } + else attempt = 0; if (State == StreamState.Completed) { diff --git a/NadekoBot/Commands/ServerGreetCommand.cs b/NadekoBot/Commands/ServerGreetCommand.cs index dbe66545..d6bf6c3c 100644 --- a/NadekoBot/Commands/ServerGreetCommand.cs +++ b/NadekoBot/Commands/ServerGreetCommand.cs @@ -52,7 +52,10 @@ namespace NadekoBot.Commands { if (controls.ByePM) { 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 { if (channel == null) return; Greeted++; diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 1c6526a7..b318ee94 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -207,6 +207,23 @@ namespace NadekoBot.Modules { 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") .Description("Writes some music data to console. **BOT OWNER ONLY**") .Do(e => { @@ -229,7 +246,7 @@ namespace NadekoBot.Modules { await e.Send("Failed to create a music player for this server."); return; } - if (query == null || query.Length < 4) + if (query == null || query.Length < 3) return; var player = musicPlayers[e.Server];