Class: Botfly::Bot

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

Instance Attribute Summary collapse

Attributes inherited from CommonBlockAcceptor

#block_state, #responders

Instance Method Summary collapse

Methods inherited from CommonBlockAcceptor

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

Constructor Details

#initialize(jid, pass, opts = {}) ⇒ Bot

Returns a new instance of Bot.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/botfly/bot.rb', line 6

def initialize(jid,pass, opts = {})
  super
  Botfly.logger.info("  BOT: Bot#new")
  @password = pass
  @jid = Jabber::JID.new(jid)
  @client = Jabber::Client.new(@jid)
  @main_thread = Thread.current
  if opts[:gtalk]
    @host = "talk.google.com"
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#jidObject (readonly)

Returns the value of attribute jid.



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

def jid
  @jid
end

#rosterObject (readonly)

Returns the value of attribute roster.



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

def roster
  @roster
end

Instance Method Details

#connectObject



18
19
20
21
22
23
24
25
26
# File 'lib/botfly/bot.rb', line 18

def connect
  Botfly.logger.info("  BOT: Connecting to #{@host || @jid}...")
  @client.connect(@host)
  @client.auth(@password)
  @roster = Jabber::Roster::Helper.new(@client)
  Botfly.logger.info("  BOT: Connected")
  register_for_callbacks
  self
end

#join(room_name, &block) ⇒ Object



28
29
30
# File 'lib/botfly/bot.rb', line 28

def join(room_name,&block)
  return Botfly::MUCClient.new(room_name,self,&block)
end

#quitObject



32
33
34
35
# File 'lib/botfly/bot.rb', line 32

def quit
  @client.close
  @main_thread.wakeup
end

#to_debug_sObject



37
# File 'lib/botfly/bot.rb', line 37

def to_debug_s; "BOT"; end