Class: Lita::Handlers::MessageRouter

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/message_router.rb

Instance Method Summary collapse

Instance Method Details

#match(message) ⇒ Object



28
29
30
31
32
# File 'lib/lita/handlers/message_router.rb', line 28

def match(message)
  regex = Regexp.new('^(' + config.robot_mention_names.join('|') + ') (.+)')
  matches = message.match(regex)
  matches[2] if matches
end

#maybe_route(chat) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lita/handlers/message_router.rb', line 8

def maybe_route(chat)
  return if chat.command?

  message = chat.matches[0].strip
  match = match(message)

  if match
    command = robot.mention_name + ' ' + match

    source = if chat.room
      Lita::Source.new(room: chat.room)
    else
      Lita::Source.new(user: chat.user)
    end

    real_message = Lita::Message.new(robot, command, source)
    robot.receive(real_message)
  end
end