diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index 2eb12d71..97494239 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -69,7 +69,7 @@ namespace NadekoBot.Classes.Music { if (VoiceClient == null) { Console.WriteLine($"Joining voice channel [{DateTime.Now.Second}]"); //todo add a new event, to tell people nadeko is trying to join - VoiceClient = await VoiceChannel.JoinAudio(); + VoiceClient = await Task.Run(async () => await VoiceChannel.JoinAudio()); Console.WriteLine($"Joined voicechannel [{DateTime.Now.Second}]"); } await Task.Factory.StartNew(async () => await CurrentSong?.Start(), TaskCreationOptions.LongRunning).Unwrap(); diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 786e0d56..4f4644eb 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -74,6 +74,8 @@ namespace NadekoBot.Classes.Music { if (OnResolving != null) OnResolving(); var links = await SearchHelper.FindYoutubeUrlByKeywords(Query); + if (links == String.Empty) + throw new OperationCanceledException("Not a valid youtube query."); var allVideos = await Task.Factory.StartNew(async () => await YouTube.Default.GetAllVideosAsync(links)).Unwrap(); var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); var video = videos diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index eedf2b8b..743297fe 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -21,13 +21,13 @@ namespace NadekoBot.Classes { } } - public static async Task GetResponseAsync(string v) => - await new StreamReader((await ((HttpWebRequest)WebRequest.Create(v)).GetResponseAsync()).GetResponseStream()).ReadToEndAsync(); - - public static async Task GetResponseAsync(string v, WebHeaderCollection headers) { + public static async Task GetResponseAsync(string v, WebHeaderCollection headers = null) { var wr = (HttpWebRequest)WebRequest.Create(v); - wr.Headers = headers; - return await new StreamReader((await wr.GetResponseAsync()).GetResponseStream()).ReadToEndAsync(); + if (headers != null) + wr.Headers = headers; + using (var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream())) { + return await sr.ReadToEndAsync(); + } } private static string token = ""; @@ -112,10 +112,11 @@ namespace NadekoBot.Classes { WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey); - var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream()); + using (var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream())) { - dynamic obj = JObject.Parse(await sr.ReadToEndAsync()); - return "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString(); + dynamic obj = JObject.Parse(await sr.ReadToEndAsync()); + return "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString(); + } } catch (Exception ex) { Console.WriteLine($"Error in findyoutubeurl: {ex.Message}"); @@ -150,7 +151,7 @@ namespace NadekoBot.Classes { } try { - WebRequest wr = WebRequest.Create($"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults={25}&playlistId={v}&key={ NadekoBot.creds.GoogleAPIKey }"); + WebRequest wr = WebRequest.Create($"https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&maxResults={30}&playlistId={v}&key={ NadekoBot.creds.GoogleAPIKey }"); var sr = new StreamReader((await wr.GetResponseAsync()).GetResponseStream()); diff --git a/NadekoBot/Classes/Trivia/TriviaGame.cs b/NadekoBot/Classes/Trivia/TriviaGame.cs index 0dc308a3..6f9b1ae0 100644 --- a/NadekoBot/Classes/Trivia/TriviaGame.cs +++ b/NadekoBot/Classes/Trivia/TriviaGame.cs @@ -77,12 +77,12 @@ namespace NadekoBot.Classes.Trivia { // load next question if game is still running await Task.Delay(2000); } - End(); + End().Wait(); } - private void End() { - _channel.SendMessage("**Trivia game ended**"); - _channel.SendMessage(GetLeaderboard()); + private async Task End() { + await _channel.SendMessage("**Trivia game ended**"); + await _channel.SendMessage(GetLeaderboard()); TriviaGame throwAwayValue; Commands.Trivia.runningTrivias.TryRemove(_server, out throwAwayValue); } diff --git a/NadekoBot/Commands/ClashOfClans.cs b/NadekoBot/Commands/ClashOfClans.cs index 1b5b85ec..2a7620e8 100644 --- a/NadekoBot/Commands/ClashOfClans.cs +++ b/NadekoBot/Commands/ClashOfClans.cs @@ -337,7 +337,7 @@ namespace NadekoBot.Commands { bases[i].TimeAdded = DateTime.Now; } Task.Run(async () => await ClearArray()); - await Task.Delay(new TimeSpan(23, 0, 0), endTokenSource.Token); + await Task.Delay(new TimeSpan(24, 0, 0), endTokenSource.Token); } catch (Exception) { } finally { diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 5062d328..3d676bca 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -79,7 +79,7 @@ namespace NadekoBot.Modules { } var player = musicPlayers[e.Server]; string toSend = "🎡 **" + player.SongQueue.Count + "** `videos currently queued.` "; - if (player.SongQueue.Count >= 25) + if (player.SongQueue.Count >= 50) toSend += "**Song queue is full!**\n"; await e.Channel.SendMessage(toSend); int number = 1; @@ -190,12 +190,12 @@ namespace NadekoBot.Modules { .Parameter("playlist", ParameterType.Unparsed) .Do(async e => { if (e.User.VoiceChannel?.Server != e.Server) { - await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server."); + await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server.\n If you already are in a voice channel, try rejoining it."); return; } var ids = await SearchHelper.GetVideoIDs(await SearchHelper.GetPlaylistIdByKeyword(e.GetArg("playlist"))); //todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE - var msg = await e.Channel.SendMessage($"🎡 `Attempting to queue **{ids.Count}** songs".SnPl(ids.Count)+"...`"); + var msg = await e.Channel.SendMessage($"🎡 `Attempting to queue {ids.Count} songs".SnPl(ids.Count)+"...`"); foreach (var id in ids) { Task.Run(async () => await QueueSong(e, id, true)).ConfigureAwait(false); await Task.Delay(150); @@ -208,7 +208,7 @@ namespace NadekoBot.Modules { .Parameter("radio_link", ParameterType.Required) .Do(async e => { if (e.User.VoiceChannel?.Server != e.Server) { - await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server."); + await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server.\n If you already are in a voice channel, try rejoining it."); return; } await QueueSong(e, e.GetArg("radio_link"), radio: true); @@ -235,7 +235,7 @@ namespace NadekoBot.Modules { } if (arg?.ToLower() == "all") { mc.SongQueue?.Clear(); - await e.Channel.SendMessage($"🎡Queue cleared!"); + await e.Channel.SendMessage($"🎡`Queue cleared!`"); return; } int num; @@ -246,7 +246,7 @@ namespace NadekoBot.Modules { return; mc.SongQueue.RemoveAt(num - 1); - await e.Channel.SendMessage($"🎡Song at position `{num}` has been removed."); + await e.Channel.SendMessage($"🎡**Track at position `#{num}` has been removed.**"); }); cgb.CreateCommand("debug") @@ -263,7 +263,7 @@ namespace NadekoBot.Modules { private async Task QueueSong(CommandEventArgs e, string query, bool silent = false, bool radio = false) { if (e.User.VoiceChannel?.Server != e.Server) { - await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server."); + await e.Channel.SendMessage("πŸ’’ You need to be in the voice channel on this server.\n If you are already in a voice channel, try rejoining."); return; } @@ -291,7 +291,7 @@ namespace NadekoBot.Modules { var player = musicPlayers[e.Server]; - if (player.SongQueue.Count >= 25) return; + if (player.SongQueue.Count >= 50) return; try { var sr = new StreamRequest(e, query, player, radio); diff --git a/NadekoBot/bin/Debug/Discord.Net.Audio.dll b/NadekoBot/bin/Debug/Discord.Net.Audio.dll index 5d8dd66d..3f06d12b 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Audio.dll and b/NadekoBot/bin/Debug/Discord.Net.Audio.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Commands.dll b/NadekoBot/bin/Debug/Discord.Net.Commands.dll index ca82db65..07ee7515 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Commands.dll and b/NadekoBot/bin/Debug/Discord.Net.Commands.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Modules.dll b/NadekoBot/bin/Debug/Discord.Net.Modules.dll index 4db24388..336315e7 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Modules.dll and b/NadekoBot/bin/Debug/Discord.Net.Modules.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.dll b/NadekoBot/bin/Debug/Discord.Net.dll index c70def20..861feb56 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.dll and b/NadekoBot/bin/Debug/Discord.Net.dll differ