Class: Botfly::MUCClient

Inherits:
CommonBlockAcceptor show all
Defined in:
lib/botfly/muc_client.rb

Instance Attribute Summary collapse

Attributes inherited from CommonBlockAcceptor

#block_state, #responders

Instance Method Summary collapse

Methods inherited from CommonBlockAcceptor

#[], #[]=, #on, #remove_responder

Constructor Details

#initialize(room, bot, &block) ⇒ MUCClient

Returns a new instance of MUCClient.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/botfly/muc_client.rb', line 9

def initialize(room, bot, &block)
  super
  Botfly.logger.info("MUC: New client created")
  @bot = bot
  @client = @bot.client
  @room = room
  @domain = "conference.#{@bot.jid.domain}"  # A sensible default for now
  @resource = @bot.jid.node
  
  execute(&block) if block_given? # i.e. join(room) do ... end
  return self
end

Instance Attribute Details

#botObject (readonly)

Returns the value of attribute bot.



5
6
7
# File 'lib/botfly/muc_client.rb', line 5

def bot
  @bot
end

#domainObject (readonly)

Returns the value of attribute domain.



5
6
7
# File 'lib/botfly/muc_client.rb', line 5

def domain
  @domain
end

#mucObject (readonly)

Returns the value of attribute muc.



5
6
7
# File 'lib/botfly/muc_client.rb', line 5

def muc
  @muc
end

#resourceObject (readonly)

Returns the value of attribute resource.



5
6
7
# File 'lib/botfly/muc_client.rb', line 5

def resource
  @resource
end

Instance Method Details

#as(resource, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/botfly/muc_client.rb', line 22

def as(resource, &block)
  Botfly.logger.info("MUC: as #{resource}")
  @resource = resource
  execute(&block) if block_given?
  return self
end

#class_prefixObject



40
# File 'lib/botfly/muc_client.rb', line 40

def class_prefix; "MUC"; end

#leaveObject



29
# File 'lib/botfly/muc_client.rb', line 29

def leave; @muc.exit; end

#respond_to(callback_type, params = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/botfly/muc_client.rb', line 32

def respond_to(callback_type, params={})
  if (params[:nick] != @resource ) # don't respond to self
    Botfly.logger.info("MUC: Responding to callback of type: #{callback_type} with time of #{params[:time]}")
    @responders[callback_type].each {|r| r.callback_with params} if @responders[callback_type]
  end
end

#roomObject



7
# File 'lib/botfly/muc_client.rb', line 7

def room; @block_state; end

#to_debug_sObject



39
# File 'lib/botfly/muc_client.rb', line 39

def to_debug_s; "MUC"; end