summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-03-14 01:13:20 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-03-14 01:13:20 +0100
commitd61de70f15e57f20b99cd4993ded2fd802997d0b (patch)
treec774d2b79be3abfd00972fa98d990d18097b9a8b /lib
parent92b0ee34a4934592d0bb5f62a4cdfa57952b9ede (diff)
filters: filters_ui core module to manage filters from IRC
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/filters_ui.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/rbot/core/filters_ui.rb b/lib/rbot/core/filters_ui.rb
new file mode 100644
index 00000000..f4f0719e
--- /dev/null
+++ b/lib/rbot/core/filters_ui.rb
@@ -0,0 +1,54 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: filters management from IRC
+#
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
+# Copyright:: (C) 2008 Giuseppe Bilotta
+# License:: GPL v2
+
+class FiltersModule < CoreBotModule
+
+ def initialize
+ super
+ @bot.clear_filters
+ end
+
+ def help(plugin, topic="")
+ "filters list [<group>] => list filters (in group <group>) | filters search <pat> => list filters matching regexp <pat>"
+ end
+
+ def do_list(m, params)
+ g = params[:group]
+ ar = @bot.filter_names(g).map { |s| s.to_s }.sort!
+ if ar.empty?
+ if g
+ msg = _("no filters in group %{g}") % {:g => g}
+ else
+ msg = _("no known filters")
+ end
+ else
+ msg = _("known filters: ") << 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
+ sl = l.grep(Regexp.new(pat))
+ if sl.empty?
+ msg = _("no filters match %{pat}") % { :pat => pat }
+ else
+ msg = _("filters matching %{pat}: ") % { :pat => pat }
+ msg << sl.sort!.join(", ")
+ end
+ m.reply msg
+ end
+
+end
+
+plugin = FiltersModule.new
+
+plugin.map "filters list [:group]", :action => :do_list
+plugin.map "filters search *pat", :action => :do_search