summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/rbot/core/utils/wordlist.rb15
-rw-r--r--lib/rbot/core/wordlist_ui.rb27
2 files changed, 41 insertions, 1 deletions
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 <giuseppe.bilotta@gmail.com>
+
+class WordlistModule < CoreBotModule
+ def help(plugin, topic="")
+ _("wordlist list [<pattern>] => list wordlists (matching <pattern>)")
+ 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