]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/ircbot.rb
patch from Alexey Froloff to use homedir from /etc/passwd (oops!) instead of
[user/henk/code/ruby/rbot.git] / lib / rbot / ircbot.rb
index 24ee6de3f6cf407bbb31108b6fe9995cb8ed9c6f..29d4711d974246fc50eff205286d7997cce6def3 100644 (file)
@@ -120,7 +120,7 @@ class IrcBot
       exit 2
     end
     
-    botclass = "/home/#{Etc.getlogin}/.rbot" unless botclass
+    botclass = "#{Etc.getpwnam(Etc.getlogin).dir}/.rbot" unless botclass
     @botclass = botclass.gsub(/\/$/, "")
 
     unless FileTest.directory? botclass
@@ -136,6 +136,7 @@ class IrcBot
 
     @startup_time = Time.new
     @config = BotConfig.new(self)
+# TODO background self after botconfig has a chance to run wizard
     @timer = Timer::Timer.new(1.0) # only need per-second granularity
     @registry = BotRegistry.new self
     @timer.add(@config['core.save_every']) { save } if @config['core.save_every']
@@ -152,11 +153,6 @@ class IrcBot
 
     @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'])
     @nick = @config['irc.nick']
-    if @config['core.address_prefix']
-      @addressing_prefixes = @config['core.address_prefix'].split(" ")
-    else
-      @addressing_prefixes = Array.new
-    end
     
     @client = IrcClient.new
     @client[:privmsg] = proc { |data|
@@ -463,8 +459,9 @@ class IrcBot
   end
 
   # totally shutdown and respawn the bot
-  def restart
-    shutdown("restarting, back in #{@config['server.reconnect_wait']}...")
+  def restart(message = false)
+    msg = message ? message : "restarting, back in #{@config['server.reconnect_wait']}..."
+    shutdown(msg)
     sleep @config['server.reconnect_wait']
     # now we re-exec
     exec($0, *@argv)
@@ -635,8 +632,8 @@ class IrcBot
           part $1 if(@auth.allow?("join", m.source, m.replyto))
         when (/^quit(?:\s+(.*))?$/i)
           quit $1 if(@auth.allow?("quit", m.source, m.replyto))
-        when (/^restart$/i)
-          restart if(@auth.allow?("quit", m.source, m.replyto))
+        when (/^restart(?:\s+(.*))?$/i)
+          restart $1 if(@auth.allow?("quit", m.source, m.replyto))
         when (/^hide$/i)
           join 0 if(@auth.allow?("join", m.source, m.replyto))
         when (/^save$/i)
@@ -710,7 +707,7 @@ class IrcBot
     else
       # stuff to handle when not addressed
       case m.message
-        when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$))[\s,-.]+#{@nick}$/i)
+        when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{@nick}$/i)
           say m.replyto, @lang.get("hello_X") % m.sourcenick
         when (/^#{@nick}!*$/)
           say m.replyto, @lang.get("hello_X") % m.sourcenick