public static async void GetData(string category, string type)
        {
            HttpClient          httpClient = new HttpClient();
            string              url        = $"https://sv443.net/jokeapi/v2/joke/{category}?blacklistFlags=nsfw,religious,political,racist,sexist{type}";
            HttpRequestMessage  request    = new HttpRequestMessage(HttpMethod.Get, url);
            HttpResponseMessage response   = await httpClient.SendAsync(request);

            string dados = await response.Content.ReadAsStringAsync();

            Piada piada = JsonConvert.DeserializeObject <Piada>(dados);

            Console.WriteLine($"Categoria: {piada.category}\n");
            Console.WriteLine($"Tipo: {piada.type}\n");
            if (piada.type == "twopart")
            {
                Console.WriteLine($"Pergunta: {piada.setup}\n" +
                                  $"Resposta: {piada.delivery}\n"
                                  );
            }
            else
            {
                Console.WriteLine($"Piada: {piada.joke}\n");
            }
            Console.WriteLine($"Id: {piada.id}\n");
        }
Exemple #2
0
        void FazerPiada(Tuple <string, string, string> comando)
        {
            CallbackTerminadoDelegate callbackTerminadoDelegate = new CallbackTerminadoDelegate(TerminadoCallback);
            CallbackErroDelegate      callbackErroDelegate      = new CallbackErroDelegate(ErroCallback);

            Piada.Falar(new FalaModel
            {
                Jogador = comando.Item3
            }, notificarBotCallback: callbackTerminadoDelegate, notificarErroBotCallback: callbackErroDelegate);
        }
Exemple #3
0
        public List <Piada> GetPiada(string titulo, string categoria, string classificacao)
        {
            var lista = new Piada().GetAllPiadas();

            if (!string.IsNullOrEmpty(titulo))
            {
                lista = lista.Where(x => x._titulo.Contains(titulo)).ToList();
            }

            if (!string.IsNullOrEmpty(categoria))
            {
                lista = lista.Where(x => x._categoria == categoria).ToList();
            }

            if (!string.IsNullOrEmpty(classificacao))
            {
                lista = lista.Where(x => x._classificacao == classificacao).ToList();
            }

            return(lista);
        }
Exemple #4
0
        public Piada GetPiadaAleatoria()
        {
            var lista = new Piada().GetAllPiadas();

            return(lista.OrderBy(x => Guid.NewGuid()).FirstOrDefault());
        }