Class: Lita::Adapters::HipChat::Callback
- Inherits:
-
Object
- Object
- Lita::Adapters::HipChat::Callback
- Defined in:
- lib/lita/adapters/hipchat/callback.rb
Instance Attribute Summary collapse
-
#robot ⇒ Object
readonly
Returns the value of attribute robot.
-
#roster ⇒ Object
readonly
Returns the value of attribute roster.
Instance Method Summary collapse
-
#initialize(robot, roster) ⇒ Callback
constructor
A new instance of Callback.
- #muc_message(muc) ⇒ Object
- #private_message(client) ⇒ Object
- #roster_update ⇒ Object
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
#robot ⇒ Object (readonly)
Returns the value of attribute robot.
5 6 7 |
# File 'lib/lita/adapters/hipchat/callback.rb', line 5 def robot @robot end |
#roster ⇒ Object (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) muc. do |time, nick, text| user = user_by_name(nick) next unless user source = Source.new(user: user, room: muc.jid..to_s) = Message.new(robot, text, source) Lita.logger.debug( "Dispatching message to Lita from #{user.id} in MUC #{muc.jid}." ) robot.receive() 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 (client) client. do |m| next if m.type == :error || m.body.nil? user = user_by_jid(m.from) source = Source.new(user: user) = Message.new(robot, m.body, source) .command! Lita.logger.debug("Dispatching PM to Lita from #{user.id}.") robot.receive() end end |
#roster_update ⇒ Object
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 |