Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created January 18, 2011 07:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronjensen/784090 to your computer and use it in GitHub Desktop.
Save aaronjensen/784090 to your computer and use it in GitHub Desktop.
# Needs Ruby 1.8.7
# gem install hipchat
# gem install xmpp4r-simple
# gem install daemons
# run with ruby zentc_to_hipchat.rb start
require 'rubygems'
require 'hipchat'
require 'xmpp4r-simple'
require 'daemons'
##### Change these values before running
hipchat_api_key = '123456789abcdef'
hipchat_room = 'RoomName'
zen_hipchat_name = 'Zen'
tc_hipchat_name = 'Build'
jabber_username = 'username@gmail.com'
jabber_password = 'password'
#####
client = HipChat::Client.new(hipchat_api_key)
def get_html(msg)
msg.first_element("html").first_element("body").to_s.gsub(/\<\/?body.*?\>/,'')
end
def get_link(msg)
link = ''
msg.first_element("html").first_element("body").each_element_with_attribute('href') { |e|
link = e.attributes['href']
}
link
end
def clean(msg)
msg.gsub("\n",'<br />').gsub(/http:\/\/[^ ]*/,'<a href="\0">\0</a>').gsub('&','&amp;')
end
Daemons.run_proc 'zentc_to_hipchat' do
im = Jabber::Simple.new(jabber_username, jabber_password)
while true do
im.reconnect if !im.connected?
im.received_messages { |msg|
if msg.from.to_s =~ /robot/
client[hipchat_room].send(tc_hipchat_name, clean(msg.body), false)
else
client[hipchat_room].send(zen_hipchat_name, get_html(msg), false) if msg.type == :chat
end
}
sleep 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment