]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
fix extra )
[infobot.git] / src / Factoids / Question.pl
index 1b4d823847ada1b31123da7b70559e215786fab0..ec5225339515411dfe9b0b7131939319a8a085b7 100644 (file)
@@ -208,22 +208,27 @@ sub factoidArgs {
     # 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', "^$chan cmd: $first " );
-      &searchTable( 'factoids', 'factoid_key', 'factoid_key', "^cmd: $first " );
+        (&searchTable( 'factoids', 'factoid_key', 'factoid_key', "^$chan cmd: $first " ),
+         &searchTable( 'factoids', 'factoid_key', 'factoid_key', "^_default cmd: $first " ),
+         &searchTable( 'factoids', 'factoid_key', 'factoid_key', "^cmd: $first " ));
 
     &DEBUG("chan is $chan, first is $first; searching for '^$chan cmd: $first' ");
 
     #    my $delta_time = &timedelta($t);
     #    &DEBUG("factArgs: delta_time = $delta_time s");
-    &DEBUG("factArgs: list => ".scalar(@list) );
+    &DEBUG("factArgs: list[.".scalar(@list)."] => ".join(',',map {qq('$_')} @list);
 
     # from a design perspective, it's better to have the regex in
     # the factoid key to reduce repetitive processing.
 
     # it does not matter if it's not alphabetically sorted.
-    foreach ( sort { length($b) <=> length($a) } @list ) {
+    foreach ( (sort { length($b) <=> length($a) } grep {$_ =~ /^\Q$chan \E/} @list),
+              (sort { length($b) <=> length($a) } grep {$_ =~ /^\Q_default \E/} @list)
+              (sort { length($b) <=> length($a) } grep {$_ !~ /^(\Q$chan\E|default) /} @list)
+            ) {
         next if (/#DEL#/);    # deleted.
 
+        s/^\Q$chan \E//i;
         s/^cmd: //i;
 
         #      &DEBUG("factarg: '$str' =~ /^$_\$/");