require 'IRC' require 'uri' require 'net/http' require 'rexml/document' require 'IRCSSLConnection' url = 'http://www3.de.indymedia.org/RSS/openposting.xml' fetching_pause = 120 messaging_pause = 3 host = 'irc.indymedia.org' port = '6697' realname = 'openposting bot' channel = '#de' bot = IRC.new('openposting', host, port, realname) IRCEvent.add_callback('endofmotd') { |event| bot.add_channel(channel) } botthread = Thread.new(bot) { |bot| bot.connect } fetched = [] iteration = 0 while true do xml = REXML::Document.new(Net::HTTP.get_response(URI.parse(url)).body) xml.elements.each('//item') do |element| unless fetched.include?(element.elements['link'].text) fetched.push(element.elements['link'].text) next if iteration == 0 bot.send_message( '#test', element.elements['title'].text + ' | ' + element.elements['link'].text + ' | ' + element.elements['description'].text.gsub(/<.*?>/, ' ').gsub(/ {2,}/, ' ').strip ) sleep messaging_pause end end sleep fetching_pause iteration += 1 end