summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-01-26 05:06:00 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-01-27 03:29:23 +0100
commit0bf6eabdddddafecc42d56eaae1e0db35413390f (patch)
treee1942675795c17082bb8be439af9c8ef091db9b8 /lib/rbot
parent0203a872d0f167c5905fc445d173f19efdd73842 (diff)
wordlist provider
Diffstat (limited to 'lib/rbot')
-rwxr-xr-xlib/rbot/core/utils/wordlist.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/wordlist.rb b/lib/rbot/core/utils/wordlist.rb
new file mode 100755
index 00000000..23e141ac
--- /dev/null
+++ b/lib/rbot/core/utils/wordlist.rb
@@ -0,0 +1,44 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: rbot wordlist provider
+#
+# Author:: Raine Virta <rane@kapsi.fi>
+
+require "find"
+
+module ::Irc
+class Bot
+class Wordlist
+ def self.wordlist_base
+ @@wordlist_base ||= File.join(Utils.bot.botclass, 'wordlists')
+ end
+
+ def self.get(path, options={})
+ opts = { :spaces => false }.merge(options)
+
+ wordlist_path = File.join(wordlist_base, path)
+ raise "wordlist not found: #{wordlist_path}" unless File.exist?(wordlist_path)
+
+ # Location is a directory -> combine all lists beneath it
+ wordlist = if File.directory?(wordlist_path)
+ wordlists = []
+ Find.find(wordlist_path) do |path|
+ next if path == wordlist_path
+ wordlists << path unless File.directory?(path)
+ end
+
+ wordlists.map { |list| File.readlines(list) }.flatten
+ else
+ File.readlines(wordlist_path)
+ end
+
+ wordlist.map! { |l| l.strip }
+ wordlist.reject do |word|
+ word =~ /\s/ && !opts[:spaces] ||
+ word.empty?
+ end
+ end
+end
+end
+end \ No newline at end of file