Class: HipchatBot
- Inherits:
-
Object
- Object
- HipchatBot
- Defined in:
- lib/hipchat_bot.rb,
lib/hipchat_bot/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#command_regexp ⇒ Object
Returns the value of attribute command_regexp.
-
#config ⇒ Object
Returns the value of attribute config.
-
#muc ⇒ Object
Returns the value of attribute muc.
-
#responders ⇒ Object
Returns the value of attribute responders.
Instance Method Summary collapse
- #add_responder(command = nil, &block) ⇒ Object
- #connect ⇒ Object
-
#initialize(config = {}) ⇒ HipchatBot
constructor
A new instance of HipchatBot.
- #run! ⇒ Object
- #say(message) ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
14 15 16 |
# File 'lib/hipchat_bot.rb', line 14 def client @client end |
#command_regexp ⇒ Object
Returns the value of attribute command_regexp.
14 15 16 |
# File 'lib/hipchat_bot.rb', line 14 def command_regexp @command_regexp end |
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/hipchat_bot.rb', line 14 def config @config end |
#muc ⇒ Object
Returns the value of attribute muc.
14 15 16 |
# File 'lib/hipchat_bot.rb', line 14 def muc @muc end |
#responders ⇒ Object
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 |
#connect ⇒ Object
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. { |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() send_response() end |