+
+ first_pars = params[:firstpar] || @bot.config['google.first_par']
+
+ idx = 0
+ while first_pars > 0 and urls.length > 0
+ url.replace(urls.shift)
+ idx += 1
+ xml = @bot.httputil.get_cached(url)
+ if xml.nil?
+ debug "Unable to retrieve #{url}"
+ next
+ end
+ # We get the first par after the first main heading, if possible
+ header_found = xml.match(/<h1( [^>]*)?>.*?<\/h1>/im)
+ txt = nil
+ if header_found
+ txt = header_found.post_match[/<p( [^>]*)?>.*?<\/p>/im]
+ end
+ # If we haven't found a first par yet, try to get it from the whole
+ # document
+ unless txt
+ txt = xml[/<p( [^>]*)?>.*?<\/p>/im]
+ end
+ # Nothing yet, give up
+ unless txt
+ debug "No first par found\n#{xml}"
+ next
+ end
+ m.reply "[#{idx}] #{txt.ircify_html}".omissis_after(400)
+ first_pars -=1
+ end