コード例 #1
0
        public async Task AddSongQueue([Remainder] string query)
        {
            QueueInfo curQueue = new QueueInfo();

            if (guildQueue.ContainsKey(Context.Guild.Id))
            {
                guildQueue.TryGetValue(Context.Guild.Id, out curQueue);
            }

            if (query.ToLower().Contains("youtube.com"))
            {
                Video grab = await borkTube.GetVideoAsync(YoutubeClient.ParseVideoId(query));

                curQueue.Songs.Add(new Song()
                {
                    SongTitle        = grab.Title,
                    SongId           = grab.Id,
                    SongURL          = grab.GetUrl(),
                    SongDuration     = grab.Duration,
                    DiscordRequester = Context.Message.Author
                });

                guildQueue.Remove(Context.Guild.Id);
                guildQueue.Add(Context.Guild.Id, curQueue);

                await ReplyAsync($"Awesome, I added `{grab.Title}` to your queue");
            }
            else
            {
                IEnumerable <VideoInformation> searchResults = new VideoSearch().SearchQuery(query, 1).Take(10);

                var borkMsg = await Context.Channel.SendMessageAsync($"***- Please respond with the song number you want -***\n\n{OrganizeList(searchResults)}");

                var uRes = await borkInteract.WaitForMessage(Context.Message.Author, borkMsg.Channel, TimeSpan.FromSeconds(60));

                if (int.TryParse(uRes.Content, out int result))
                {
                    if (result >= 10)
                    {
                        await DoMessages(borkMsg.Channel, borkMsg, "**The song number you gave was not listed, please try again.**");
                    }
                    else
                    {
                        Video chosen = await borkTube.GetVideoAsync(YoutubeClient.ParseVideoId(searchResults.ElementAt(result).Url));

                        curQueue.Songs.Add(new Song()
                        {
                            SongTitle        = chosen.Title,
                            SongId           = chosen.Id,
                            SongURL          = chosen.GetUrl(),
                            SongDuration     = chosen.Duration,
                            DiscordRequester = uRes.Author
                        });

                        guildQueue.Remove(Context.Guild.Id);
                        guildQueue.Add(Context.Guild.Id, curQueue);

                        await DoMessages(borkMsg.Channel, borkMsg, $"Awesome, I added `{chosen.Title}` to your queue");
                    }
                }
                else
                {
                    await DoMessages(borkMsg.Channel, borkMsg, "**The response you gave was not valid, please try again.**");
                }
            }
        }