]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Process.pl
final cruft from old static configuration file fixed... found by irq
[infobot.git] / src / Process.pl
index 08dcc579019f7fe7375eb2326b9b52dfab76595d..93a3a32d25782417a8cf60d57bb1e79f138cac7c 100644 (file)
@@ -50,7 +50,7 @@ sub process {
 
        $2 =~ /^($mask{chan})(,(\S+))?/;
        my($thischan, $key) = (lc $1, $3);
-       my $chankey     = $thischan;
+       my $chankey     = lc $thischan;
        $chankey        .= " $key"      if (defined $key);
 
        if ($thischan eq "") {
@@ -58,18 +58,16 @@ sub process {
            return;
        }
 
-       # Thanks to Eden Li (tile) for the channel key patch
-       my @chans = split(/[\s\t]+/, $param{'join_channels'});
-       if (!grep /^$thischan$/i, @chans) {
-           if (&IsFlag("o") ne "o") {
+       if (&IsFlag("o") ne "o") {
+           if (!exists $chanconf{$thischan}) {
                &msg($who, "I am not allowed to join $thischan.");
                return;
            }
-       }
 
-       if (&validChan($thischan)) {
-           &msg($who,"I'm already on $thischan...");
-           return;
+           if (&validChan($thischan)) {
+               &msg($who,"I'm already on $thischan...");
+               return;
+           }
        }
        $joinverb{$thischan} = $who;    # used for on_join self.
 
@@ -80,6 +78,48 @@ sub process {
        return;
     }
 
+    # 'identify'
+    if ($msgType =~ /private/ and $message =~ s/^identify//) {
+       $message =~ s/^\s+|\s+$//g;
+       my @array = split / /, $message;
+
+       if ($who =~ /^_default$/i) {
+           &pSReply("you are too eleet.");
+           return;
+       }
+
+       if (!scalar @array or scalar @array > 2) {
+           &help("identify");
+           return;
+       }
+
+       my $do_nick = $array[1] || $who;
+
+       if (!exists $users{$do_nick}) {
+           &pSReply("nick $do_nick is not in user list.");
+           return;
+       }
+
+       my $crypt = $users{$do_nick}{PASS};
+       if (!defined $crypt) {
+           &pSReply("user $do_nick has no passwd set.");
+           return;
+       }
+
+       if (!&ckpasswd($array[0], $crypt)) {
+           &pSReply("invalid passwd for $do_nick.");
+           return;
+       }
+
+       my $mask = "*!$user@".&makeHostMask($host);
+       ### TODO: prevent adding multiple dupe masks?
+       ### TODO: make &addHostMask() CMD?
+       &pSReply("Added $mask for $do_nick...");
+       $users{$do_nick}{HOSTS}{$mask} = 1;
+
+       return;
+    }
+
     # allowOutsiders.
     if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
        my $found = 0;
@@ -98,7 +138,14 @@ sub process {
     }
 
     # User Processing, for all users.
-    return '$noreply from userC' if &userCommands() eq $noreply;
+    if ($addressed) {
+       my $retval;
+       return 'returned from pCH'   if &parseCmdHook("main",$message);
+
+       $retval = &userCommands();
+       return unless (defined $retval);
+       return if ($retval eq $noreply);
+    }
 
     ###
     # once useless messages have been parsed out, we match them.
@@ -156,7 +203,6 @@ sub process {
 
     # thanks.
     if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
-       &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
        return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
 
        &performReply( &getRandom(keys %{$lang{'welcome'}}) );
@@ -207,10 +253,12 @@ sub process {
     # here's where the external routines get called.
     # if they return anything but null, that's the "answer".
     if ($addressed) {
-       &parseCmdHook();
+       if ( &parseCmdHook("extra",$message) ) {
+           return 'DID SOMETHING IN PCH.';
+       }
+
        my $er = &Modules();
-       if ($er =~ /\S/) {
-           &performStrictReply($er) if ($er ne $noreply);
+       if (!defined $er) {
            return 'SOMETHING 1';
        }
 
@@ -300,8 +348,17 @@ sub FactoidStuff {
 
            return 'locked factoid' if (&IsLocked($faqtoid) == 1);
 
-           &status("forget: <$who> '$faqtoid' =is=> '$result'");
-           &delFactoid($faqtoid);
+           if (&IsParam("factoidDeleteDelay")) {
+               &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
+               &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
+
+               ### delete info. modified_ isn't really used.
+               &setFactInfo($faqtoid, "modified_by", $who);
+               &setFactInfo($faqtoid, "modified_time", time());
+           } else {
+               &status("forget: <$who> '$faqtoid' =is=> '$result'");
+               &delFactoid($faqtoid);
+           }
 
            &performReply("i forgot $faqtoid");
 
@@ -313,6 +370,48 @@ sub FactoidStuff {
        return;
     }
 
+    # factoid unforget/undelete.
+    if ($message =~ s/^un(forget|delete)\s+//i) {
+       return 'unforget: no addr' unless ($addressed);
+
+       if (!&IsParam("factoidDeleteDelay")) {
+           &performReply("safe delete has been disable so what is there to undelete?");
+           return;
+       }
+
+       my $faqtoid = $message;
+       if ($faqtoid eq "") {
+           &help("undelete");
+           return;
+       }
+
+       $faqtoid =~ tr/A-Z/a-z/;
+       my $result = &getFactoid($faqtoid." #DEL#");
+       my $check  = &getFactoid($faqtoid);
+
+       if (!defined $result) {
+           &performReply("i didn't have anything ('$faqtoid') to undelete.");
+           return;
+       }
+
+       if (defined $check) {
+           &performReply("cannot undeleted '$faqtoid' because it already exists?");
+           return;
+       }
+
+       &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
+
+       ### delete info. modified_ isn't really used.
+       &setFactInfo($faqtoid, "modified_by",  "");
+       &setFactInfo($faqtoid, "modified_time", 0);
+
+       &performReply("Successfully recovered '$faqtoid'.  Have fun now.");
+
+       $count{'Undelete'}++;
+
+       return;
+    }
+
     # factoid locking.
     if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
        return 'lock: no addr 2' unless ($addressed);
@@ -363,7 +462,7 @@ sub FactoidStuff {
                my $author = &getFactInfo($from, "created_by");
                if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
                    &msg($who, "It's not yours to modify.");
-                   return $noreply;
+                   return;
                }
 
                if ($_ = &getFactoid($to)) {
@@ -454,13 +553,14 @@ sub FactoidStuff {
     }
 
     my $result = &doQuestion($message);
+    if (!defined $result or $result eq $noreply) {
+       return 'result from doQ undef.';
+    }
 
-    return 'result is $noreply' if ($result eq $noreply);
-
-    if (defined $result and $result ne "") {           # question.
+    if (defined $result and $result !~ /^0?$/) {       # question.
        &status("question: <$who> $message");
        $count{'Question'}++;
-    } elsif (&IsParam("perlMath") and $addressed) {    # perl math.
+    } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
        &loadMyModule("perlMath");
        my $newresult = &perlMath();
 
@@ -470,26 +570,33 @@ sub FactoidStuff {
        }
     }
 
-    if ($result ne "") {
+    if ($result !~ /^0?$/) {
        &performStrictReply($result);
        return;
-    } else {
-       # why would a friendly bot get passed here?
-       if (&IsParam("friendlyBots")) {
-           return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
-       }
+    }
 
-       # do the statement.
-       if ($_ = &doStatement($message)) {
-           return;
-       }
+    # why would a friendly bot get passed here?
+    if (&IsParam("friendlyBots")) {
+       return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
+    }
 
-       if ($addressed) {
-           &status("unparseable: $message");
-           &performReply( &getRandom(keys %{$lang{'dunno'}}) );
-           $count{'Dunno'}++;
-       }
+    # do the statement.
+    if (!defined &doStatement($message)) {
+       return;
     }
+
+    return unless ($addressed);
+
+    if (length $message > 64) {
+       &status("unparseable-moron: $message");
+       &performReply( &getRandom(keys %{$lang{'moron'}}) );
+       $count{'Moron'}++;
+       return;
+    }
+
+    &status("unparseable: $message");
+    &performReply( &getRandom(keys %{$lang{'dunno'}}) );
+    $count{'Dunno'}++;
 }
 
 1;