diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-03-13 22:54:05 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-03-13 23:49:14 +0100 |
commit | d6998e9b33f57c66d8026ba6b07054cf0b6a7003 (patch) | |
tree | c443291c2d28637a63bd0d63e707798ddfed063f /lib | |
parent | defb429a1e8edcef13f54486490770eebae80468 (diff) |
filters: BotModule user filter loading
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/core/utils/filters.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/filters.rb b/lib/rbot/core/utils/filters.rb index bf8ac580..463e6f38 100644 --- a/lib/rbot/core/utils/filters.rb +++ b/lib/rbot/core/utils/filters.rb @@ -148,6 +148,53 @@ module ::Irc register_filter(:identity) { |stream| stream } end + + module Plugins + class BotModule + # read accessor for the default filter group for this BotModule + def filter_group + @filter_group ||= name + end + + # write accessor for the default filter group for this BotModule + def filter_group=(name) + @filter_group = name + end + + # define a filter defaulting to the default filter group + # for this BotModule + def define_filter(filter, &block) + @bot.register_filter(filter, self.filter_group, &block) + end + + # load filters associated with the BotModule by looking in + # the path(s) specified by the :path option, defaulting to + # * Config::datadir/filters/<name>.rb + # * botclass/filters/<name>.rb + # (note that as <name> we use #dirname() rather than #name(), + # since we're looking for datafiles; this is only relevant + # for the very few plugins whose dirname differs from name) + def load_filters(options={}) + case options[:path] + when nil + file = "#{self.dirname}.rb" + paths = [ + File.join(Config::datadir, 'filters', file), + @bot.path('filters', file) + ] + when Array + paths = options[:path] + else + paths = [options[:path]] + end + + paths.each do |file| + instance_eval(File.read(file), file) if File.exist?(file) + end + end + end + end + end end |