]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rss.rb
rss: watch handle case during rename
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rss.rb
index fac7a9244e1992fea0170588fc261b970e56e5bc..eb3fa5f86b1bcb60be626006f323b91ac1341a14 100644 (file)
@@ -162,18 +162,27 @@ module ::RSS
       end
     end
 
+    # Atom categories are squashed to their label only
     {
       :link => %w{link.href link},
       :guid => %w{guid.content guid},
       :content => %w{content.content content},
       :description => %w{description.content description},
       :title => %w{title.content title},
-      :category => %w{category.content category},
+      :category => %w{category.content category.label category},
       :dc_subject => %w{dc_subject},
       :author => %w{author.name.content author.name author},
       :dc_creator => %w{dc_creator}
     }.each { |name, chain| def_bang name, chain }
 
+    def categories!
+      return nil unless self.respond_to? :categories
+      cats = categories.map do |c|
+        blank2nil { c.content rescue c.label rescue c rescue nil }
+      end.compact
+      cats.empty? ? nil : cats
+    end
+
     protected
     def blank2nil(&block)
       x = yield
@@ -377,7 +386,7 @@ class RSSFeedsPlugin < Plugin
 
   # Define default output filters (rss types), and load custom ones.
   # Custom filters are looked for in the plugin's default filter locations
-  # and in rss/types under botclass.
+  # and in rss/types.rb under botclass.
   # Preferably, the rss_type method should be used in these files, e.g.:
   #   rss_type :my_type do |s|
   #     line1 = "%{handle} and some %{author} info"
@@ -772,15 +781,28 @@ class RSSFeedsPlugin < Plugin
     end
     case params[:what].intern
     when :handle
-      new = params[:new].downcase
-      if @feeds.key?(new) and @feeds[new]
+      # preserve rename case, but beware of key
+      realnew = params[:new]
+      new = realnew.downcase
+      if feed.handle.downcase == new
+        if feed.handle == realnew
+          m.reply _("You want me to rename %{handle} to itself?") % {
+            :handle => feed.handle
+          }
+          return false
+        else
+          feed.mutex.synchronize do
+            feed.handle = realnew
+          end
+        end
+      elsif @feeds.key?(new) and @feeds[new]
         m.reply "There already is a feed with handle #{new}"
         return
       else
         feed.mutex.synchronize do
           @feeds[new] = feed
           @feeds.delete(handle)
-          feed.handle = new
+          feed.handle = realnew
         end
         handle = new
       end
@@ -919,7 +941,7 @@ class RSSFeedsPlugin < Plugin
         debug "fetching #{feed}"
 
         first_run = !feed.last_success
-        if (@bot.config['rss.announce_timeout'] > 0 &&
+        if (!first_run && @bot.config['rss.announce_timeout'] > 0 &&
            (Time.now - feed.last_success > @bot.config['rss.announce_timeout']))
           debug "#{feed} wasn't polled for too long, supressing output"
           first_run = true
@@ -1112,6 +1134,7 @@ class RSSFeedsPlugin < Plugin
     link = item.link!
     link.strip! if link
 
+    categories = item.categories!
     category = item.category! || item.dc_subject!
     category.strip! if category
     author = item.dc_creator! || item.author!
@@ -1128,12 +1151,13 @@ class RSSFeedsPlugin < Plugin
     stream_hash = {
       :item => item,
       :handle => handle,
-      :handle_wrap => '::',
+      :handle_wrap => ['::', ':: '],
       :date => date,
       :date_wrap => [nil, ' :: '],
       :title => title,
       :title_wrap => Bold,
       :desc => desc, :link => link,
+      :categories => categories,
       :category => category, :author => author, :at => at
     }
     output = @bot.filter(key, stream_hash)