summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-06 16:46:54 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-06 16:46:54 +0000
commitbcacf025a0d2cbba181ad3e55fba30926286f9c8 (patch)
tree587e32335e8c2e1ddfc3393ebceb136653bf0638 /lib/rbot
parentd845911e2e16734f1dffb9f5747bd87233824204 (diff)
Move code to get first par from a series of urls from search plugin to Utils, and use it in dict plugin too
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/core/utils/utils.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb
index 11312e19..f5a6c1db 100644
--- a/lib/rbot/core/utils/utils.rb
+++ b/lib/rbot/core/utils/utils.rb
@@ -445,5 +445,40 @@ module ::Irc
end
return txt
end
+
+ # Get the first pars of the first _count_ _urls_.
+ # The pages are downloaded using an HttpUtil service passed as _opts_ :http_util,
+ # and echoed as replies to the IRC message passed as _opts_ :message.
+ #
+ def Utils.get_first_pars(urls, count, opts={})
+ idx = 0
+ msg = opts[:message]
+ while count > 0 and urls.length > 0
+ url = urls.shift
+ idx += 1
+
+ # FIXME what happens if some big file is returned? We should share
+ # code with the url plugin to only retrieve partial file content!
+ xml = opts[:http_util].get_cached(url)
+ if xml.nil?
+ debug "Unable to retrieve #{url}"
+ next
+ end
+ debug "Retrieved #{url}"
+ debug "\t#{xml}"
+ par = Utils.ircify_first_html_par(xml)
+ if par.empty?
+ debug "No first par found\n#{xml}"
+ # FIXME only do this if the 'url' plugin is loaded
+ # TODO even better, put the code here
+ # par = @bot.plugins['url'].get_title_from_html(xml)
+ next if par.empty?
+ end
+ msg.reply "[#{idx}] #{par}", :overlong => :truncate if msg
+ count -=1
+ end
+ end
+
+
end
end