summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-01-27 21:46:11 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-01-27 21:47:50 +0100
commit102fab9a892f39bc77a92db37f6f77f77a7f0f2f (patch)
tree41cfb811c52fe40de33acd7756c75f3c89392369 /lib/rbot
parent106501b21d8dd11ae976d646c0dcc0bc856a392c (diff)
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.
Diffstat (limited to 'lib/rbot')
-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