]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/keywords.rb
lart plugin: replace "me" with sourcenick
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / keywords.rb
index 424df8749d31bc9c290abf1f0d94bc5f893b5fa8..5ed5256544a7e4e32a30e4901fccdb4b04d0c66b 100644 (file)
@@ -33,7 +33,10 @@ class Keyword
     ar = Array.new
     @values.each { |val|
       debug "key #{key}, value #{val}"
-      ar << "%s %s %s" % [key, @type, val]
+      vals = val.split(" or ")
+      vals.each { |v|
+        ar << "%s %s %s" % [key, @type, v]
+      }
     }
     return ar
   end
@@ -440,12 +443,25 @@ class Keywords < Plugin
 
   # forget one of the dynamic keywords
   def keyword_forget(m, key)
-    if(@keywords.has_key?(key))
-      @keywords.delete(key)
-      @bot.okay m.replyto
+    if @keywords.delete(key)
+      m.okay
+    else
+      m.reply _("couldn't find keyword %{key}" % { :key => key })
     end
   end
 
+  # low-level keyword wipe command for when forget doesn't work
+  def keyword_wipe(m, key)
+    reg = @keywords.registry
+    reg.env.begin(reg) { |t, b|
+      b.delete_if { |k, v|
+        (k == key) && (m.reply "wiping keyword #{key} with stored value #{Marshal.restore(v)}")
+      }
+      t.commit
+    }
+    m.reply "done"
+  end
+
   # export keywords to factoids file
   def keyword_factoids_export
     ar = Array.new
@@ -485,6 +501,8 @@ class Keywords < Plugin
         keyword_command(m, $1, $2, $3) if @bot.auth.allow?('keycmd', m.source, m.replyto)
       when /^forget\s+(.+)$/
         keyword_forget(m, $1) if @bot.auth.allow?('keycmd', m.source, m.replyto)
+      when /^wipe\s(.+)$/ # note that only one space is stripped, allowing removal of space-prefixed keywords
+        keyword_wipe(m, $1) if @bot.auth.allow?('keycmd', m.source, m.replyto)
       when /^lookup\s+(.+)$/
         keyword_lookup(m, $1) if @bot.auth.allow?('keyword', m.source, m.replyto)
       when /^stats\s*$/