summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-08-31 20:40:46 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-08-31 20:40:46 +0200
commit30e9bb21325872963f5532527e78d787fe7b26d0 (patch)
treee99085bebed956d73d2755e24d3eb507221ef6db /data/rbot
parentcd27dd58378016dac5266e89c65e69ff3e383292 (diff)
search plugin: update gdef
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/search.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb
index 5745a24b..827a1303 100644
--- a/data/rbot/plugins/search.rb
+++ b/data/rbot/plugins/search.rb
@@ -21,7 +21,7 @@ GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
GOOGLE_WAP_LINK = /<a href="(?:.*?u=(.*?)|(http:\/\/.*?))">(.*?)<\/a>/im
GOOGLE_CALC_RESULT = %r{<img src=/images/calc_img\.gif(?: width=40 height=30 alt="")?>.*?<h2 class=r[^>]*><b>(.+?)</b>}
GOOGLE_COUNT_RESULT = %r{<font size=-1>Results <b>1<\/b> - <b>10<\/b> of about <b>(.*)<\/b> for}
-GOOGLE_DEF_RESULT = %r{<p> (Web definitions for .*?)<br/>(.*?)<br/>(.*?)\s-\s+<a href}
+GOOGLE_DEF_RESULT = %r{<a href="([^"]*)"[^>]*>(Web definitions for .*?)<br/>(.*?)<br/>(.*?)\s-\s+<a href}
GOOGLE_TIME_RESULT = %r{alt="Clock"></td><td valign=[^>]+>(.+?)<(br|/td)>}
class SearchPlugin < Plugin
@@ -212,10 +212,21 @@ class SearchPlugin < Plugin
return
end
- head = results[0][0].ircify_html
- text = results[0][1].ircify_html
- link = results[0][2]
+ gdef_link = "http://www.google.com" + CGI.unescapeHTML(results[0][0]) # could be used to extract all defs
+ head = results[0][1].ircify_html
+ text = results[0][2].ircify_html
+ link = results[0][3]
m.reply "#{head} -- #{link}\n#{text}"
+
+ ### gdef_link could be used for something like
+ # html_defs = @bot.httputil.get(gdef_link)
+ # related_index = html_defs.index(/Related phrases:/, 0)
+ # defs_index = html_defs.index(/Definitions of <b>/, related_index)
+
+ # related = html_defs[related_index..defs_index]
+ # defs = html_defs[defs_index..-1]
+
+ # m.reply defs.gsub(' <br/>','<li>').ircify_html
end
def wikipedia(m, params)