]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
filters: UI and methods to list filter groups
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 25 Mar 2008 11:44:48 +0000 (12:44 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 25 Mar 2008 11:44:48 +0000 (12:44 +0100)
lib/rbot/core/filters_ui.rb
lib/rbot/core/utils/filters.rb

index ed3e65d7cdb0ea8976f66d90f79b75993cddafde..6f5ecbb3210dd8254721e98757060cd5c70d54f2 100644 (file)
@@ -34,6 +34,16 @@ class FiltersModule < CoreBotModule
     m.reply msg
   end
 
+  def do_listgroups(m, params)
+    ar = @bot.filter_groups.map { |s| s.to_s }.sort!
+    if ar.empty?
+      msg = _("no known filter groups")
+    else
+      msg = _("known filter groups: ") << ar.join(", ") 
+    end
+    m.reply msg
+  end
+
   def do_search(m, params)
     l = @bot.filter_names.map { |s| s.to_s }
     pat = params[:pat].to_s
@@ -53,3 +63,4 @@ plugin = FiltersModule.new
 
 plugin.map "filters list [:group]", :action => :do_list
 plugin.map "filters search *pat", :action => :do_search
+plugin.map "filter groups", :action => :do_listgroups
index 2da89d085766d4697cc545afdd29b83692262cfa..6d560c9150df8d23cd8d4b7f8d068e825cd77e07 100644 (file)
@@ -96,6 +96,11 @@ module ::Irc
       @filters.key?(global_filter_name(name, group))
     end
 
+    # This method checks if the bot has a filter group named _name_
+    def has_filter_group?(name)
+      @filter_group.key?(name)
+    end
+
     # This method is used to register a new filter
     def register_filter(name, group=nil, &block)
       raise "No block provided" unless block_given?
@@ -129,6 +134,12 @@ module ::Irc
       end
     end
 
+    # This method is used to retrieve the filter group names
+    def filter_groups
+      return [] unless defined? @filter_group
+      return @filter_group.keys
+    end
+
     # This method clears the filter list and installs the identity filter
     def clear_filters
       @filters ||= {}