Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool        canLoading = false;
            WaitingUser user       = Session["user"];

            if (user != null)
            {
            }
        }
Esempio n. 2
0
        public async Task SendAudioAsync(IGuild guildObj, IMessageChannel channel, IUser user, string path)
        {
            var g = Program.GetGuild(guildObj);

            if (g.MessageChannel == null)
            {
                g.MessageChannel = channel;
            }
            var guild = Program.GetGuild(guildObj.Id);

            var  youtube  = new YoutubeClient();
            bool playlist = false;
            var  id       = string.Empty;

            try
            {
                if (path.Contains("playlist?list") || path.Contains("&list"))
                {
                    //Console.WriteLine("playlist gotten");
                    id       = YoutubeClient.ParsePlaylistId(path);
                    playlist = true;
                }
                else
                {
                    id = YoutubeClient.ParseVideoId(path);
                }
            }
            catch (Exception e)
            {
                // invalid id
                // find videos
                var items  = new VideoSearch();
                var videos = new List <SearchVideoItem>();
                var sb     = new StringBuilder();
                var index  = 0;
                foreach (var item in items.SearchQuery(path, 1))
                {
                    if (index > 5)
                    {
                        break;
                    }
                    var itemId = YoutubeClient.ParseVideoId(item.Url);
                    videos.Add(new SearchVideoItem(
                                   item.Url,
                                   itemId,
                                   item.Title,
                                   item.Duration));
                    sb.AppendLine($"{Program.Emojis[(index+1).ToString()].Name} {item.Title} ({item.Duration})");
                    index++;
                }

                var embed = Embeds.GetRetrievedSongs(sb.ToString(), guild.Prefix);
                var msg   = await g.MessageChannel.SendMessageAsync(string.Empty, embed : embed);

                WaitingUser u = new WaitingUser(user.Id, guild.Id, msg.Id, WaitingUser.TypeOfWait.SearchingSong, videos.ToArray());
                guild.WaitingUsers.Add(u);
                return;
            }

            if (playlist)
            {
                await ParsePlaylist(guild, channel, user, path, youtube, id);
            }
            else
            {
                await ParseVideo(guild, channel, user, path, youtube, id);
            }
            ;
        }