Class: HappyFunTimeBot
- Inherits:
-
Object
- Object
- HappyFunTimeBot
- Defined in:
- lib/happy_fun_time_bot.rb
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 = {}) ⇒ HappyFunTimeBot
constructor
A new instance of HappyFunTimeBot.
- #run! ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
15 16 17 |
# File 'lib/happy_fun_time_bot.rb', line 15 def client @client end |
#command_regexp ⇒ Object
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 |
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/happy_fun_time_bot.rb', line 15 def config @config end |
#muc ⇒ Object
Returns the value of attribute muc.
15 16 17 |
# File 'lib/happy_fun_time_bot.rb', line 15 def muc @muc end |
#responders ⇒ Object
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 = nil, &block) ⇒ Object
42 43 44 |
# File 'lib/happy_fun_time_bot.rb', line 42 def add_responder(command = nil, &block) responders << Responder.new(command, &block) end |
#connect ⇒ Object
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. { |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 |