Class: HappyFunTimeBot

Inherits:
Object
  • Object
show all
Defined in:
lib/happy_fun_time_bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ HappyFunTimeBot

Returns a new instance of HappyFunTimeBot.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/happy_fun_time_bot.rb', line 17

def initialize(config = {})
  config = {:command_regex => /^!(.+)$/}.merge(config)
  self.client = Jabber::Client.new(config[:jid])
  self.muc    = Jabber::MUC::SimpleMUCClient.new(client)
  self.command_regexp = /^!(.+)$/
  self.responders = []
  self.config = config

  Jabber.debug = true if Jabber.logger = config[:debug]
  self
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



15
16
17
# File 'lib/happy_fun_time_bot.rb', line 15

def client
  @client
end

#command_regexpObject

Returns the value of attribute command_regexp.



15
16
17
# File 'lib/happy_fun_time_bot.rb', line 15

def command_regexp
  @command_regexp
end

#configObject

Returns the value of attribute config.



15
16
17
# File 'lib/happy_fun_time_bot.rb', line 15

def config
  @config
end

#mucObject

Returns the value of attribute muc.



15
16
17
# File 'lib/happy_fun_time_bot.rb', line 15

def muc
  @muc
end

#respondersObject

Returns the value of attribute responders.



15
16
17
# File 'lib/happy_fun_time_bot.rb', line 15

def responders
  @responders
end

Instance Method Details

#add_responder(command = '', &block) ⇒ Object



42
43
44
# File 'lib/happy_fun_time_bot.rb', line 42

def add_responder(command  = '', &block)
  responders << Responder.new(command, &block)
end

#connectObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/happy_fun_time_bot.rb', line 29

def connect
  client.connect
  client.auth(self.config[:password])
  client.send(Jabber::Presence.new.set_type(:available))

  salutation = config[:nick].split(/\s+/).first

  muc.on_message { |time, nick, text| process(nick, text) }

  muc.join(self.config[:room] + '/' + self.config[:nick])
  self
end

#run!Object



46
47
48
49
# File 'lib/happy_fun_time_bot.rb', line 46

def run!
  connect
  loop { sleep 1 }
end