+ next unless (@vals);
+
+ if ( defined $result ) {
+ &WARN("factargs: '$_' matches aswell.");
+ next;
+ }
+
+ # &DEBUG("vals => @vals");
+
+ &status("Question: factoid Arguments for '$str'");
+
+ # TODO: use getReply() - need to modify it :(
+ my $i = 0;
+ my $q = "cmd: $_";
+ my $r = &getFactoid($q);
+ if ( !defined $r ) {
+ &DEBUG("question: !result... should this happen?");
+ return;
+ }
+
+ # 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( ',', $vars ) ) {
+ my $val = $vals[$i];
+
+ # &DEBUG("val => $val");
+
+ if ( !defined $val ) {
+ &status(
+ "factArgs: vals[$i] == undef; not SARing '$_' for '$str'");
+ next;
+ }
+
+ my $done = 0;
+ my $old = $result;
+ while (1) {
+
+ # &DEBUG("Q: result => $result (1before)");
+ $result = &substVars( $result, 1 );
+
+ # &DEBUG("Q: result => $result (1after)");
+
+ last if ( $old eq $result );
+ $old = $result;
+ $done++;
+ }
+
+ # hack.
+ $vals[$i] =~ s/^me$/$who/gi;
+
+ # if (!$done) {
+ &status("factArgs: SARing '$_' to '$vals[$i]'.");
+ $result =~ s/\Q$_\E/$vals[$i]/g;
+
+ # }
+ $i++;
+ }
+
+ # rest of nasty hack to get partial &getReply() functionality.
+ $result =~ s/^\s*<action>\s*(.*)/\cAACTION $1\cA/i;
+ $result =~ s/^\s*<reply>\s*//i;
+
+ # well... lets go through all of them. not advisable if we have like
+ # 1000 commands, heh.
+ # return $result;
+ $cmdstats{'Factoid Commands'}++;