|
# File rbot/keywords.rb, line 118
def scan
# first scan for DBHash files, and load them
Dir["#{@bot.botclass}/keywords/*"].each {|f|
next unless f =~ /\.db$/
hsh = DBHash.new @bot, f, true
key = File.basename(f).gsub(/\.db$/, "")
debug "keywords module: loading DBHash file #{f}, key #{key}"
@statickeywords[key] = hsh
}
# then scan for non DBHash files, and convert/import them and delete
Dir["#{@bot.botclass}/keywords/*"].each {|f|
next if f =~ /\.db$/
puts "auto converting keywords from #{f}"
key = File.basename(f)
unless @statickeywords.has_key?(key)
@statickeywords[key] = DBHash.new @bot, "#{f}.db", true
end
IO.foreach(f) {|line|
if(line =~ /^(.*?)\s*<?=(is|are)?=?>\s*(.*)$/)
lhs = $1
mhs = $2
rhs = $3
# support infobot style factfiles, by fixing them up here
rhs.gsub!(/\$who/, "<who>")
mhs = "is" unless mhs
rhs = Keyword.escape rhs
values = rhs.split("<=or=>")
@statickeywords[key][lhs] = Keyword.new(mhs, values).dump
end
}
File.delete(f)
@statickeywords[key].flush
}
end
|