]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Question.pl
add missing )
[infobot.git] / src / Factoids / Question.pl
index 71ae23c171d4156d0d7fb946a92b32dc542c913e..44a50ec462d9d796bf0d75d5920402dc7a38ce0e 100644 (file)
@@ -23,7 +23,6 @@ sub doQuestion {
     local ($query) = @_;
     local ($reply) = '';
     local $finalQMark = $query =~ s/\?+\s*$//;
-    $finalQMark += $query =~ s/\?\s*$//;
     $query =~ s/^\s+|\s+$//g;
 
     if ( !defined $query or $query =~ /^\s*$/ ) {
@@ -34,8 +33,16 @@ sub doQuestion {
 
     if ( !$addressed ) {
         return '' unless ($finalQMark);
-        return '' unless &IsChanConf('minVolunteerLength') > 0;
-        return '' if ( length $query < &::getChanConf('minVolunteerLength') );
+        return ''
+          if (
+            length $query <
+            &::getChanConfDefault( 'minVolunteerLength', 2, $chan ) or
+            $param{'addressing'} =~ m/require/i );
+        return ''
+          if (
+            length $query >
+            &::getChanConfDefault( 'maxVolunteerLength', 512, $chan ) or
+            $param{'addressing'} =~ m/require/i );
     }
     else {
         ### TODO: this should be caught in Process.pl?
@@ -96,7 +103,7 @@ sub doQuestion {
     push( @query, $query ) if ( $query ne $x );
 
     if ( &IsChanConf('factoidArguments') > 0 ) {
-        $result = &factoidArgs( $query[0] );
+        $result = &factoidArgs( $query[0] , $chan);
 
         return $result if ( defined $result );
     }
@@ -187,9 +194,11 @@ sub doQuestion {
 }
 
 sub factoidArgs {
-    my ($str) = @_;
+    my ($str,$chan) = @_;
     my $result;
 
+    $chan //= '';
+
     # 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. !!! !!! !!!
@@ -199,19 +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', "^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' =~ /^$_\$/");