summaryrefslogtreecommitdiff
path: root/lib/rbot/core/utils/wordlist.rb
diff options
context:
space:
mode:
authorMatthias Hecker <mail@apoc.cc>2020-04-15 20:26:54 +0200
committerMatthias Hecker <mail@apoc.cc>2020-04-15 20:26:54 +0200
commitff6d7e5d043da99b2da36f628d52b7b5df47119d (patch)
treefe513113e54536ff32cdd6ad66faf0e0a020792c /lib/rbot/core/utils/wordlist.rb
parent77540358a94db4c1fe21462c5f821692eb140df7 (diff)
refactor: wordlist shouldn't use bot singleton #35
also related to #41 and #6
Diffstat (limited to 'lib/rbot/core/utils/wordlist.rb')
-rw-r--r--[-rwxr-xr-x]lib/rbot/core/utils/wordlist.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/rbot/core/utils/wordlist.rb b/lib/rbot/core/utils/wordlist.rb
index 81d7d775..339a3219 100755..100644
--- a/lib/rbot/core/utils/wordlist.rb
+++ b/lib/rbot/core/utils/wordlist.rb
@@ -10,11 +10,8 @@ require "find"
module ::Irc
class Bot
class Wordlist
- def self.wordlist_base
- @@wordlist_base ||= Utils.bot.path 'wordlists'
- end
-
- def self.get(where, options={})
+ def self.get(bot, where, options={})
+ wordlist_base = bot.path('wordlists')
opts = { :spaces => false }.merge(options)
wordlist_path = File.join(wordlist_base, where)
@@ -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