Class: Lita::Adapters::HipChat::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/adapters/hipchat/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot, roster) ⇒ Callback

Returns a new instance of Callback.



7
8
9
10
# File 'lib/lita/adapters/hipchat/callback.rb', line 7

def initialize(robot, roster)
  @robot = robot
  @roster = roster
end

Instance Attribute Details

#robotObject (readonly)

Returns the value of attribute robot.



5
6
7
# File 'lib/lita/adapters/hipchat/callback.rb', line 5

def robot
  @robot
end

#rosterObject (readonly)

Returns the value of attribute roster.



5
6
7
# File 'lib/lita/adapters/hipchat/callback.rb', line 5

def roster
  @roster
end

Instance Method Details

#muc_message(muc) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lita/adapters/hipchat/callback.rb', line 24

def muc_message(muc)
  muc.on_message do |time, nick, text|
    user = user_by_name(nick)
    next unless user
    source = Source.new(user: user, room: muc.jid.bare.to_s)
    message = Message.new(robot, text, source)
    Lita.logger.debug(
      "Dispatching message to Lita from #{user.id} in MUC #{muc.jid}."
    )
    robot.receive(message)
  end
end

#private_message(client) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lita/adapters/hipchat/callback.rb', line 12

def private_message(client)
  client.add_message_callback do |m|
    next if m.type == :error || m.body.nil?
    user = user_by_jid(m.from)
    source = Source.new(user: user)
    message = Message.new(robot, m.body, source)
    message.command!
    Lita.logger.debug("Dispatching PM to Lita from #{user.id}.")
    robot.receive(message)
  end
end

#roster_updateObject



37
38
39
40
41
42
43
44
# File 'lib/lita/adapters/hipchat/callback.rb', line 37

def roster_update
  roster.add_update_callback do |old_item, item|
    next unless item
    jid = item.attributes["jid"]
    Lita.logger.debug("Updating record for user with ID: #{jid}.")
    create_user(item.attributes)
  end
end