From 102fab9a892f39bc77a92db37f6f77f77a7f0f2f Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 27 Jan 2009 21:46:11 +0100 Subject: wordlist: Wordlist.list command and UI Introduce an elementary Wordlist.list() command that accepts an optional :pattern option to restrict the list to wordlists matching the given pattern. Also introduce a wordlist UI to list wordlists from IRC. --- lib/rbot/core/utils/wordlist.rb | 15 ++++++++++++++- lib/rbot/core/wordlist_ui.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/rbot/core/wordlist_ui.rb (limited to 'lib') diff --git a/lib/rbot/core/utils/wordlist.rb b/lib/rbot/core/utils/wordlist.rb index 23e141ac..63cc99a7 100755 --- a/lib/rbot/core/utils/wordlist.rb +++ b/lib/rbot/core/utils/wordlist.rb @@ -39,6 +39,19 @@ class Wordlist word.empty? end end + + # Return an array with the list of available wordlists. + # Available options: + # pattern:: pattern that should be matched by the wordlist filename + def self.list(options={}) + pattern = options[:pattern] || "**" + # refuse patterns that contain ../ + return [] if pattern =~ /\.\.\// + striplen = self.wordlist_base.length+1 + Dir.glob(File.join(self.wordlist_base, pattern)).map { |name| + name[striplen..-1] + } + end +end end end -end \ No newline at end of file diff --git a/lib/rbot/core/wordlist_ui.rb b/lib/rbot/core/wordlist_ui.rb new file mode 100644 index 00000000..20ccc228 --- /dev/null +++ b/lib/rbot/core/wordlist_ui.rb @@ -0,0 +1,27 @@ +#-- vim:sw=2:et +#++ +# +# :title: wordlist management from IRC +# +# Author:: Giuseppe "Oblomov" Bilotta + +class WordlistModule < CoreBotModule + def help(plugin, topic="") + _("wordlist list [] => list wordlists (matching )") + end + + def do_list(m, p) + found = Wordlist.list(p) + if found.empty? + m.reply _("no wordlist found") + else + m.reply _("Wordlists: %{found}") % { + :found => found.sort.join(', ') + } + end + end +end + +plugin = WordlistModule.new + +plugin.map "wordlist list [:pattern]", :action => :do_list -- cgit v1.2.3