Skip to content

Instantly share code, notes, and snippets.

@melito
Created November 12, 2008 05:55
Show Gist options
  • Save melito/24099 to your computer and use it in GitHub Desktop.
Save melito/24099 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rubygems"
require "xmpp4r"
user = "[email protected]"
pass = "password_goes_here"
jid = Jabber::JID.new(user)
client = Jabber::Client.new(jid)
client.connect
client.auth(pass)
mel = Jabber::JID.new("[email protected]")
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment