Class: HipchatBot

Inherits:
Object
  • Object
show all
Defined in:
lib/hipchat_bot.rb,
lib/hipchat_bot/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ HipchatBot

Returns a new instance of HipchatBot.



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

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.



14
15
16
# File 'lib/hipchat_bot.rb', line 14

def client
  @client
end

#command_regexpObject

Returns the value of attribute command_regexp.



14
15
16
# File 'lib/hipchat_bot.rb', line 14

def command_regexp
  @command_regexp
end

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/hipchat_bot.rb', line 14

def config
  @config
end

#mucObject

Returns the value of attribute muc.



14
15
16
# File 'lib/hipchat_bot.rb', line 14

def muc
  @muc
end

#respondersObject

Returns the value of attribute responders.



14
15
16
# File 'lib/hipchat_bot.rb', line 14

def responders
  @responders
end

Instance Method Details

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



41
42
43
# File 'lib/hipchat_bot.rb', line 41

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

#connectObject



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

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



45
46
47
48
# File 'lib/hipchat_bot.rb', line 45

def run!
  connect
  loop { sleep 1 }
end

#say(message) ⇒ Object



51
52
53
# File 'lib/hipchat_bot.rb', line 51

def say(message)
  send_response(message)
end