]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/delicious.rb
script plugin: hook on message() rather than listen()
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / delicious.rb
index 9244b9bc440e47d1e63fd2b1b2945796c2f13b0a..61ba0091a0e33df87d6cd14693c826e880a308c7 100644 (file)
@@ -18,17 +18,17 @@ class DeliciousPlugin < Plugin
 
   attr_accessor :last_error
 
-  BotConfig.register BotConfigStringValue.new('delicious.user',
+  Config.register Config::StringValue.new('delicious.user',
     :default => '', :desc => "Username on del.icio.us")
-  BotConfig.register BotConfigStringValue.new('delicious.password',
+  Config.register Config::StringValue.new('delicious.password',
     :default => '', :desc => "Password on del.icio.us")
-  BotConfig.register BotConfigStringValue.new('delicious.user_fmt',
+  Config.register Config::StringValue.new('delicious.user_fmt',
     :default => 'user:%s', :desc => "How to convert users to tags?")
-  BotConfig.register BotConfigStringValue.new('delicious.channel_fmt',
+  Config.register Config::StringValue.new('delicious.channel_fmt',
     :default => 'channel:%s', :desc => "How to convert channels to tags?")
 
   def help(plugin, topic="")
-    "delicious => show url of del.icio.us feed of bot url log."
+    "logs urls seen to del.icio.us. you can use [tags: tag1 tag2 ...] to provide tags. special tags are: #{Underline}!hide#{Underline} - log the url as non-shared, #{Underline}!skip#{Underline} - don't log the url. Commands: !#{Bold}delicious#{Bold} => show url of del.icio.us feed of bot url log. "
   end
 
   def diu_req(verb, opts = {})
@@ -46,7 +46,7 @@ class DeliciousPlugin < Plugin
   end
 
   def diu_add(url, opts = {})
-    old = diu_req('get', :url => url).root.get_elements('/posts/post')[0] rescue ni
+    old = diu_req('get', :url => url).root.get_elements('/posts/post')[0] rescue nil
     opts[:tags] ||= ''
     if old
       opts[:description] ||= old.attribute('description').to_s
@@ -71,7 +71,20 @@ class DeliciousPlugin < Plugin
     end
     if options[:ircline] and options[:ircline].match(/\[tag(?:s)?:([^\]]+)\]/)
       tags = $1
-      opts[:tags] << ' ' + tags.tr(',', ' ')
+      tags.tr(',', ' ').split(/\s+/).each do |t|
+        if t.sub!(/^!/, '')
+          case t
+          when 'nolog', 'no-log', 'dont-log', 'dontlog', 'skip':
+            debug "skipping #{url} on user request"
+            return
+          when 'private', 'unshared', 'not-shared', 'notshared', 'hide':
+            debug "hiding #{url} on user request"
+            opts[:shared] = 'no'
+          end
+        else
+          opts[:tags] << ' ' + t
+        end
+      end
     end
     debug "backgrounding del.icio.us api call"
     Thread.new { diu_add(url, opts) }