Created
January 18, 2011 07:27
-
-
Save aaronjensen/784090 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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 = '[email protected]' | |
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('&','&') | |
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