Skip to content

Instantly share code, notes, and snippets.

@kurbmedia
Created February 27, 2011 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurbmedia/846469 to your computer and use it in GitHub Desktop.
Save kurbmedia/846469 to your computer and use it in GitHub Desktop.
Basic daemon to run a jabber bot
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('name@gmail.com', "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