예제 #1
0
        public async Task <IActionResult> GetDadJoke([Required, FromQuery] string JokeID)
        {
            if (string.IsNullOrEmpty(JokeID))
            {
                return(BadRequest("Joke ID cannot be null or empty."));
            }

            var dadJoke = await _dadJokeService.GetDadJoke(JokeID);

            if (dadJoke == null)
            {
                return(NotFound(new { Id = JokeID }));
            }

            if (dadJoke.Status < 200 || dadJoke.Status >= 300)
            {
                return(BadRequest());
            }

            return(Ok(dadJoke));
        }
예제 #2
0
        public void Handle(OnChatCommandReceivedArgs cmd)
        {
            try
            {
                var dadJoke = dadJokeService.GetDadJoke(alternateSite).Result;

                sayingResponse.SaySomethingNice(dadJoke.Setup);
                client.SendMessage(cmd.Command.ChatMessage.Channel, $"Q: {dadJoke.Setup}");

                Task.Delay(5000).Wait();

                sayingResponse.SaySomethingNice(dadJoke.Punchline);
                client.SendMessage(cmd.Command.ChatMessage.Channel, $"A: {dadJoke.Punchline}");
            }
            catch (Exception ex)
            {
                alternateSite = "https://karljoke.herokuapp.com/jokes/random";

                sayingResponse.SaySomethingNice(ex.Message);
                client.SendMessage(cmd.Command.ChatMessage.Channel, $"We've got problem {ex.Message}");
            }
        }