Help with Ruby XMPP4R

Hi All,

A complete newbie here, I have been left some Ruby code by a contractor
and need some help.

I would like the bot to reconnect when it is kicked from the room or
when the server is rebooted/goes offline. Current this is happening, but
the time it takes for it to reconnect is random, sometimes it will take
5 minutes others 50 seconds.

Also, how would I go about adding some logging?

Thanks in advance for your help

Nick

CODE

#!/usr/bin/env ruby
require ‘rubygems’
require ‘xmpp4r/client’
require ‘xmpp4r/roster’
require ‘xmpp4r/muc’
require ‘socket’
require ‘daemons’
include Jabber

options = {}
options[:host] = ‘XXXXXX’
options[:port] = 5222
options[:jid] = “XXXX@XXXXXX/#ETVDVXDF
options[:password] = ‘XXXXXX’
options[:room_jid] = ‘XXXX@XXXXXX/XXXXX’

Bind to localhost

server = TCPServer.new(“127.0.0.1”, 5223) # Server bind to port 5223

cl = Client.new(JID::new(options[:jid]))

def reconnect(cl)
cl.connect(‘XXXXXX’, 5222 )
cl.auth( ‘XXXXX’)
cl.send(Presence.new.set_type(:available))
end

cl.connect(‘talk.google.com’, 5222 )
cl.auth( ‘XXXXXXX’)
cl.send(Presence.new.set_type(:available))

muc_room = MUC::SimpleMUCClient.new(cl)
muc_room.join(options[:room_jid])

while true
Thread.start(server.accept) do |cl|
response = cl.gets
muc_room.say(response)
cl.close
end
end

reconnect(cl)
cl.on_exception { sleep 1; reconnect(cl) }