Created
February 26, 2009 08:54
-
-
Save visnup/70743 to your computer and use it in GitHub Desktop.
xmpp4r + say
This file contains 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
# login to jabber/gtalk and have your computer say whatever people are saying to you | |
require 'rubygems' | |
require 'xmpp4r/client' | |
include Jabber | |
# settings | |
if ARGV.length != 2 | |
puts "Run with ./echo_thread.rb user@server/resource password" | |
exit 1 | |
end | |
id, pass = JID.new(ARGV[0]), ARGV[1] | |
cl = Client.new id | |
cl.connect | |
cl.auth pass | |
cl.send Presence.new | |
puts id.strip.to_s | |
mainthread = Thread.current | |
cl.add_message_callback do |m| | |
if m.type != :error | |
puts m.body | |
`say "#{m.body}"` | |
if m.body == 'exit' | |
mainthread.wakeup | |
end | |
end | |
end | |
Thread.stop | |
cl.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment