alias :value :get
def set(value, on_change = true)
@manager.config[@key] = value
+ @manager.changed = true
@on_change.call(@manager.bot, value) if on_change && @on_change
end
def unset
@manager.config.delete(@key)
+ @manager.changed = true
+ @on_change.call(@manager.bot, value) if @on_change
end
# set string will raise ArgumentErrors on failed parse/validate
attr_reader :bot
attr_reader :items
attr_reader :config
+ attr_accessor :changed
def initialize
bot_associate(nil,true)
@bot = bot
return unless @bot
+ @changed = false
if(File.exist?("#{@bot.botclass}/conf.yaml"))
begin
newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
# if we got here, we need to run the first-run wizard
BotConfigWizard.new(@bot).run
# save newly created config
+ @changed = true
save
end
# write current configuration to #{botclass}/conf.yaml
def save
+ if not @changed
+ debug "Not writing conf.yaml (unchanged)"
+ return
+ end
begin
debug "Writing new conf.yaml ..."
File.open("#{@bot.botclass}/conf.yaml.new", "w") do |file|
debug "Officializing conf.yaml ..."
File.rename("#{@bot.botclass}/conf.yaml.new",
"#{@bot.botclass}/conf.yaml")
+ @changed = false
rescue => e
error "failed to write configuration file conf.yaml! #{$!}"
error "#{e.class}: #{e}"