Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 42 lines (35 sloc) 0.722 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
require 'dialogue_extension'
require 'quote_of_the_day'

class QuoteDialogue < DialogueExtension
  
  initial_state :quote
  hook_words 'quote of the day', 'quote'
  state :quote, {
    ['random','next','last','repeat'] => :quote
  }
  
  def initialize
    @quoter = QuoteOfTheDay.new
    # reset
  end
  
  def find_quotes
    @last_search = Time.now
    puts 'finding quotes'
    @quoter.find
    @quoter.random
  end
  
  def exit_quote(phrase)
    case phrase
    when 'random'
      @quoter.random
    when 'next'
      @quoter.next
    when 'last'
      @quoter.last
    end
  end
  
  def enter_quote
    if @last_search.nil? or Time.now - @last_search > 600
      find_quotes
    end
    @quoter.read
  end
  
end
Something went wrong with that request. Please try again.