##
# use strict; # TODO
+use POSIX qw(strftime);
use vars qw($msgType $uh $lastWho $ident);
use vars qw(%lang %lastWho);
}
$message =~ tr/A-Z/a-z/;
- $message =~ s/^cmd:/CMD:/;
- if (&IsChanConf("factoidSearch")) {
- @searches = split(/\s+/, &getChanConf("factoidSearch"));
- } else {
+ @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+//;
}
# check for factoids with each prefix
foreach $search (@searches) {
- if ($search eq '_default') {
+ if ($search eq '$chan') {
+ $factoid = "$chan $message";
+ } elsif ($search eq '_default') {
$factoid = $message;
} else {
$factoid = "$search $message";
}
- ($count, $fauthor, $result) = &sqlSelect("factoids",
+ ($count, $fauthor, $result) = &sqlSelect('factoids',
"requested_count,created_by,factoid_value",
{ factoid_key => $factoid }
);
if ($result) {
$lhs = $message;
- $mhs = "is";
+ $mhs = 'is';
$rhs = $result;
return "\"$factoid\" $mhs \"$rhs\"" if ($literal);
$result = &SARit($result);
$reply = $result;
- if ($result ne "") {
+ if ($result ne '') {
### AT LAST, REPEAT PREVENTION CODE REMOVED IN FAVOUR OF GLOBAL
### 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}, {
+ &sqlSet('factoids', {'factoid_key' => $factoid}, {
requested_by => $nuh,
requested_time => time(),
requested_count => $count
# TODO: rename $real to something else!
my $real = 0;
-# my $author = &getFactInfo($lhs,"created_by") || '';
+# my $author = &getFactInfo($lhs,'created_by') || '';
# $real++ if ($author =~ /^\Q$who\E\!/);
-# $real++ if (&IsFlag("n"));
+# $real++ if (&IsFlag('n'));
$real = 0 if ($msgType =~ /public/);
### fix up the reply.
### bot->person reply.
# result is random if separated by '||'.
# rhs is full factoid with '||'.
- if ($mhs eq "is") {
+ if ($mhs eq 'is') {
$reply = &getRandom(keys %{ $lang{'factoid'} });
$reply =~ s/##KEY/$lhs/;
$reply =~ s/##VALUE/$result/;
###
# 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;
}
}
&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;
}
sub substVars {
my($reply,$flag) = @_;
- # $date, $time.
+ # $date, $time, $day.
# TODO: support localtime.
- my $date = scalar(gmtime());
- $date =~ s/\:\d+(\s+\w+)\s+\d+$/$1/;
+ my $date = strftime("%Y.%m.%d", gmtime());
$reply =~ s/\$date/$date/gi;
- $date =~ s/\w+\s+\w+\s+\d+\s+//;
- $reply =~ s/\$time/$date/gi;
+ my $time = strftime("%k:%M:%S", gmtime());
+ $reply =~ s/\$time/$time/gi;
+ my $day = strftime("%A", gmtime());
+ $reply =~ s/\$day/$day/gi;
+
+ # support $ident when I have multiple nicks
+ my $mynick = $conn->nick() if $conn;
# dollar variables.
if ($flag) {
}
}
- $reply =~ s/\$ident/$ident/g;
+ $reply =~ s/\$ident/$mynick/g;
if ($reply =~ /\$startTime/) {
my $time = scalar(gmtime $^T);
}
if ($reply =~ /\$factoids/) {
- my $factoids = &countKeys("factoids");
+ my $factoids = &countKeys('factoids');
$reply =~ s/\$factoids/$factoids/;
}
if ($reply =~ /\$Fupdate/) {
my $x = "\002$count{'Update'}\002 ".
- &fixPlural("modification", $count{'Update'});
+ &fixPlural('modification', $count{'Update'});
$reply =~ s/\$Fupdate/$x/;
}
if ($reply =~ /\$Fquestion/) {
my $x = "\002$count{'Question'}\002 ".
- &fixPlural("question", $count{'Question'});
+ &fixPlural('question', $count{'Question'});
$reply =~ s/\$Fquestion/$x/;
}
if ($reply =~ /\$Fdunno/) {
my $x = "\002$count{'Dunno'}\002 ".
- &fixPlural("dunno", $count{'Dunno'});
+ &fixPlural('dunno', $count{'Dunno'});
$reply =~ s/\$Fdunno/$x/;
}