Sha256: d555de6f6532d710a72b4534af82466184dd60848f216d5783c8246ff1d77f7d

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Waylon
  module Skills
    # Lets Waylon tell some jokes
    class Jokes < Waylon::Skill
      route(
        /^(tell me a )?joke$/i,
        :tell_a_joke,
        help: {
          usage: "[tell me a] joke",
          description: 'Tells a "dad" joke'
        }
      )

      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
waylon-jokes-0.2.0 lib/waylon/skills/jokes.rb