]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
more work on packaging, use Irc::Config module for storing configuration set
authorTom Gilbert <tom@linuxbrit.co.uk>
Wed, 27 Jul 2005 17:50:27 +0000 (17:50 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Wed, 27 Jul 2005 17:50:27 +0000 (17:50 +0000)
by install.rb

lib/rbot/config.rb
lib/rbot/ircbot.rb
lib/rbot/language.rb
lib/rbot/plugins.rb

index f021d8271c8545c82d39351aa10819f968e61044..a193e8c38e652025a904cbf42dd9c582cabe16a7 100644 (file)
@@ -143,7 +143,7 @@ module Irc
           :prompt => "Language",
           :key => "core.language",
           :type => :enum,
-          :items => Dir.new(@bot.datadir + "/languages").collect {|f|
+          :items => Dir.new(CONFIG::DATADIR + "/languages").collect {|f|
             f =~ /\.lang$/ ? f.gsub(/\.lang$/, "") : nil
           }.compact
         },
index 844231ddeddb19512467a2c1f0df7475f2e9f8fb..89746af36c547be40f3786807ba60cd584807fcb 100644 (file)
@@ -20,6 +20,8 @@
 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 require 'thread'
+require 'etc'
+require 'fileutils'
 
 require 'rbot/rfc2812'
 require 'rbot/keywords'
@@ -35,6 +37,7 @@ require 'rbot/language'
 require 'rbot/dbhash'
 require 'rbot/registry'
 require 'rbot/httputil'
+require 'rbot/rbotconfig'
 
 module Irc
 
@@ -77,12 +80,26 @@ class IrcBot
 
   # create a new IrcBot with botclass +botclass+
   def initialize(botclass)
+    unless Config::DATA_DIR && FileTest.directory? Config::DATA_DIR
+      puts "no data directory '#{Config::DATA_DIR}' found, did you run install.rb?"
+      exit 2
+    end
+    
+    botclass = "/home/#{Etc.getlogin}/.rbot" unless botclass
     @botclass = botclass.gsub(/\/$/, "")
-    @startup_time = Time.new
+
+    unless FileTest.directory? botclass
+      puts "no #{botclass} directory found, creating from templates.."
+      if FileTest.exist? botclass
+        puts "Error: file #{botclass} exists but isn't a directory"
+        exit 2
+      end
+      FileUtils.cp_r Config::DATA_DIR+'/templates', botclass
+    end
     
-    Dir.mkdir("#{botclass}") if(!File.exist?("#{botclass}"))
     Dir.mkdir("#{botclass}/logs") if(!File.exist?("#{botclass}/logs"))
 
+    @startup_time = Time.new
     @config = Irc::BotConfig.new(self)
     @timer = Timer::Timer.new
     @registry = BotRegistry.new self
index 75885a51def9a95fe58270ec2926202e3afe61aa..64555248d6b8c64a110d7462042faf884a8d22cd 100644 (file)
@@ -1,11 +1,10 @@
 module Irc
 
   class Language
-    def initialize(bot, language, file="")
-      @bot = bot
+    def initialize(language, file="")
       @language = language
       if file.empty?
-        file = bot.datadir + "/languages/#{@language}.lang"
+        file = Config::DATADIR + "/languages/#{@language}.lang"
       end
       unless(FileTest.exist?(file))
         raise "no such language: #{@language} (no such file #{file})"
index d239c5e6bfcd3626ac911e7f4ce6b3c164e7d4dc..9f88d0c3ea1bb4caa86c31037fd69c80329d5106 100644 (file)
@@ -170,7 +170,7 @@ module Irc
     # load plugins from pre-assigned list of directories
     def scan
       dirs = Array.new
-      dirs << @bot.datadir + "/plugins"
+      dirs << CONFIG::DATADIR + "/plugins"
       dirs += @dirs
       dirs.each {|dir|
         if(FileTest.directory?(dir))