Class: Botfly::MUCResponder

Inherits:
Responder show all
Extended by:
Forwardable
Defined in:
lib/botfly/responder/muc_responder.rb

Constant Summary collapse

@@id =
1

Instance Attribute Summary

Attributes inherited from Responder

#bot, #callback, #callback_type, #id

Instance Method Summary collapse

Methods included from CommonResponderMethods

#tell

Constructor Details

#initialize(muc, &block) ⇒ MUCResponder

Returns a new instance of MUCResponder.



11
12
13
14
15
16
17
18
19
# File 'lib/botfly/responder/muc_responder.rb', line 11

def initialize(muc,&block)
  Botfly.logger.info("RSP: #{self.class.to_s}#new")
  @matcher_chain = []
  @muc = muc
  @bot = @muc.bot

  @callback = block if block_given?
  @id = @@id += 1
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/botfly/responder/muc_responder.rb', line 21

def method_missing(method,*args,&block)
  condition = args.first
  Botfly.logger.info("RSP: Responder##{method}(#{condition.inspect})")

  add_matcher(method,condition)

  if block_given?
    Botfly.logger.info("RSP: Callback recorded: #{block.inspect}")
    @callback = block
    return @id
  end

  return self
end

Instance Method Details

#callback_with(params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/botfly/responder/muc_responder.rb', line 36

def callback_with(params)
  Botfly.logger.debug("RSP: Launching callback with params: #{params.inspect}")

  setup_instance_variables(params)
  if @matcher_chain.all? {|matcher| matcher.match(params) }
    Botfly.logger.debug("RSP: All matchers passed")
    cb = @callback # Ruby makes it difficult to apply & to an instance variable
    instance_eval &cb
  end
end

#leaveObject

room



47
48
49
# File 'lib/botfly/responder/muc_responder.rb', line 47

def leave #room
  raise "NotImplementedError: Sorry, coming soon!"
end

#remove(responder_id) ⇒ Object



55
56
57
# File 'lib/botfly/responder/muc_responder.rb', line 55

def remove(responder_id)
  @muc.remove_responder(responder_id)
end

#say(msg) ⇒ Object



51
52
53
# File 'lib/botfly/responder/muc_responder.rb', line 51

def say(msg)
  @muc.muc.say(msg)
end