]> git.donarmstrong.com Git - infobot.git/blobdiff - src/core.pl
removed feedback addressing. Issue raised by Flugh
[infobot.git] / src / core.pl
index b53e98144e7c6779d58d5c081361d0103f075639..42a1ca81e9d8e4e2136a73ba56c9751502fa5d60 100644 (file)
@@ -1,6 +1,6 @@
 #
 #   core.pl: Important functions stuff...
-#    Author: xk <xk@leguin.openprojects.net>
+#    Author: dms
 #   Version: v0.4 (20000718)
 #   Created: 20000322
 #
@@ -10,10 +10,10 @@ use strict;
 # dynamic scalar. MUST BE REDUCED IN SIZE!!!
 ### TODO: reorder.
 use vars qw(
-       $answer $correction_plausible $loggingstatus $talkchannel
-       $statcount $memusage $user $memusageOld $infobot_version $dbh
-       $shm $host $msg $infobot_misc_dir $infobot_pid $infobot_base_dir 
-       $infobot_src_dir $conn $irc $learnok $nick $ident $no_syscall
+       $answer $correction_plausible $talkchannel
+       $statcount $memusage $user $memusageOld $bot_version $dbh
+       $shm $host $msg $bot_misc_dir $bot_pid $bot_base_dir $noreply
+       $bot_src_dir $conn $irc $learnok $nick $ident $no_syscall
        $force_public_reply $addrchar $userHandle $addressedother
        $floodwho $chan $msgtime $server $firsttime $wingaterun
 );
@@ -35,6 +35,7 @@ $SIG{'KILL'} = 'doExit';  #  9. DOES NOT WORK. 'man perlipc' for details.
 $SIG{'TERM'} = 'doExit';  # 15.
 $SIG{'__WARN__'} = 'doWarn';
 
+# initialize variables.
 $last{buflen}  = 0;
 $last{say}     = "";
 $last{msg}     = "";
@@ -42,7 +43,10 @@ $userHandle  = "default";
 $msgtime       = time();
 $wingaterun    = time();
 $firsttime     = 1;
-$infobot_version = "blootbot 1.0.0 (20000725) -- $^O";
+
+### CHANGE TO STATIC.
+$bot_version = "blootbot 1.0.0 (20000725) -- $^O";
+$noreply        = "NOREPLY";
 
 ##########
 ### misc commands.
@@ -51,9 +55,9 @@ $infobot_version = "blootbot 1.0.0 (20000725) -- $^O";
 sub doExit {
     my ($sig) = @_;
 
-    if (!defined $infobot_pid) {       # independent.
+    if (!defined $bot_pid) {   # independent.
        exit 0;
-    } elsif ($infobot_pid == $$) {     # parent.
+    } elsif ($bot_pid == $$) { # parent.
        &status("parent caught SIG$sig (pid $$).") if (defined $sig);
 
        my $type;
@@ -66,6 +70,7 @@ sub doExit {
        &closeSHM($shm);
        &dumpallvars()  if (&IsParam("dumpvarsAtExit"));
        &closeLog();
+       &closeSQLDebug()        if (&IsParam("SQLDebug"));
     } else {                                   # child.
        &status("child caught SIG$sig (pid $$).");
     }
@@ -111,15 +116,22 @@ sub showProc {
        if (defined $memusageOld and &IsParam("DEBUG")) {
            # it's always going to be increase.
            my $delta = $memusage - $memusageOld;
-           if ($delta > 500) {
-               &status("MEM:$prefix increased by $delta kB. (total: $memusage kB)");
+           my $str;
+           if ($delta == 0) {
+               return;
+           } elsif ($delta > 500) {
+               $str = "MEM:$prefix increased by $delta kB. (total: $memusage kB)";
            } elsif ($delta > 0) {
-               &status("MEM:$prefix increased by $delta kB.");
-           } elsif ($delta < 0) {
+               $str = "MEM:$prefix increased by $delta kB";
+           } else {    # delta < 0.
                $delta = -$delta;
                # never knew RSS could decrease, probably Size can't?
-               &status("MEM:$prefix decreased by $delta kB. YES YES YES");
+               $str = "MEM:$prefix decreased by $delta kB. YES YES YES";
            }
+
+           &status($str);
+           &DCCBroadcast($str) if (&whatInterface() =~ /IRC/ &&
+               grep(/Irc.pl/, keys %moduleAge));
        }
        $memusageOld = $memusage;
     } else {
@@ -137,13 +149,14 @@ sub setup {
     &openLog();                # write, append.
 
     # read.
-    &loadIgnore($infobot_misc_dir."/infobot.ignore");
-    &loadLang($infobot_misc_dir."/infobot.lang");
-    &loadIRCServers($infobot_misc_dir."/ircII.servers");
-    &loadUsers($infobot_misc_dir."/infobot.users");
+    &loadIgnore($bot_misc_dir.         "/blootbot.ignore");
+    &loadLang($bot_misc_dir.           "/blootbot.lang");
+    &loadIRCServers($bot_misc_dir.     "/ircII.servers");
+    &loadUsers($bot_misc_dir.          "/blootbot.users");
 
     $shm = &openSHM();
-    &openDB();
+    &openSQLDebug()    if (&IsParam("SQLDebug"));
+    &openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'});
 
     &status("Setup: ". &countKeys("factoids") ." factoids.");
 
@@ -151,7 +164,8 @@ sub setup {
 }
 
 sub setupConfig {
-    &loadConfig($infobot_misc_dir."/infobot.config");
+    $param{'VERBOSITY'} = 1;
+    &loadConfig($bot_misc_dir."/blootbot.config");
 
     foreach ("ircNick", "ircUser", "ircName", "DBType") {
        next if &IsParam($_);
@@ -160,8 +174,8 @@ sub setupConfig {
     }
 
     # static scalar variables.
-    $file{utm} = "$infobot_base_dir/$param{'ircUser'}.uptime";
-    $file{PID} = "$infobot_base_dir/$param{'ircUser'}.pid";
+    $file{utm} = "$bot_base_dir/$param{'ircUser'}.uptime";
+    $file{PID} = "$bot_base_dir/$param{'ircUser'}.pid";
 }
 
 sub startup {
@@ -188,7 +202,7 @@ sub shutdown {
 sub restart {
     my ($sig) = @_;
 
-    if ($$ == $infobot_pid) {
+    if ($$ == $bot_pid) {
        &status("$sig called.");
 
        ### crappy bug in Net::IRC?
@@ -200,8 +214,8 @@ sub restart {
        }
 
        &shutdown();
-       &loadConfig($infobot_misc_dir."/infobot.config");
-       &reloadModules() if (&IsParam("DEBUG"));
+       &loadConfig($bot_misc_dir."/blootbot.config");
+       &reloadAllModules() if (&IsParam("DEBUG"));
        &setup();
 
        &status("End of $sig.");
@@ -216,8 +230,9 @@ sub loadConfig {
 
     if (!open(FILE, $file)) {
        &ERROR("FAILED loadConfig ($file): $!");
-       &status("Please make sure the configuration file exists.");
-       exit 1;
+       &status("Please copy files/sample.config to files/blootbot.config");
+       &status("  and edit files/blootbot.config, modify to tastes.");
+       exit 0;
     }
 
     my $count = 0;