]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/url.rb
plugins/keywords: add method that was missing from commit 7cac523563de6473d2f93fd2d05 ...
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / url.rb
index f44da3eb879f1f72ad550e25e1a89c98c4520614..d08c24e837fea4fe2bb88b6829a7ba5e322fef8a 100644 (file)
@@ -79,7 +79,7 @@ class UrlPlugin < Plugin
 
     begin
       debug "+ getting info for #{url.request_uri}"
-      info = Utils.get_html_info(url)
+      info = @bot.filter(:htmlinfo, url)
       debug info
       resp = info[:headers]
 
@@ -140,12 +140,21 @@ class UrlPlugin < Plugin
         debug "Title #{title ? '' : 'not '} found"
         reply = "#{LINK_INFO} #{title}" if title
       rescue => e
+        debug e
+        # we might get a 404 because of trailing punctuation, so we try again
+        # with the last character stripped. this might generate invalid URIs
+        # (e.g. because "some.url" gets chopped to some.url%2, so catch that too
+        if e.message =~ /\(404 - Not Found\)/i or e.kind_of?(URI::InvalidURIError)
+          # chop off last character, and retry if we still have enough string to
+          # look like a minimal URL
+          retry if urlstr.chop! and urlstr =~ /^https?:\/\/./
+        end
         reply = "Error #{e.message}"
       end
 
       if display_info > urls_displayed
         if reply
-          m.reply(reply, :overlong => :truncate)
+          m.plainreply(reply, :overlong => :truncate)
           urls_displayed += 1
         end
       end