]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Reply.pl
changes for Debian stable/sarge, 3.1
[infobot.git] / src / Factoids / Reply.pl
index 780881b9edea806ddb99e94d51571bc25e5e88c4..d21f0f2e6e2ec97687a11162d714cb91bd9593ed 100644 (file)
@@ -18,7 +18,7 @@ use vars qw(%lang %lastWho);
 sub getReply {
     my($message) = @_;
     my($lhs,$mhs,$rhs);
-    my($reply);
+    my($reply, $count, $fauthor, $result, $factoid, $search, @searches);
     $orig{message} = $message;
 
     if (!defined $message or $message =~ /^\s*$/) {
@@ -27,28 +27,29 @@ sub getReply {
     }
 
     $message =~ tr/A-Z/a-z/;
-    $message =~ s/^cmd:/CMD:/;
 
-    my ($count, $fauthor, $result, $factoid);
-
-    if (!$literal and &IsChanConf("channelFactoids")) {
-       # check for factoids specific to this channel
-       ($count, $fauthor, $result) = &sqlSelect("factoids",
-           "requested_count,created_by,factoid_value",
-           { factoid_key => "$chan $message" }
-       );
+    @searches = split(/\s+/, &getChanConfDefault('factoidSearch', '_default', $chan));
+    &::DEBUG("factoidSearch: $chan is: " . join(':', @searches));
+    # requesting the _default one, ignore factoidSearch
+    if ($message =~ /^_default\s+/) {
+       @searches = ('_default');
+       $message =~ s/^_default\s+//;
     }
 
-    if ($result) {
-       # got channel specific reply above
-       $factoid="$chan $message"
-    } else {
-       # no channel specific factoid was requested / found
+    # check for factoids with each prefix
+    foreach $search (@searches) {
+       if ($search eq '$chan') {
+           $factoid = "$chan $message";
+       } elsif ($search eq '_default') {
+           $factoid = $message;
+       } else {
+           $factoid = "$search $message";
+       }
        ($count, $fauthor, $result) = &sqlSelect("factoids",
            "requested_count,created_by,factoid_value",
-           { factoid_key => $message }
+           { factoid_key => $factoid }
        );
-       $factoid=$message if ($result);
+       last if ($result);
     }
 
     if ($result) {
@@ -79,7 +80,7 @@ sub getReply {
        ### FLOOD REPETION AND PROTECTION. -20000124
 
        # stats code.
-       ### FIXME: old mysql doesn't support
+       ### FIXME: old mysql/sqlite doesn't support
        ### "requested_count=requested_count+1".
        $count++;
        &sqlSet("factoids", {'factoid_key' => $factoid}, {
@@ -133,8 +134,6 @@ sub getReply {
        }
     }
 
-    return $reply if ($literal);
-
     # remove excessive beginning and end whitespaces.
     $reply     =~ s/^\s+|\s+$//g;
 
@@ -150,11 +149,11 @@ sub getReply {
     ###
 
     # don't evaluate if it has factoid arguments.
-    if ($message =~ /^CMD:/i) {
-       &status("Reply: not doing substVars (eval dollar vars)");
-    } else {
+#    if ($message =~ /^cmd:/i) {
+#      &status("Reply: not doing substVars (eval dollar vars)");
+#    } else {
        $reply = &substVars($reply,1);
-    }
+#    }
 
     $reply;
 }
@@ -250,6 +249,19 @@ sub SARit {
     }
     &status("Reply.pl: $done SARs done.") if ($done);
 
+    # <URL></URL> type
+    #
+    while ($txt =~ /<URL>(.*)<\/URL>/){
+       &status("we have to norm this <URL></URL> stuff, SARing");
+       my $foobar = $1;
+       if ($foobar =~ m/(http:\/\/[^?]+)\?(.*)/){
+           my ($pig1,$pig2) = ($1,$2);
+           &status("SARing using URLencode");
+           $pig2=~s/([^\w])/sprintf("%%%02x",ord($1))/gie;
+           $foobar=$pig1."?".$pig2;
+       }
+       $txt =~ s/<URL>(.*)<\/URL>/$foobar/;
+    }
     return $txt;
 }