- foreach (sort { length($b) <=> length($a) } @list) {
- next if (/#DEL#/); # deleted.
-
- s/^CMD: //i;
-# &DEBUG("factarg: '$str' =~ /^$_\$/");
- my $arg = $_;
-
- # TODO: <greycat> ~punish apt for (Eating) (Parentheses)
- # how the hell do I fix the above? -dms.
-
- # eval (evil!) code. cleaned up courtesy of lear.
- my @vals;
- eval {
- @vals = ($str =~ /^$arg$/i);
- };
-
- if ($@) {
- &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
- next;
- }
-
- 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.
- &sqlUpdate("factoids", { factoid_key => $q }, {
- requested_by => $nuh,
- requested_time => time(),
- -requested_count => "requested_count+1",
- } );
-
- # end of update stats.
-
- $result = $r;
- $result =~ s/^\((.*?)\): //;
-
- foreach ( split(',', $1) ) {
- 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);
-# &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++;
- }
-
- # 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.
-# return $result;
- $cmdstats{'Factoid Commands'}++;
+ foreach ( sort { length($b) <=> length($a) } @list ) {
+ next if (/#DEL#/); # deleted.
+
+ s/^cmd: //i;
+
+ # &DEBUG("factarg: '$str' =~ /^$_\$/");
+ my $arg = $_;
+
+ # eval (evil!) code. cleaned up courtesy of lear.
+ my @vals;
+ eval { @vals = ( $str =~ /^$arg$/i ); };
+
+ if ($@) {
+ &WARN("factargs: regex failed! '$str' =~ /^$_\$/");
+ next;
+ }
+
+ 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'}++;