scan
# import old format keywords into DBHash
- if(File.exist?("#{@bot.botclass}/keywords.rbot"))
+ olds = @bot.path 'keywords.rbot'
+ if File.exist? olds
log "auto importing old keywords.rbot"
- IO.foreach("#{@bot.botclass}/keywords.rbot") do |line|
+ IO.foreach(olds) do |line|
if(line =~ /^(.*?)\s*<=(is|are)?=?>\s*(.*)$/)
lhs = $1
mhs = $2
@keywords[lhs] = Keyword.new(mhs, values).dump
end
end
- File.rename("#{@bot.botclass}/keywords.rbot", "#{@bot.botclass}/keywords.rbot.old")
+ File.rename(olds, olds + ".old")
end
end
# have been added
def scan
# first scan for old DBHash files, and convert them
- Dir["#{@bot.botclass}/keywords/*"].each {|f|
+ Dir[datafile('*')].each {|f|
next unless f =~ /\.db$/
log "upgrading keyword db #{f} (rbot 0.9.5 or prior) database format"
newname = f.gsub(/\.db$/, ".kdb")
- old = BDB::Hash.open f, nil,
- "r+", 0600
- new = BDB::CIBtree.open(newname, nil,
- BDB::CREATE | BDB::EXCL,
- 0600)
+ old = BDB::Hash.open f, nil, "r+", 0600
+ new = BDB::CIBtree.open(newname, nil, BDB::CREATE | BDB::EXCL, 0600)
old.each {|k,v|
new[k] = v
}
}
# then scan for current DBTree files, and load them
- Dir["#{@bot.botclass}/keywords/*"].each {|f|
+ Dir[@bot.path('keywords', '*')].each {|f|
next unless f =~ /\.kdb$/
hsh = DBTree.new @bot, f, true
key = File.basename(f).gsub(/\.kdb$/, "")
}
# then scan for non DB files, and convert/import them and delete
- Dir["#{@bot.botclass}/keywords/*"].each {|f|
+ Dir[@bot.path('keywords', '*')].each {|f|
next if f =~ /\.kdb$/
next if f =~ /CVS$/
log "auto converting keywords from #{f}"
# upgrade data files found in old rbot formats to current
def upgrade_data
- if File.exist?("#{@bot.botclass}/keywords.db")
+ olds = @bot.path 'keywords.db'
+ if File.exist? olds
log "upgrading old keywords (rbot 0.9.5 or prior) database format"
- old = BDB::Hash.open "#{@bot.botclass}/keywords.db", nil,
- "r+", 0600
+ old = BDB::Hash.open olds, nil, "r+", 0600
old.each {|k,v|
@keywords[k] = v
}
old.close
@keywords.flush
- File.rename("#{@bot.botclass}/keywords.db", "#{@bot.botclass}/keywords.db.old")
+ File.rename(olds, olds + ".old")
end
- if File.exist?("#{@bot.botclass}/keyword.db")
+ olds.replace(@bot.path('keyword.db'))
+ if File.exist? olds
log "upgrading old keywords (rbot 0.9.9 or prior) database format"
- old = BDB::CIBtree.open "#{@bot.botclass}/keyword.db", nil,
- "r+", 0600
+ old = BDB::CIBtree.open olds, nil, "r+", 0600
old.each {|k,v|
@keywords[k] = v
}
old.close
@keywords.flush
- File.rename("#{@bot.botclass}/keyword.db", "#{@bot.botclass}/keyword.db.old")
+ File.rename(olds, olds + ".old")
end
end
end
def oldsave
- File.open("#{@bot.botclass}/keywords.rbot", "w") do |file|
+ File.open(@bot.path("keywords.rbot"), "w") do |file|
@keywords.each do |key, value|
file.puts "#{key}<=#{value.type}=>#{value.dump}"
end
case plugin
when /keyword/
case topic
+ when 'export'
+ 'keyword export => exports definitions to keyword_factoids.rbot'
+ when 'stats'
+ 'keyword stats => show statistics about static facts'
+ when 'wipe'
+ 'keyword wipe <keyword> => forgets everything about a keyword'
when 'lookup'
'keyword [lookup] <keyword> => look up the definition for a keyword; writing "lookup" is optional'
when 'set'
when '<topic>'
'<topic> => respond by setting the topic to the rest of the definition'
else
- 'keyword module (fact learning and regurgitation) topics: lookup, set, forget, tell, search, listen, address, <reply>, <action>, <who>, <topic>'
+ 'keyword module (fact learning and regurgitation) topics: lookup, set, forget, tell, search, listen, address, stats, export, wipe, <reply>, <action>, <who>, <topic>'
end
when "forget"
'forget <keyword> => forget a keyword'
# TODO check factoids config
# also TODO: runtime export
- dir = File.join(@bot.botclass,"factoids")
+ dir = @bot.path 'factoids'
fname = File.join(dir,"keyword_factoids.rbot")
Dir.mkdir(dir) unless FileTest.directory?(dir)