]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rss plugin: add command to change the handle or url or type of an existing feed
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 5 Feb 2007 16:07:07 +0000 (16:07 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 5 Feb 2007 16:07:07 +0000 (16:07 +0000)
data/rbot/plugins/rss.rb

index 03b6406d44a58c9a49cc9691508384817bd0d1c5..75fc9b472b3a8b22ce760dfc880ca2d7482580f8 100644 (file)
@@ -26,9 +26,9 @@ class ::String
 end\r
 \r
 class ::RssBlob\r
-  attr :url\r
-  attr :handle\r
-  attr :type\r
+  attr_accessor :url\r
+  attr_accessor :handle\r
+  attr_accessor :type\r
   attr :watchers\r
   attr_accessor :xml\r
   attr_accessor :title\r
@@ -188,6 +188,8 @@ class RSSFeedsPlugin < Plugin
       "rss watched [#{Bold}handle#{Bold}] : list all watched rss feeds (matching #{Bold}handle#{Bold})"\r
     when "add"\r
       "rss add #{Bold}handle#{Bold} #{Bold}url#{Bold} [#{Bold}type#{Bold}] : add a new rss called #{Bold}handle#{Bold} from url #{Bold}url#{Bold} (of type #{Bold}type#{Bold})"\r
+    when "change"\r
+      "rss change #{Bold}what#{Bold} of #{Bold}handle#{Bold} to #{Bold}new#{Bold} : change the handle, url or type of rss called #{Bold}handle#{Bold} to value #{Bold}new#{Bold}"\r
     when /^(del(ete)?|rm)$/\r
       "rss del(ete)|rm #{Bold}handle#{Bold} : delete rss feed #{Bold}handle#{Bold}"\r
     when "replace"\r
@@ -201,7 +203,7 @@ class RSSFeedsPlugin < Plugin
     when "rewatch"\r
       "rss rewatch : restart threads that watch for changes in watched rss"\r
     else\r
-      "manage RSS feeds: rss show|list|watched|add|del(ete)|rm|(force)replace|watch|unwatch|rmwatch|rewatch"\r
+      "manage RSS feeds: rss show|list|watched|add|change|del(ete)|rm|(force)replace|watch|unwatch|rmwatch|rewatch"\r
     end\r
   end\r
 \r
@@ -331,6 +333,41 @@ class RSSFeedsPlugin < Plugin
     return handle\r
   end\r
 \r
+  def change_rss(m, params)\r
+    handle = params[:handle].downcase\r
+    feed = @feeds.fetch(handle, nil)\r
+    return m.reply "No such feed with handle #{handle}" unless feed\r
+    case params[:what].intern\r
+    when :handle\r
+      new = params[:new].downcase\r
+      if @feeds.key?(new) and @feeds[new]\r
+        m.reply "There already is a feed with handle #{new}"\r
+        return\r
+      else\r
+        @feeds[new] = feed\r
+        @feeds.delete(handle)\r
+        feed.handle = new\r
+        handle = new\r
+      end\r
+    when :url\r
+      new = params[:new]\r
+      feed.mutex.synchronize do\r
+        feed.url = new\r
+      end\r
+    when :format, :type\r
+      new = params[:new]\r
+      new = nil if new == 'default'\r
+      feed.mutex.synchronize do\r
+        feed.type = new\r
+      end\r
+    else\r
+      m.reply "Don't know how to change #{params[:what]} for feeds"\r
+      return\r
+    end\r
+    m.reply "Feed changed:"\r
+    list_rss(m, {:handle => handle})\r
+  end\r
+\r
   def del_rss(m, params, pass=false)\r
     feed = unwatch_rss(m, params, true)\r
     if feed.watched?\r
@@ -616,6 +653,12 @@ plugin.map 'rss watched :handle',
 plugin.map 'rss add :handle :url :type',\r
   :action => 'add_rss',\r
   :defaults => {:type => nil}\r
+plugin.map 'rss change :what of :handle to :new',\r
+  :action => 'change_rss',\r
+  :requirements => { :what => /handle|url|format|type/ }\r
+plugin.map 'rss change :what for :handle to :new',\r
+  :action => 'change_rss',\r
+  :requirements => { :what => /handle|url|format|type/ }\r
 plugin.map 'rss del :handle',\r
   :action => 'del_rss'\r
 plugin.map 'rss delete :handle',\r