X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Frss.rb;h=7dcfdf6649977a2eccac37961163cae7964848e6;hb=51c35168127e0faed56bceb3f5103f92ed31478c;hp=a1bec30fb85eceebedc2baffe47d8e1e1ddadebf;hpb=c31697b2d75aa46df9163ebce92ee68fd0f9ce7f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb index a1bec30f..7dcfdf66 100644 --- a/data/rbot/plugins/rss.rb +++ b/data/rbot/plugins/rss.rb @@ -314,6 +314,10 @@ class RSSFeedsPlugin < Plugin # TODO: load personal ones def define_filters @outkey = :"rss.out" + @bot.register_filter(:headlines, @outkey) { |s| + line1 = (s[:handle].empty? ? "%{date}" : "%{handle}") << "%{title}" + make_stream(line1, nil, s) + } @bot.register_filter(:blog, @outkey) { |s| author = s[:author] ? (s[:author] + " ") : "" abt = s[:category] ? "about #{s[:category]} " : "" @@ -329,13 +333,13 @@ class RSSFeedsPlugin < Plugin make_stream(line1, line2, s, :author => author, :abt => abt) } @bot.register_filter(:news, @outkey) { |s| - line1 = "%{handle}%{date}%{title} @ %{link}" % s + line1 = "%{handle}%{date}%{title}%{at}%{link}" % s line2 = "%{handle}%{date}%{desc}" % s make_stream(line1, line2, s) } @bot.register_filter(:git, @outkey) { |s| author = s[:author] ? (s[:author] + " ") : "" - line1 = "%{handle}%{date}%{author}committed %{title} @ %{link}" + line1 = "%{handle}%{date}%{author}committed %{title}%{at}%{link}" make_stream(line1, nil, s, :author => author) } @bot.register_filter(:forum, @outkey) { |s| @@ -353,7 +357,7 @@ class RSSFeedsPlugin < Plugin } @bot.register_filter(:trac, @outkey) { |s| author = s[:author].sub(/@\S+?\s*>/, "@...>") + ": " if s[:author] - line1 = "%{handle}%{date}%{author}%{title} @ %{link}" + line1 = "%{handle}%{date}%{author}%{title}%{at}%{link}" line2 = nil unless s[:item].title =~ /^(?:Changeset \[(?:[\da-f]+)\]|\(git commit\))/ line2 = "%{handle}%{date}%{desc}" @@ -441,7 +445,7 @@ class RSSFeedsPlugin < Plugin } @feeds = @registry[:feeds] - raise unless @feeds + raise LoadError, "corrupted feed database" unless @feeds @registry.recovery = nil @@ -591,13 +595,12 @@ class RSSFeedsPlugin < Plugin fetched = fetchRss(feed, m, false) end return unless fetched or feed.xml - if not fetched and feed.items - m.reply "using old data" - else + if fetched or not feed.items parsed = parseRss(feed, m) - m.reply "using old data" unless parsed end return unless feed.items + m.reply "using old data" unless fetched and parsed + title = feed.title items = feed.items @@ -1089,6 +1092,13 @@ class RSSFeedsPlugin < Plugin # reassign the 0.9 RDFs to 1.0, and hope it goes right. xml.gsub!("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\"", "xmlns=\"http://purl.org/rss/1.0/\"") + # make sure the parser doesn't double-convert in case the feed is not UTF-8 + xml.sub!(/<\?xml (.*?)\?>/) do |match| + if /\bencoding=(['"])(.*?)\1/.match(match) + match.sub!(/\bencoding=(['"])(?:.*?)\1/,'encoding="UTF-8"') + end + match + end feed.mutex.synchronize do feed.xml = xml end @@ -1150,7 +1160,7 @@ class RSSFeedsPlugin < Plugin report_problem("no items found in the feed, maybe try weed?", e, m) return nil end - feed.title = title + feed.title = title.strip feed.items = items return true end