From 0bf6eabdddddafecc42d56eaae1e0db35413390f Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Mon, 26 Jan 2009 05:06:00 +0200 Subject: wordlist provider --- lib/rbot/core/utils/wordlist.rb | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 lib/rbot/core/utils/wordlist.rb (limited to 'lib') 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 + +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 -- cgit v1.2.3