diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-01-25 09:44:40 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-01-25 09:44:44 +0100 |
commit | 7993226963ede0c50da4d32d2ba877c97736ad5c (patch) | |
tree | 662776c2e408d5c1f976378c42a62a01c600f823 /data/rbot | |
parent | 435e7d0a7f47626d59b71867712dd82fde67c097 (diff) |
search: fix gcalc
Google changed their layout again. To be a little more future-proof,
split the html into as many <br/> sections as there are, and pick the
first one that contains the literal string ' = ' if there is one.
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/search.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index 60a70c54..2a1b3dc1 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -183,13 +183,15 @@ class SearchPlugin < Plugin debug "#{html.size} bytes of html recieved" - intro, result, junk = html.split(/\s*<br\/>\s*/, 3) - debug "result: #{result.inspect}" + splits = html.split(/\s*<br\/>\s*/) + candidates = splits.select { |section| section.include? ' = ' } + debug "candidates: #{candidates.inspect}" - unless result.include? '=' + if candidates.empty? m.reply "couldn't calculate #{what}" return end + result = candidates.first debug "replying with: #{result.inspect}" m.reply result.ircify_html |