]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
config core module: config search command
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Feb 2008 15:25:04 +0000 (16:25 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 14 Feb 2008 15:25:04 +0000 (16:25 +0100)
lib/rbot/core/config.rb

index 13f93c9def78b246a3125b89abbd2bf0f913797d..9f5d76f02bd9e9110aab8f9a681d3de0c95b1a48 100644 (file)
@@ -62,6 +62,20 @@ class ConfigModule < CoreBotModule
     m.reply "#{key}: #{@bot.config.items[key].desc}"\r
   end\r
 \r
+  def handle_search(m, params)\r
+    rx = Regexp.new(params[:rx].to_s, true)\r
+    cfs = []\r
+    @bot.config.items.each do |k, v|\r
+      cfs << v if k.to_s.match(rx) or (v.desc.match(rx) rescue false)\r
+    end\r
+    if cfs.empty?\r
+      m.reply _("no config key found matching %{r}") % { :r => params[:rx].to_s}\r
+    else\r
+      m.reply _("possible keys: %{kl}") % { :kl => cfs.map { |c| c.key}.join(', ') }\r
+      m.reply cfs.map { |c| [c.key, c.desc].join(': ') }.join("\n")\r
+    end\r
+  end\r
+\r
   def handle_unset(m, params)\r
     key = params[:key].to_s.intern\r
     unless @bot.config.items.has_key?(key)\r
@@ -252,6 +266,9 @@ conf.map 'config desc :key',
 conf.map 'config describe :key',\r
   :action => 'handle_desc',\r
   :auth_path => 'show'\r
+conf.map 'config search *rx',\r
+  :action => 'handle_search',\r
+  :autho_path => 'show'\r
 \r
 conf.map "save",\r
   :action => 'bot_save'\r