lib/lita/adapters/campfire/callback.rb in lita-campfire-0.1.4 vs lib/lita/adapters/campfire/callback.rb in lita-campfire-0.2.0
- old
+ new
@@ -1,24 +1,27 @@
module Lita
module Adapters
class Campfire < Adapter
class Callback
- attr_reader :robot, :room
+ attr_reader :robot, :room, :robot_id
- def initialize(robot, room)
- @robot = robot
- @room = room
+ def initialize(options)
+ @robot = options.fetch(:robot)
+ @room = options.fetch(:room)
+ @robot_id = options.fetch(:robot_id)
@receivers = [MessageReceiver, EnterReceiver].map do |receiver_type|
receiver_type.new(self)
end
end
def listen(options={})
- @room.listen(options) do |event|
- receive event
+ Thread.new do
+ @room.listen(options) do |event|
+ receive event
+ end
end
end
def register_users
@room.users.each do |user|
@@ -52,21 +55,28 @@
def initialize(callback)
@callback = callback
@robot = callback.robot
@room = callback.room
+ @robot_id = callback.robot_id
end
def receive(event)
_receive(event) if receives?(event)
end
private
+ attr_reader :robot_id
+
def receives?(event)
- self.class.message_types.include?(event.type)
+ self.class.message_types.include?(event.type) && !robot?(event.user)
end
+
+ def robot?(user)
+ robot_id == user.id
+ end
end
class MessageReceiver < EventReceiver
receives 'TextMessage', 'PasteMessage'
@@ -88,10 +98,9 @@
def _receive(event)
@callback.create_user(event.user)
end
end
-
end
end
end
end
\ No newline at end of file