Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require "rubygems"
- require "xmpp4r"
- user = "user@gmail.com"
- pass = "password_goes_here"
- jid = Jabber::JID.new(user)
- client = Jabber::Client.new(jid)
- client.connect
- client.auth(pass)
- mel = Jabber::JID.new("mel@seomoz.org")
- sent = []
- mainthread = Thread.current
- client.send(Jabber::Presence.new.set_status("Ruby Robot logged on @ #{Time.now.utc}"))
- msg = Jabber::Message.new(mel, "SEND ME MESSAGES!")
- client.send(msg)
- client.add_message_callback do |m|
- if m.type != :error
- if !sent.include?(m.from)
- msg = Jabber::Message.new(m.from, "I am a robot. ")
- msg.type = :chat
- client.send(msg)
- sent << m.from
- end
- case m.body
- when 'exit'
- msg = Jabber::Message.new(m.from, "Exiting")
- msg.type = :chat
- client.send(msg)
- mainthread.wakeup
- else
- puts "Received: " + m.body
- output = `/usr/bin/env #{m.body}`
- #msg = Jabber::Message.new(m.from, "You said: #{m.body}")
- msg = Jabber::Message.new(m.from, output)
- msg.type = :chat
- client.send(msg)
- end
- else
- puts [m.type.to_s, m.body].join(": ")
- end
- end
- Thread.stop
- client.close
Add Comment
Please, Sign In to add comment