]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
pipes in nicks
[infobot.git] / src / Factoids / Question.pl
index 5a0ddb299c5d7ddd62ca16fb7c1939f0e7d03d25..c269117a7f423228a0a9069a9f5761729698ce84 100644 (file)
@@ -33,8 +33,8 @@ sub doQuestion {
 
     if (!$addressed) {
        return '' unless ($finalQMark);
-       return '' if (&IsParam("minVolunteerLength") == 0);
-       return '' if (length $query < $param{'minVolunteerLength'});
+       return '' unless &IsChanConf("minVolunteerLength");
+       return '' if (length $query < &::getChanConf('minVolunteerLength'));
     } else {
        ### TODO: this should be caught in Process.pl?
        return '' unless ($talkok);
@@ -126,6 +126,18 @@ sub doQuestion {
 
            push(@link, $link);
            my $newr = &getReply($link);
+
+           # no such factoid. try commands
+           if (!defined $newr || $newr =~ /^0?$/) {
+               # support command redirection.
+               # recursive cmdHooks aswell :)
+               my $done = 0;
+               $done++ if &parseCmdHook($link);
+               $message        = $link;
+               $done++ unless (&Modules());
+
+               return;
+           }
            last if (!defined $newr or $newr eq "");
            $result  = $newr;
        }
@@ -141,16 +153,9 @@ sub doQuestion {
        return $result;
     }
 
-    ### TODO: Use &Forker(); move function to Freshmeat.pl.
-    if (&IsChanConf("freshmeatForFactoid")) {
-       &loadMyModule($myModules{'freshmeat'});
-       $result = &Freshmeat::showPackage($query);
-       return $result if (defined $result);
-    }
-
     ### TODO: Use &Forker(); move function to Debian.pl
-    if (&IsChanConf("debianForFactoid")) {
-       &loadMyModule($myModules{'debian'});
+    if (&IsChanConf('debianForFactoid')) {
+       &loadMyModule('Debian');
        $result = &Debian::DebianFind($query);  # ???
        ### TODO: debian module should tell, through shm, that it went
        ###       ok or not.
@@ -180,9 +185,13 @@ sub factoidArgs {
 
     # to make it eleeter, split each arg and use "blah OR blah or BLAH"
     # which will make it less than linear => quicker!
-    # todo: cache this, update cache when altered. !!! !!! !!!
+    # TODO: cache this, update cache when altered. !!! !!! !!!
 #    my $t = &timeget();
-    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: ");
+    my ($first) = split(/\s+/, $str);
+
+    # ignore split to commands [dumb commands vs. factoids] (editing commands?)
+    return undef if $str =~ /\s+\=\~\s+s[\#\/\:]/;
+    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^cmd: $first ");
 #    my $delta_time = &timedelta($t);
 #    &DEBUG("factArgs: delta_time = $delta_time s");
 #    &DEBUG("factArgs: list => ".scalar(@list) );
@@ -194,11 +203,11 @@ sub factoidArgs {
     foreach (sort { length($b) <=> length($a) } @list) {
        next if (/#DEL#/);      # deleted.
 
-       s/^CMD: //i;
+       s/^cmd: //i;
 #      &DEBUG("factarg: '$str' =~ /^$_\$/");
        my $arg = $_;
 
-       # todo: <greycat> ~punish apt for (Eating) (Parentheses)
+       # TODO: <greycat> ~punish apt for (Eating) (Parentheses)
        # how the hell do I fix the above? -dms.
 
        # eval (evil!) code. cleaned up courtesy of lear.
@@ -222,36 +231,35 @@ sub factoidArgs {
 #      &DEBUG("vals => @vals");
 
        &status("Question: factoid Arguments for '$str'");
-       # todo: use getReply() - need to modify it :(
+       # TODO: use getReply() - need to modify it :(
        my $i   = 0;
-       my $q   = "CMD: $_";
+       my $q   = "cmd: $_";
        my $r   = &getFactoid($q);
        if (!defined $r) {
            &DEBUG("question: !result... should this happen?");
            return;
        }
 
-       # update stats.
-       if (0) {        # old.
-           my $count = &getFactInfo($q, "requested_count") || 0;
-           $count++;
-           &setFactInfo($q, "requested_by", $nuh);
-           &setFactInfo($q, "requested_time", time());
-           &setFactInfo($q, "requested_count", $count);
-       } else {
-           &sqlUpdate("factoids", { factoid_key => $q }, {
-               requested_by            => $nuh,
-               requested_time          => time(),
-               -requested_count        => "requested_count+1",
-           } );
-       }
+       # update stats. old mysql/sqlite don't do +1
+       my ($count) = &sqlSelect("factoids", "requested_count", { factoid_key => $q });
+       $count++;
+       &sqlSet("factoids", {'factoid_key' => $q}, {
+               requested_by    => $nuh,
+               requested_time  => time(),
+               requested_count => $count
+       } );
 
        # end of update stats.
 
        $result = $r;
+
        $result =~ s/^\((.*?)\): //;
+       my $vars = $1;
+
+       # start nasty hack to get partial &getReply() functionality.
+       $result = &SARit($result);
 
-       foreach ( split(',', $1) ) {
+       foreach ( split(',', $vars) ) {
            my $val = $vals[$i];
 #          &DEBUG("val => $val");
 
@@ -264,7 +272,7 @@ sub factoidArgs {
            my $old = $result;
            while (1) {
 #              &DEBUG("Q: result => $result (1before)");
-               $result = &substVars($result);
+               $result = &substVars($result,1);
 #              &DEBUG("Q: result => $result (1after)");
 
                last if ($old eq $result);
@@ -275,17 +283,16 @@ sub factoidArgs {
            # hack.
            $vals[$i] =~ s/^me$/$who/gi;
 
-           if (!$done) {
+#          if (!$done) {
                &status("factArgs: SARing '$_' to '$vals[$i]'.");
                $result =~ s/\Q$_\E/$vals[$i]/g;
-           }
+#          }
            $i++;
        }
 
-       # nasty hack to get partial &getReply() functionality.
+       # rest of nasty hack to get partial &getReply() functionality.
        $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
        $result =~ s/^\s*<reply>\s*//i;
-       $result = &SARit($result);
 
 # well... lets go through all of them. not advisable if we have like
 # 1000 commands, heh.