X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Futils%2Fwordlist.rb;h=339a3219383a934bf0db5003a26947d3893705c9;hb=56e4713c5c0498838ed77a409e44fbc3251acde2;hp=fc3415786ad0ddffc0052a354cd3902917a97339;hpb=3b294f9aa35c975b00c4f11d090526eb4ff9c34c;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/utils/wordlist.rb b/lib/rbot/core/utils/wordlist.rb old mode 100755 new mode 100644 index fc341578..339a3219 --- a/lib/rbot/core/utils/wordlist.rb +++ b/lib/rbot/core/utils/wordlist.rb @@ -10,14 +10,11 @@ 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={}) + def self.get(bot, where, options={}) + wordlist_base = bot.path('wordlists') opts = { :spaces => false }.merge(options) - wordlist_path = File.join(wordlist_base, path) + wordlist_path = File.join(wordlist_base, where) raise "wordlist not found: #{wordlist_path}" unless File.exist?(wordlist_path) # Location is a directory -> combine all lists beneath it @@ -44,21 +41,23 @@ class Wordlist # 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={}) + def self.list(bot, options={}) + wordlist_base = bot.path('wordlists') 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| + striplen = wordlist_base.length+1 + Dir.glob(File.join(wordlist_base, pattern)).map { |name| name[striplen..-1] } end - def self.exist?(path) + def self.exist?(bot, path) + wordlist_base = bot.path('wordlists') fn = path.to_s # refuse to check outside of the wordlist base directory return false if fn =~ /\.\.\// - File.exist?(File.join(self.wordlist_base, fn)) + File.exist?(File.join(wordlist_base, fn)) end end