Module: Twibot::Handlers

Included in:
Bot
Defined in:
lib/twibot/handlers.rb

Instance Method Summary collapse

Instance Method Details

#add_handler(type, handler) ⇒ Object

Add a handler for this bot



6
7
8
9
# File 'lib/twibot/handlers.rb', line 6

def add_handler(type, handler)
  handlers_for_type(type) << handler
  handler
end

#dispatch(type, message) ⇒ Object



19
20
21
# File 'lib/twibot/handlers.rb', line 19

def dispatch(type, message)
  handlers_for_type(type).each { |handler| handler.dispatch(message) }
end

#handlersObject



23
24
25
26
27
28
29
30
31
# File 'lib/twibot/handlers.rb', line 23

def handlers
  @handlers ||= {
    :message => [],
    :reply => [],
    :tweet => [],
    :follower => [],
    :search => {}
  }
end

#handlers=(hash) ⇒ Object



33
34
35
# File 'lib/twibot/handlers.rb', line 33

def handlers=(hash)
  @handlers = hash
end

#handlers_for_type(type) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/twibot/handlers.rb', line 11

def handlers_for_type(type)
  if type.is_a? Array
    handlers[type.first][type.last] ||= []
  else
    handlers[type] || {}
  end
end