]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/urban.rb
rename file
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / urban.rb
index dd275e2de7a995e1c90f3fdc7d7287d5a3dcc1a2..f95eabd6f35e23ec88f26cbe5ba31fd1ad038aa3 100644 (file)
@@ -1,5 +1,12 @@
 require 'cgi'
-require 'rubyful_soup'
+begin
+  require 'rubyful_soup'
+rescue
+  warning "could not load rubyful_soup, urban dictionary disabled"
+  warning "please get it from http://www.crummy.com/software/RubyfulSoup/"
+  warning "or install it via gem"
+  return
+end
 require 'uri/common'
 
 class UrbanPlugin < Plugin
@@ -30,11 +37,11 @@ class UrbanPlugin < Plugin
       uri = URI.parse( "http://www.urbandictionary.com/define.php?term=#{ URI.escape query}" )
     end
 
-    soup = BeautifulSoup.new( @bot.httputil.get( uri ) )
+    soup = BeautifulSoup.new( @bot.httputil.get_cached( uri ) )
     if titleNavi = soup.find_all( 'td', :attrs => { 'class' => 'def_word' } )[0] then
       title = titleNavi.contents
       results = soup.find_all( 'div', :attrs => { 'class' => 'def_p' } )
-      debug PP.pp(results,'')
+      debug PP.pp(results,'')
       output = Array.new
       if results[definitionN] then
         results[definitionN].p.contents.each { |s| output.push( strip_tags( s.to_s ) ) }