Class: JabberBot
- Inherits:
-
Jabber::Client
- Object
- Jabber::Client
- JabberBot
- Includes:
- Jabber
- Defined in:
- lib/jabber_bot.rb
Instance Method Summary collapse
- #connect_and_authenticate ⇒ Object
-
#initialize(jabber_id, jabber_password, options = {}) ⇒ JabberBot
constructor
A new instance of JabberBot.
- #on_message(from, body) ⇒ Object
- #run ⇒ Object
- #say(jabber_id, body) ⇒ Object
Constructor Details
#initialize(jabber_id, jabber_password, options = {}) ⇒ JabberBot
Returns a new instance of JabberBot.
6 7 8 9 10 11 12 13 |
# File 'lib/jabber_bot.rb', line 6 def initialize(jabber_id, jabber_password, = {}) @jabber_id = jabber_id @jabber_password = jabber_password @options = jid = JID::new(@jabber_id) super(jid) end |
Instance Method Details
#connect_and_authenticate ⇒ Object
19 20 21 22 23 |
# File 'lib/jabber_bot.rb', line 19 def connect_and_authenticate connect auth(@jabber_password) send(Presence::new) end |
#on_message(from, body) ⇒ Object
15 16 17 |
# File 'lib/jabber_bot.rb', line 15 def (from, body) raise "on_message not implemented!" end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jabber_bot.rb', line 25 def run main = Thread.current { || next if .type == :error or .body.blank? # support exit command if owner is set main.wakeup if @options[:owner_jabber_id] == .from && .body == 'exit' # simple callback self.(.from, .body, .first_element('entry')) } Thread.stop close end |
#say(jabber_id, body) ⇒ Object
38 39 40 |
# File 'lib/jabber_bot.rb', line 38 def say(jabber_id, body) send(Message::new(jabber_id, body).set_type(:chat).set_id('1')) end |