diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-08 14:34:52 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-08 14:34:52 +0100 |
commit | 3dc53f61fcb7fae58c2259bc88d2a884e74b9331 (patch) | |
tree | c6790fc8d73cb0b73e580645bd1999a8c6bf53db /data | |
parent | edbd40c4a968645bd340a7300b429bd4856ee5b8 (diff) |
grouphug: fix retrieval of spurious confessions
The real confessions are in the 'main' div, so rather than
second-guessing their true location (and getting it wrong every time the
site changes layout), just skip to the 'main' div before looking for
content.
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/grouphug.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/data/rbot/plugins/grouphug.rb b/data/rbot/plugins/grouphug.rb index 5a1890a2..45083e1c 100644 --- a/data/rbot/plugins/grouphug.rb +++ b/data/rbot/plugins/grouphug.rb @@ -10,6 +10,7 @@ # License:: GPL v2 class GrouphugPlugin < Plugin + START = '<div id="main"' REG = Regexp.new('<div class="content">\s*<p>(.*?)</p>\s+</div>', Regexp::MULTILINE) REGPOST = Regexp.new('title>(.*?) \| Group Hug') def initialize @@ -55,15 +56,16 @@ class GrouphugPlugin < Plugin path = "confessions/#{params[:num]}" opts.delete(:cache) data = @bot.httputil.get("http://grouphug.us/#{path}", opts) - - res = data.scan(REG) - confession = res[2][0].ircify_html # use res[2] to skip the new sidebar "Group Hug is run by one person..." and other text. + start = data.index(START) + res = data[start, data.length - start].scan(REG) + confession = res.first[0].ircify_html confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num] m.reply confession else # Cache random confessions if @confessions.empty? data = @bot.httputil.get("http://grouphug.us/#{path}", opts) - res = data.scan(REG) + start = data.index(START) + res = data[start, data.length - start].scan(REG) res.each do |quote| @confessions << quote[0].ircify_html end |