X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=data%2Frbot%2Fplugins%2Fslashdot.rb;h=69f1566f7245f5db4a37a94061a8156db2bd5df9;hb=3847836a3ce7d075fc160fa3cf63b18433839c8b;hp=657cc0099b39c26f6c1ea263db3e2478b2c6de1b;hpb=55a13ec9c487860975f0fe491fbc1a7c2357c6ac;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/slashdot.rb b/data/rbot/plugins/slashdot.rb index 657cc009..69f1566f 100644 --- a/data/rbot/plugins/slashdot.rb +++ b/data/rbot/plugins/slashdot.rb @@ -23,14 +23,28 @@ class SlashdotPlugin < Plugin h = Hpricot(s[:text]) # If we have no title tag in a head tag, return as this is not # a /. page (it's probably a Slashdot RSS - return nil if h/"head/title".empty? - title = (h/"head/title").first.to_html.ircify_html + ht = h/"head/title" + return nil if ht.empty? + title = ht.first.to_html.ircify_html arts = (h/"div.article") return nil if arts.empty? if arts.length > 1 tits = [] arts.each { |el| - artitle = (el/"div.generaltitle").first.to_html.ircify_html + # see if the div tag with generaltitle class is present + artitle = (el/"div.generaltitle").first + if artitle + tits << artitle.to_html.ircify_html + next + end + # otherwise, check for skin+datitle a tags + datitle = (el/"a.datitle").first + next unless datitle + skin = (el/"a.skin").first + artitle = [ + skin ? skin.innerHTML.ircify_html : nil, + datitle.innerHTML.ircify_html + ].compact.join(" ") tits << artitle } content = tits.join(" | ") @@ -48,7 +62,7 @@ class SlashdotPlugin < Plugin @bot.register_filter(:slashdot, :htmlinfo) { |s| slashdot_filter(s) } end end - + def search_slashdot(m, params) max = params[:limit].to_i search = params[:search].to_s @@ -85,7 +99,7 @@ class SlashdotPlugin < Plugin m.reply "search for #{search} failed" end end - + def slashdot(m, params) debug params.inspect max = params[:limit].to_i @@ -109,12 +123,12 @@ class SlashdotPlugin < Plugin max = 8 if max > 8 matches = Array.new doc.elements.each("*/story") {|e| - matches << [ e.elements["title"].text, - e.elements["author"].text, + matches << [ e.elements["title"].text, + e.elements["author"].text, e.elements["time"].text.gsub(/\d{4}-(\d{2})-(\d{2})/, "\\2/\\1").gsub(/:\d\d$/, "") ] done += 1 break if done >= max - } + } if oneline m.reply matches.collect{|mat| mat[0]}.join(" | ") else