summaryrefslogtreecommitdiff
path: root/rbot/config.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2004-10-09 01:51:05 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2004-10-09 01:51:05 +0000
commit0f3e302547363ea237454dda891ddb5de1be4476 (patch)
treeec45be24a669ee28b5e2da4ff65e39265a418e0b /rbot/config.rb
initial import of rbot
Diffstat (limited to 'rbot/config.rb')
-rw-r--r--rbot/config.rb40
1 files changed, 40 insertions, 0 deletions
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