Class: Waylon::Skills::Jokes

Inherits:
Waylon::Skill
  • Object
show all
Defined in:
lib/waylon/skills/jokes.rb

Overview

Lets Waylon tell some jokes

Instance Method Summary collapse

Instance Method Details

#fallbackObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/waylon/skills/jokes.rb', line 27

def fallback
  [
    "I was addicted to the hokey pokey…but I turned myself around.",
    "What invention allows us to see through walls? Windows.",
    "The past, the present, and the future walked into a bar. It was tense.",
    "What's the least-spoken language in the world? Sign language.",
    "Why do cows wear bells? Because their horns don't work.",
    "Police arrested a bottle of water because it was wanted in three different states: solid, liquid, and gas."
  ].sample
end

#tell_a_jokeObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/waylon/skills/jokes.rb', line 16

def tell_a_joke
  conn = Faraday.new(headers: { accept: "application/json" }) do |f|
    f.response :json
  end
  response = conn.get("https://icanhazdadjoke.com/")

  reply(response.body["joke"])
rescue Faraday::Error
  reply(fallback)
end