]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/utils/filters.rb
filters: UI and methods to list filter groups
[user/henk/code/ruby/rbot.git] / lib / rbot / core / utils / filters.rb
index 4a831497c211c68d06119b2dd76487f254057928..6d560c9150df8d23cd8d4b7f8d068e825cd77e07 100644 (file)
@@ -64,22 +64,16 @@ module ::Irc
     #
     def filter(*args)
       @filters ||= {}
-      case args.last
-      when DataStream
-        # the stream is an actual DataStream
-        ds = args.pop
-      when String
-        # the stream is just plain text
-        ds = DataStream.new(args.pop)
-      when Hash
-        # the stream is a Hash, check if the previous element is a String
-        if String === args[-2]
-          ds = DataStream.new(*args.slice!(-2, 2))
-        else
+      if Hash === args.last
+        # the stream is a Hash, check if the previous element is not a Symbol
+        if Symbol === args[-2]
           ds = DataStream.new(args.pop)
+        else
+          ds = DataStream.new(*args.slice!(-2, 2))
         end
       else
-        raise "Unknown DataStream class #{args.last.class}"
+        # the stream is just whatever else
+        ds = DataStream.new(args.pop)
       end
       names = args.dup
       return ds if names.empty?
@@ -102,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?
@@ -135,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 ||= {}