From 0f3e302547363ea237454dda891ddb5de1be4476 Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Sat, 9 Oct 2004 01:51:05 +0000 Subject: initial import of rbot --- rbot/config.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 rbot/config.rb (limited to 'rbot/config.rb') diff --git a/rbot/config.rb b/rbot/config.rb new file mode 100644 index 00000000..52899205 --- /dev/null +++ b/rbot/config.rb @@ -0,0 +1,40 @@ +module Irc + + # container for bot configuration + # just treat it like a hash + class BotConfig < Hash + + # bot:: parent bot class + # create a new config hash from #{botclass}/conf.rbot + def initialize(bot) + super(false) + @bot = bot + # some defaults + self["SERVER"] = "localhost" + self["PORT"] = "6667" + self["NICK"] = "rbot" + self["USER"] = "gilbertt" + self["LANGUAGE"] = "english" + self["SAVE_EVERY"] = "60" + self["KEYWORD_LISTEN"] = false + if(File.exist?("#{@bot.botclass}/conf.rbot")) + IO.foreach("#{@bot.botclass}/conf.rbot") do |line| + next if(line =~ /^\s*#/) + if(line =~ /(\S+)\s+=\s+(.*)$/) + self[$1] = $2 if($2) + end + end + end + end + + # write current configuration to #{botclass}/conf.rbot + def save + Dir.mkdir("#{@bot.botclass}") if(!File.exist?("#{@bot.botclass}")) + File.open("#{@bot.botclass}/conf.rbot", "w") do |file| + self.each do |key, value| + file.puts "#{key} = #{value}" + end + end + end + end +end -- cgit v1.2.3