4 # :title: filters management from IRC
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
7 # Copyright:: (C) 2008 Giuseppe Bilotta
10 class FiltersModule < CoreBotModule
15 @bot.register_filter(:htmlinfo) { |s| Utils.get_html_info(s.to_s, s) }
18 def help(plugin, topic="")
19 "filters list [<group>] => list filters (in group <group>) | filters search <pat> => list filters matching regexp <pat>"
22 def do_list(m, params)
24 ar = @bot.filter_names(g).map { |s| s.to_s }.sort!
27 msg = _("no filters in group %{g}") % {:g => g}
29 msg = _("no known filters")
32 msg = _("known filters: ") << ar.join(", ")
37 def do_listgroups(m, params)
38 ar = @bot.filter_groups.map { |s| s.to_s }.sort!
40 msg = _("no known filter groups")
42 msg = _("known filter groups: ") << ar.join(", ")
47 def do_search(m, params)
48 l = @bot.filter_names.map { |s| s.to_s }
49 pat = params[:pat].to_s
50 sl = l.grep(Regexp.new(pat))
52 msg = _("no filters match %{pat}") % { :pat => pat }
54 msg = _("filters matching %{pat}: ") % { :pat => pat }
55 msg << sl.sort!.join(", ")
62 plugin = FiltersModule.new
64 plugin.map "filters list [:group]", :action => :do_list
65 plugin.map "filters search *pat", :action => :do_search
66 plugin.map "filter groups", :action => :do_listgroups