From 31b2558523c894752f182ad6df8d521497d0e06a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 31 Jul 2016 17:01:56 +0200 Subject: [PATCH] fix #470 , !!ap now takes a random video out of 4 related ones --- NadekoBot/Classes/SearchHelper.cs | 12 +++--------- NadekoBot/Modules/Help/Commands/HelpCommand.cs | 4 ++-- NadekoBot/Modules/Music/MusicModule.cs | 14 ++++++++------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index 1db124e0..a0a59e9b 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -175,7 +175,7 @@ namespace NadekoBot.Classes return null; } - public static async Task GetRelatedVideoId(string id) + public static async Task> GetRelatedVideoIds(string id, int count = 1) { if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); @@ -186,20 +186,14 @@ namespace NadekoBot.Classes } var response = await GetResponseStringAsync( $"https://www.googleapis.com/youtube/v3/search?" + - $"part=snippet&maxResults=1&type=video" + + $"part=snippet&maxResults={count}&type=video" + $"&relatedToVideoId={id}" + $"&key={NadekoBot.Creds.GoogleAPIKey}").ConfigureAwait(false); JObject obj = JObject.Parse(response); var data = JsonConvert.DeserializeObject(response); - if (data.items.Length > 0) - { - var toReturn = "http://www.youtube.com/watch?v=" + data.items[0].id.videoId.ToString(); - return toReturn; - } - else - return null; + return data.items.Select(v => "http://www.youtube.com/watch?v=" + v.id.videoId); } public static async Task GetPlaylistIdByKeyword(string query) diff --git a/NadekoBot/Modules/Help/Commands/HelpCommand.cs b/NadekoBot/Modules/Help/Commands/HelpCommand.cs index 6d6826a0..1ed5f73c 100644 --- a/NadekoBot/Modules/Help/Commands/HelpCommand.cs +++ b/NadekoBot/Modules/Help/Commands/HelpCommand.cs @@ -48,8 +48,8 @@ namespace NadekoBot.Classes.Help.Commands public Action DoGitFunc() => e => { string helpstr = -$@"######For more information and how to setup your own NadekoBot, go to: **http://github.com/Kwoth/NadekoBot/** -######You can donate on patreon: `https://patreon.com/nadekobot` +$@"######For more information and how to setup your own NadekoBot, go to: +######You can donate on patreon: ######or paypal: `nadekodiscordbot@gmail.com` #NadekoBot List Of Commands diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index 77630fd7..d3becde1 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -771,20 +771,22 @@ namespace NadekoBot.Modules.Music var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1); if (selSong == null) { - await e.Channel.SendMessage("Could not select song, likely wrong index"); - - } else + await e.Channel.SendMessage("Could not select song, likely wrong index"); + + } + else { await e.Channel.SendMessage($"🎶`Selected song {selSong.SongInfo.Title}:` <{selSong.SongInfo.Query}>").ConfigureAwait(false); } - } else + } + else { var curSong = musicPlayer.CurrentSong; if (curSong == null) return; await e.Channel.SendMessage($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false); } - + }); cgb.CreateCommand(Prefix + "autoplay") @@ -837,7 +839,7 @@ namespace NadekoBot.Modules.Music lastFinishedMessage = await textCh.SendMessage($"🎵`Finished`{song.PrettyName}").ConfigureAwait(false); if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.Provider == "YouTube") { - await QueueSong(queuer, textCh, voiceCh, await SearchHelper.GetRelatedVideoId(song.SongInfo.Query), silent, musicType).ConfigureAwait(false); + await QueueSong(queuer, textCh, voiceCh, (await SearchHelper.GetRelatedVideoIds(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false); } } catch (Exception e)