diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-14 00:26:30 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-14 00:26:30 +0100 |
commit | 61b99d005b86ecd1abe7eb08e698141a07b85a9f (patch) | |
tree | c348c3c86fb56f5f937ff0c6144d0a4b079eb0ce | |
parent | e7c109b7f575d4c9e14ce1b523697a943320d7bd (diff) |
filters: filter groups
-rw-r--r-- | lib/rbot/core/utils/filters.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/rbot/core/utils/filters.rb b/lib/rbot/core/utils/filters.rb index 6a4434cc..7535ff42 100644 --- a/lib/rbot/core/utils/filters.rb +++ b/lib/rbot/core/utils/filters.rb @@ -91,16 +91,34 @@ module ::Irc end # This method is used to register a new filter - def register_filter(name, &block) + def register_filter(name, group=nil, &block) raise "No block provided" unless block_given? @filters ||= {} - @filters[name.to_sym] = DataFilter.new &block + tlkey = ( group ? "#{group}.#{name}" : name.to_s ).intern + key = name.to_sym + if @filters.key?(tlkey) + debug "Overwriting filter #{tlkey}" + end + @filters[tlkey] = DataFilter.new &block + if group + gkey = group.to_sym + @filter_group ||= {} + @filter_group[gkey] ||= {} + if @filter_group[gkey].key?(key) + debug "Overwriting filter #{key} in group #{gkey}" + end + @filter_group[gkey][key] = @filters[tlkey] + end end # This method clears the filter list and installs the identity filter def clear_filters @filters ||= {} @filters.clear + + @filter_group ||= {} + @filter_group.clear + register_filter(:identity) { |stream| stream } end end |