Esempio n. 1
0
        internal static async Task AnswerInlineQueryAsync(ExtendedUser user, string inlineQueryId, IReadOnlyList <YoutubeExplode.Models.Video> videos)
        {
            var results = new List <InlineQueryResultArticle>();

            for (int i = 0; i < Math.Min(50, videos.Count); i++)
            {
                var video = videos.ElementAt(i);

                var message = $"*{video.Author}*" + "\n\r" +
                              $"[{video.Title}](https://www.youtube.com/watch?v={video.Id})";

                var thumbnail = video.Thumbnails.LowResUrl;
                var url       = "https://www.youtube.com/watch?v=" + video.Id;
                InputTextMessageContent content = new InputTextMessageContent(message);
                content.ParseMode = ParseMode.Markdown;
                InlineQueryResultArticle result = new InlineQueryResultArticle(inlineQueryId + i * 123, video.Title, content);
                result.ThumbUrl = thumbnail;
                result.Url      = url;
                result.HideUrl  = true;

                result.ReplyMarkup = GetMarkup(user, video);
                result.Description = $@"👁️ {ShortenNumber(video.Statistics.ViewCount)} | {ShortenNumber(video.Statistics.LikeCount)} 👍 \ 👎 {ShortenNumber(video.Statistics.DislikeCount)}";

                results.Add(result);
            }

            await botClient.AnswerInlineQueryAsync(inlineQueryId, results, 100, true);

            //cacheTime  - The maximum amount of time the result of the inline query may be cached on the server
            //isPersonal - Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
            //offset     - Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
            //pmText     - clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switchPmParameter
        }
Esempio n. 2
0
        private static InlineKeyboardMarkup GetMarkup(ExtendedUser user, YoutubeExplode.Models.Video video)
        {
            var videoId = video.Id.Replace('~', '-');
            var title   = video.Title.Replace('~', '-');


            /*if (user.Credential != null)
             * {*/
            InlineKeyboardButton like = new InlineKeyboardButton();

            like.Text         = "👍"; //
            like.CallbackData = $"l~{videoId}~-1";

            InlineKeyboardButton dislike = new InlineKeyboardButton();

            dislike.Text         = "👎"; //
            dislike.CallbackData = $"d~{videoId}~-1";


            InlineKeyboardButton share = new InlineKeyboardButton();

            share.Text = "📤 Поделиться"; //
            share.SwitchInlineQuery = $"videoId: {video.Id}";


            InlineKeyboardButton search = new InlineKeyboardButton();

            search.Text = "🔎 Поиск"; //
            search.SwitchInlineQueryCurrentChat = $"{video.Author}: ";

            //
            InlineKeyboardButton downloadAudio = new InlineKeyboardButton();

            downloadAudio.Text         = "📥 Загрузить аудио";
            downloadAudio.CallbackData = $"d-A~{videoId}";

            InlineKeyboardButton[]   row1     = new InlineKeyboardButton[] { like, dislike };
            InlineKeyboardButton[]   row2     = new InlineKeyboardButton[] { downloadAudio };
            InlineKeyboardButton[]   row3     = new InlineKeyboardButton[] { share, search };
            InlineKeyboardButton[][] keyboard = new InlineKeyboardButton[][] { row1, row2, row3 };
            InlineKeyboardMarkup     markup   = new InlineKeyboardMarkup(keyboard);

            return(markup);

            /*}
             * else
             * {
             *  InlineKeyboardButton downloadAudio = new InlineKeyboardButton();
             *  downloadAudio.Text = "Загрузить аудио";
             *  downloadAudio.CallbackData = $"d-A~{videoId}";
             *
             *  InlineKeyboardButton[] row2 = new InlineKeyboardButton[] { downloadAudio };
             *  InlineKeyboardButton[][] keyboard = new InlineKeyboardButton[][] { row2 };
             *  InlineKeyboardMarkup markup = new InlineKeyboardMarkup(keyboard);
             *
             *  return markup;
             * }*/
        }