Class: Irc::Bot::Wordlist
- Inherits:
-
Object
- Object
- Irc::Bot::Wordlist
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/core/utils/wordlist.rb
Class Method Summary (collapse)
- + (Boolean) exist?(path)
- + (Object) get(where, options = {})
-
+ (Object) list(options = {})
Return an array with the list of available wordlists.
- + (Object) wordlist_base
Class Method Details
+ (Boolean) exist?(path)
57 58 59 60 61 62 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/utils/wordlist.rb', line 57 def self.exist?(path) 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)) end |
+ (Object) get(where, options = {})
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/utils/wordlist.rb', line 17 def self.get(where, ={}) opts = { :spaces => false }.merge() 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 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 # wordlists are assumed to be UTF-8, but we need to strip the BOM, if present wordlist.map! { |l| l.sub("\xef\xbb\xbf",'').strip } wordlist.reject do |word| word =~ /\s/ && !opts[:spaces] || word.empty? end end |
+ (Object) list(options = {})
Return an array with the list of available wordlists. Available options:
- pattern
-
pattern that should be matched by the wordlist filename
47 48 49 50 51 52 53 54 55 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/utils/wordlist.rb', line 47 def self.list(={}) pattern = [: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 |
+ (Object) wordlist_base
13 14 15 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/utils/wordlist.rb', line 13 def self.wordlist_base @@wordlist_base ||= Utils.bot.path 'wordlists' end |