]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rss plugin: initial support for Atom feeds (needs Ruby's rss module 0.1.8 or later)
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 28 Nov 2007 23:15:29 +0000 (23:15 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 28 Nov 2007 23:15:29 +0000 (23:15 +0000)
data/rbot/plugins/rss.rb

index 22aa742ff6bc3c08f98a1020123f9c8e19ace2f2..87e0730c3120aed63f5a78270403bf2f7dae3856 100644 (file)
@@ -789,6 +789,7 @@ class RSSFeedsPlugin < Plugin
   end\r
 \r
   def printFormattedRss(feed, item, opts=nil)\r
+    debug item\r
     places = feed.watchers\r
     handle = "::#{feed.handle}:: "\r
     date = String.new\r
@@ -796,13 +797,25 @@ class RSSFeedsPlugin < Plugin
       places = opts[:places] if opts.key?(:places)\r
       handle = opts[:handle].to_s if opts.key?(:handle)\r
       if opts.key?(:date) && opts[:date]\r
-        if item.respond_to?(:pubDate) \r
+        if item.respond_to?(:updated)\r
+          if item.updated.content.class <= Time\r
+            date = item.updated.content.strftime("%Y/%m/%d %H:%M")\r
+          else\r
+            date = item.updated.content.to_s\r
+          end\r
+        elsif item.respond_to?(:source) and item.source.respond_to?(:updated)\r
+          if item.source.updated.content.class <= Time\r
+            date = item.source.updated.content.strftime("%Y/%m/%d %H:%M")\r
+          else\r
+            date = item.source.updated.content.to_s\r
+          end\r
+        elsif item.respond_to?(:pubDate) \r
           if item.pubDate.class <= Time\r
             date = item.pubDate.strftime("%Y/%m/%d %H:%M")\r
           else\r
             date = item.pubDate.to_s\r
           end\r
-        elsif  item.respond_to?(:date)\r
+        elsif item.respond_to?(:date)\r
           if item.date.class <= Time\r
             date = item.date.strftime("%Y/%m/%d %H:%M")\r
           else\r
@@ -820,26 +833,38 @@ class RSSFeedsPlugin < Plugin
     # limit to 160 characters, and most of them are under 140 characters\r
     tit_opt[:limit] = @bot.config['rss.head_max'] unless feed.type == 'twitter'\r
 \r
-    title = "#{Bold}#{item.title.ircify_html(tit_opt)}#{Bold}" if item.title\r
+    title = "#{Bold}#{item.title.to_s.ircify_html(tit_opt)}#{Bold}" if item.title\r
 \r
     desc_opt = {\r
       :limit => @bot.config['rss.text_max'],\r
       :a_href => :link_out\r
     }\r
-    desc = item.description.ircify_html(desc_opt) if item.description\r
 \r
-    link = item.link.chomp if item.link\r
+    if item.respond_to? :description\r
+      desc = item.description.ircify_html(desc_opt) if item.description\r
+    else\r
+      if item.content.type == "html"\r
+        desc = item.content.content.ircify_html(desc_opt)\r
+      else\r
+        desc = item.content.content\r
+        if desc.size > desc_opt[:limit]\r
+          desc = desc.slice(0, desc_opt[:limit]) + "#{Reverse}...#{Reverse}"\r
+        end\r
+      end\r
+    end\r
+\r
+    link = item.link.href rescue item.link.chomp rescue nil\r
 \r
-    debug item.inspect\r
-    category = item.dc_subject rescue item.category.content rescue nil\r
+    category = item.category.content rescue item.dc_subject rescue nil\r
     category = nil if category and category.empty?\r
-    author = item.dc_creator rescue item.author rescue nil\r
+    author = item.author.name.content rescue item.dc_creator rescue item.author rescue nil\r
     author = nil if author and author.empty?\r
 \r
     line1 = nil\r
     line2 = nil\r
 \r
     at = ((item.title && item.link) ? ' @ ' : '')\r
+\r
     case feed.type\r
     when 'blog'\r
       author << " " if author\r
@@ -936,8 +961,12 @@ class RSSFeedsPlugin < Plugin
           report_problem("bah! something went wrong =(", e, m)\r
           return nil\r
         end\r
-        rss.channel.title ||= "Unknown"\r
-        title = rss.channel.title\r
+        if rss.respond_to? :channel\r
+          rss.channel.title ||= "Unknown"\r
+          title = rss.channel.title\r
+        else\r
+          title = rss.title.content\r
+        end\r
         rss.items.each do |item|\r
           item.title ||= "Unknown"\r
           items << item\r