]> git.donarmstrong.com Git - infobot.git/blobdiff - infobot
dunno
[infobot.git] / infobot
diff --git a/infobot b/infobot
index 419c3487976055a371bbef63e03bfe02f8a1843c..ffc3911387e33b9bd2554d97e8704b0e9257091d 100755 (executable)
--- a/infobot
+++ b/infobot
@@ -1,31 +1,44 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 
-# infobot  -- copyright kevin lenzo (c) 1997-1999
-# blootbot -- copyright david sobon (c) 1999-infinity
+# infobot
+# copyright kevin lenzo (c) 1997-1999
+# copyright david sobon (c) 1999-infinity
+# Copyright (c) 2001-2014 Tim Riker <Tim@Rikers.org>
 
 use strict;
 use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir
-           $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
-           $bot_pid $memusage %param
+  $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
+  $bot_pid $memusage %param
 );
 
+# ancient Perl may not like these, but modern systems should have this
+use open ':utf8';
+use open ':std';
+use Encode qw( decode FB_QUIET );
+
 BEGIN {
-    if (@ARGV and -f $ARGV[0]) {
-       # source passed config to allow $bot_*_dir to be set.
-       do $ARGV[0];
+    if ( @ARGV and -f $ARGV[0] ) {
+
+        # source passed config to allow $bot_*_dir to be set.
+        do $ARGV[0];
     }
 
     # set any $bot_*_dir var's that aren't already set
-    $bot_base_dir      ||= '.';
-    $bot_config_dir    ||= 'files/';
-    $bot_data_dir      ||= 'files/';
-    $bot_state_dir     ||= 'files/';
-    $bot_run_dir       ||= '.';
-    $bot_src_dir       ||= "$bot_base_dir/src";
-    $bot_log_dir       ||= "$bot_base_dir/log";
+    $bot_base_dir      ||= `pwd`;
+    chomp($bot_base_dir);
+    $bot_config_dir    ||= "$bot_base_dir/files/";
+    $bot_data_dir      ||= "$bot_base_dir/files/";
+    $bot_state_dir     ||= "$bot_base_dir/files/";
+    $bot_run_dir           ||= "$bot_base_dir";
+    $bot_src_dir    ||= "$bot_base_dir/src";
+    $bot_log_dir    ||= "$bot_base_dir/log";
     $bot_misc_dir      ||= "$bot_base_dir/files";
 
-    $bot_pid           = $$;
+    $bot_pid = $$;
+
+    $bot_base_dir = $bot_state_dir;
+
+       unshift @INC,"$bot_src_dir","$bot_src_dir/Modules";
 
     require "$bot_src_dir/logger.pl";
     require "$bot_src_dir/core.pl";
@@ -34,7 +47,7 @@ BEGIN {
     # load the configuration (params) file.
     &setupConfig();
 
-    &showProc();       # to get the first value.
+    &showProc();    # to get the first value.
     &status("Initial memory usage: $memusage kB");
     &loadCoreModules();
     &loadDBModules();
@@ -48,17 +61,19 @@ BEGIN {
 &duperuncheck();
 
 # initialize everything
-&startup();    # first time initialization.
+&startup();    # first time initialization.
 &setup();
 
-if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
+if ( !&IsParam("Interface") or $param{'Interface'} =~ /IRC/ ) {
+
     # launch the irc event loop
     &ircloop();
-} else {
+}
+else {
     &cliloop();
 }
 
-exit 0;  # just so you don't look farther down in this file :)
+exit 0;        # just so you don't look farther down in this file :)
 
 # --- support routines
 
@@ -66,30 +81,32 @@ exit 0;  # just so you don't look farther down in this file :)
 
 # added by the xk
 sub duperuncheck {
-    my $pid    = $$;
-    my $file   = $file{PID};
-
-    if ( -f $file) {
-       open(PIDFILE,$file) or die "error: cannot open $file.";
-       my $thispid = <PIDFILE> || "NULL\n";
-       close PIDFILE;
-       chop $thispid;
-
-       if ($thispid =~ /^\D$/) {
-           &staus("warning: pidfile is invalid; wiping out.");
-       } else {
-           if ( -d "/proc/$thispid/") {
-               &ERROR("bot is already running from this directory.");
-               &ERROR("if this is incorrect, erase '*.pid'.");
-               &ERROR("verify with 'ps -axu | grep $thispid'.");
-               exit 1;
-           } else {
-               &status("warning: stale $file found; wiping.");
-           }
-       }
+    my $pid  = $$;
+    my $file = $file{PID};
+
+    if ( -f $file ) {
+        open( PIDFILE, $file ) or die "error: cannot open $file.";
+        my $thispid = <PIDFILE> || "NULL\n";
+        close PIDFILE;
+        chop $thispid;
+
+        if ( $thispid =~ /^\D$/ ) {
+            &staus("warning: pidfile is invalid; wiping out.");
+        }
+        else {
+            if ( -d "/proc/$thispid/" ) {
+                &ERROR("bot is already running from this directory.");
+                &ERROR("if this is incorrect, erase '*.pid'.");
+                &ERROR("verify with 'ps -axu | grep $thispid'.");
+                exit 1;
+            }
+            else {
+                &status("warning: stale $file found; wiping.");
+            }
+        }
     }
 
-    open(PIDFILE,">$file") or die "error: cannot write to $file.";
+    open( PIDFILE, ">$file" ) or die "error: cannot write to $file.";
     print PIDFILE "$pid\n";
     close PIDFILE;
 
@@ -97,5 +114,3 @@ sub duperuncheck {
 }
 
 1;
-
-# vim:ts=4:sw=4:expandtab:tw=80