Exemplo n.º 1
0
        public static async Task <string> Ask(string question, List <string> tags, int maxResults = 3)
        {
            var bestAnswers = await GetBestAnswersFor(question, tags, maxResults);

            if (bestAnswers.IsEmpty())
            {
                throw new Error("No answers found for " + question);
            }
            var answerStrings = bestAnswers.Map(a => {
                var answerHtmlAsText = RestRequestHelper.HtmlToPlainText(a.Value.body);
                var questi           = $"?? Question ({a.Key.score} votes):  {WebUtility.HtmlDecode(a.Key.title)}";
                var answer           = $">> Answer {a.Value.answer_url} ({a.Value.score} votes): \n{answerHtmlAsText}";
                return("\n" + questi + ":\n" + answer + "\n");
            });
            var searchSentence = question + " " + tags.ToStringV2("[", "]", "] [");
            var s = "https://stackoverflow.com/search?q=" + WebUtility.UrlEncode(searchSentence);

            return($"\n{question}\nSearching.. {s}\n{answerStrings.ToStringV2("", "", "")}");
        }