Created
February 27, 2011 19:48
-
-
Save kurbmedia/846469 to your computer and use it in GitHub Desktop.
Basic daemon to run a jabber bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JabberBot | |
attr_accessor :daemon | |
attr_accessor :messenger | |
def initialize | |
end | |
def activate! | |
@daemon = Daemons.run_proc('dev_bot', :dir => "#{Rails.root}/tmp/pids", :dir_mode => :normal, :monitor => false, :log_output => true ) do | |
@messenger = Jabber::Simple.new('[email protected]', "password", status = nil, status_message = "Available", host = 'talk.l.google.com') | |
puts "Connected and ready to serve you master...." | |
loop do | |
messenger.connect! unless messenger.connected? | |
process_incoming if messenger.received_messages? | |
sleep(3) | |
end | |
end | |
end | |
def messenger; @messenger; end | |
def process_incoming | |
messenger.received_messages do |msg| | |
messenger.deliver(msg.from, "Got your message thanks! You said: #{msg.body}") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment