]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugins: use CGI.escape instead of URI.escape where appropriate, remove some checks...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 8 Apr 2007 09:37:01 +0000 (09:37 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 8 Apr 2007 09:37:01 +0000 (09:37 +0000)
data/rbot/plugins/bash.rb
data/rbot/plugins/dict.rb
data/rbot/plugins/fish.rb
data/rbot/plugins/freshmeat.rb
data/rbot/plugins/games/azgame.rb
data/rbot/plugins/imdb.rb
data/rbot/plugins/lastfm.rb
data/rbot/plugins/search.rb
data/rbot/plugins/slashdot.rb
data/rbot/plugins/urban.rb
data/rbot/plugins/weather.rb

index 520346be4bc480f78575e5fe0df709234712a5d2..93d9c3f2af77f54844bb77b2edd7b79f3dbd4f79 100644 (file)
@@ -17,7 +17,6 @@
 # TODO allow selection of only quotes with vote > 0
 
 require 'rexml/document'
-require 'uri/common'
 
 class ::BashQuote
   attr_accessor :num, :text, :vote
@@ -56,7 +55,7 @@ class BashPlugin < Plugin
   end
 
   def search(m, params)
-    esc = URI.escape(params[:words].to_s)
+    esc = CGI.escape(params[:words].to_s)
     html = @bot.httputil.get("http://bash.org/?search=#{esc}")
     html_bash(m, :html => html)
   end
index ef162215ef4ee5044363ba24ce4b11139d775832..30cfc5feefb9eefba7259c667b7e6619a26d6a8e 100644 (file)
@@ -54,7 +54,7 @@ class DictPlugin < Plugin
     justcheck = params[:justcheck]\r
 \r
     word = params[:word].downcase\r
-    url = @dmwapurl % URI.escape(word)\r
+    url = @dmwapurl % CGI.escape(word)\r
     xml = nil\r
     info = @bot.httputil.get_response(url) rescue nil\r
     xml = info.body if info\r
@@ -106,7 +106,7 @@ class DictPlugin < Plugin
 \r
     word = params[:word].join\r
     [word, word + "_1"].each { |check|\r
-      url = @oxurl % URI.escape(check)\r
+      url = @oxurl % CGI.escape(check)\r
       h = @bot.httputil.head(url, :max_redir => 5)\r
       if h\r
         m.reply("#{word} found: #{url}") unless justcheck\r
@@ -126,7 +126,7 @@ class DictPlugin < Plugin
     justcheck = params[:justcheck]\r
 \r
     word = params[:word].to_s.downcase\r
-    url = @chambersurl % URI.escape(word)\r
+    url = @chambersurl % CGI.escape(word)\r
     xml = nil\r
     info = @bot.httputil.get_response(url) rescue nil\r
     xml = info.body if info\r
index 140c95704b2cb1a904c1aa7bf0eb034a68453eb5..dcd4a0e3928f505856d10896c5b02faccc8da637 100644 (file)
@@ -31,7 +31,7 @@ class BabelPlugin < Plugin
       return
     end
 
-    data_text = URI.escape trans_text
+    data_text = CGI.escape trans_text
     trans_pair = "#{trans_from}_#{trans_to}"
 
     if (trans_text =~ /^http:\/\//) && (URI.parse(trans_text) rescue nil)
index 5a045123256e72fc35b617b83078696e94102e40..49e73e0d2785b447ecef4237240c048765c548db 100644 (file)
@@ -1,5 +1,4 @@
 require 'rexml/document'
-require 'uri/common'
 
 class FreshmeatPlugin < Plugin
   include REXML
@@ -11,12 +10,7 @@ class FreshmeatPlugin < Plugin
     max = params[:limit].to_i
     search = params[:search].to_s
     max = 8 if max > 8
-    begin
-      xml = @bot.httputil.get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{URI.escape(search)}")
-    rescue URI::InvalidURIError, URI::BadURIError => e
-      m.reply "illegal search string #{search}"
-      return
-    end
+    xml = @bot.httputil.get("http://freshmeat.net/search-xml/?orderby=locate_projectname_full_DESC&q=#{CGI.escape(search)}")
     unless xml
       m.reply "search for #{search} failed"
       return
index f62232c086046094e874916d6281837d7dcf3612..66646e7361df3d87f0e81e0cd3e1315eddab359e 100644 (file)
@@ -446,7 +446,7 @@ class AzGamePlugin < Plugin
     wc = @wordcache[:english]\r
     return true if wc.key?(word.to_sym)\r
     rules = @rules[:english]\r
-    p = @bot.httputil.get(rules[:url] % URI.escape(word))\r
+    p = @bot.httputil.get(rules[:url] % CGI.escape(word))\r
     if not p\r
       error "could not connect!"\r
       return false\r
@@ -497,7 +497,7 @@ class AzGamePlugin < Plugin
         ll = ('a'..'z').to_a[rand(26)]\r
         random = [l,ll].join('*') + '*'\r
         debug "getting random word from dictionary, matching #{random}"\r
-        p = @bot.httputil.get(rules[:url] % URI.escape(random))\r
+        p = @bot.httputil.get(rules[:url] % CGI.escape(random))\r
         debug p\r
         lemmi = Array.new\r
         good = rules[:good]\r
index 240ded86303cfb35420bc2b1d37dee588ee09d9d..0464ba3ae4b009d2627a5850742d68ff9f9edb43 100644 (file)
@@ -32,7 +32,7 @@ class Imdb
   end
 
   def search(rawstr, rawopts={})
-    str = URI.escape(rawstr)
+    str = CGI.escape(rawstr)
     str << ";site=aka" if @bot.config['imdb.aka']
     opts = rawopts.dup
     opts[:type] = :both unless opts[:type]
index 46b140fff86c43e2599ba87e790a097faf3eab7e..6e7d4c7119ab1fa56392e278c69229260d69eba3 100644 (file)
@@ -70,10 +70,10 @@ class LastFmPlugin < Plugin
     spec = location ? "in #{location}" : "by #{artist}"
     begin
       if location
-        esc = URI.escape(location)
+        esc = CGI.escape(location)
         page = @bot.httputil.get "#{LASTFM}/events/?findloc=#{esc}"
       else
-        esc = URI.escape(artist)
+        esc = CGI.escape(artist)
         page = @bot.httputil.get "#{LASTFM}/events?s=#{esc}&findloc="
       end
 
@@ -131,7 +131,7 @@ class LastFmPlugin < Plugin
     artist = params[:who].to_s
     page = nil
     begin
-      esc = URI.escape(artist)
+      esc = URI.escape(CGI.escape(artist))
       page = @bot.httputil.get "#{LASTFM}/music/#{esc}"
       if page
         if page.match(/<h1 class="h1artist"><a href="([^"]+)">(.*?)<\/a><\/h1>/)
index da98dd08d1915cccc5e0152db4d0744061c8ef26..c733c815fd03481b1b5a2451437f3a9e9a6ea852 100644 (file)
@@ -45,7 +45,7 @@ class SearchPlugin < Plugin
 
   def google(m, params)
     what = params[:words].to_s
-    searchfor = URI.escape what
+    searchfor = CGI.escape what
     # This method is also called by other methods to restrict searching to some sites
     if params[:site]
       site = "site:#{params[:site]}+"
@@ -93,7 +93,7 @@ class SearchPlugin < Plugin
 
   def gcalc(m, params)
     what = params[:words].to_s
-    searchfor = URI.escape(what).sub('+','%2B')
+    searchfor = CGI.escape(what)
     
     debug "Getting gcalc thing: #{searchfor.inspect}"
     url = "http://www.google.com/search?q=#{searchfor}"
index fa1338bdcc8d6f75af330e9bbe31e309e8bf12b1..c9e35b9e9592badde10fe4689aa9765e17c55add 100644 (file)
@@ -1,5 +1,4 @@
 require 'rexml/document'
-require 'uri/common'
 
 class SlashdotPlugin < Plugin
   include REXML
@@ -8,15 +7,10 @@ class SlashdotPlugin < Plugin
   end
   
   def search_slashdot(m, params)
-   max = params[:limit].to_i
-   search = params[:search].to_s
+    max = params[:limit].to_i
+    search = params[:search].to_s
 
-    begin
-      xml = @bot.httputil.get("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}")
-    rescue URI::InvalidURIError, URI::BadURIError => e
-      m.reply "illegal search string #{search}"
-      return
-    end
+    xml = @bot.httputil.get("http://slashdot.org/search.pl?content_type=rss&query=#{CGI.escape(search)}")
     unless xml
       m.reply "search for #{search} failed"
       return
@@ -39,7 +33,7 @@ class SlashdotPlugin < Plugin
     doc.elements.each("*/item") {|e|
       desc = e.elements["title"].text
       desc.gsub!(/(.{150}).*/, '\1..')
-      reply = sprintf("%s | %s", e.elements["link"].text, desc)
+      reply = sprintf("%s | %s", e.elements["link"].text, desc.ircify_html)
       m.reply reply
       done += 1
       break if done >= max
index 1a4b9d74e34562d823a7e487cbc8238a2f600fd1..9b547644ad80ea5b6be8bf4e0dcc6ad72f805270 100644 (file)
@@ -16,7 +16,7 @@ class UrbanPlugin < Plugin
       end
     end
     # we give a very high 'skip' because this will allow us to get the number of definitions by retrieving the previous definition
-    uri = "http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=65536"
+    uri = "http://www.urbanwap.com/search.php?term=#{CGI.escape words}&skip=65536"
     page = @bot.httputil.get(uri)
     if page.nil?
       m.reply "Couldn't retrieve an urban dictionary definition of #{words}"
@@ -37,7 +37,7 @@ class UrbanPlugin < Plugin
       n = numdefs
     end
     if n < numdefs
-      uri = "http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=#{n-1}"
+      uri = "http://www.urbanwap.com/search.php?term=#{CGI.escape words}&skip=#{n-1}"
       page = @bot.httputil.get(uri)
       if page.nil?
         case n % 10
index da6a2116a57548525d7799f1e808c0b162845c6d..4edcc96381b2d4c52fe822d42d713c1db2b07183 100644 (file)
@@ -164,7 +164,7 @@ class WeatherPlugin < Plugin
 
   def wu_station(m, where, units)
     begin
-      xml = @bot.httputil.get(@wu_station_url % [units, URI.escape(where)])
+      xml = @bot.httputil.get(@wu_station_url % [units, CGI.escape(where)])
       case xml
       when nil
         m.reply "couldn't retrieve weather information, sorry"
@@ -186,7 +186,7 @@ class WeatherPlugin < Plugin
 
   def wu_weather(m, where, units)
     begin
-      xml = @bot.httputil.get(@wu_url % [units, URI.escape(where)])
+      xml = @bot.httputil.get(@wu_url % [units, CGI.escape(where)])
       case xml
       when nil
         m.reply "couldn't retrieve weather information, sorry"