]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - rbot/config.rb
initial import of rbot
[user/henk/code/ruby/rbot.git] / rbot / config.rb
1 module Irc
2
3   # container for bot configuration
4   # just treat it like a hash
5   class BotConfig < Hash
6
7     # bot:: parent bot class
8     # create a new config hash from #{botclass}/conf.rbot
9     def initialize(bot)
10       super(false)
11       @bot = bot
12       # some defaults
13       self["SERVER"] = "localhost"
14       self["PORT"] = "6667"
15       self["NICK"] = "rbot"
16       self["USER"] = "gilbertt"
17       self["LANGUAGE"] = "english"
18       self["SAVE_EVERY"] = "60"
19       self["KEYWORD_LISTEN"] = false
20       if(File.exist?("#{@bot.botclass}/conf.rbot"))
21         IO.foreach("#{@bot.botclass}/conf.rbot") do |line|
22           next if(line =~ /^\s*#/)
23           if(line =~ /(\S+)\s+=\s+(.*)$/)
24             self[$1] = $2 if($2)
25           end
26         end
27       end
28     end
29
30     # write current configuration to #{botclass}/conf.rbot
31     def save
32       Dir.mkdir("#{@bot.botclass}") if(!File.exist?("#{@bot.botclass}"))
33       File.open("#{@bot.botclass}/conf.rbot", "w") do |file|
34         self.each do |key, value|
35           file.puts "#{key} = #{value}"
36         end
37       end
38     end
39   end
40 end