2 # Update.pl: Add or modify factoids in the db.
12 my($lhs, $mhs, $rhs) = @_;
15 s/^i (heard|think) //i;
16 s/^some(one|1|body) said //i;
21 return if (&IsLocked($lhs) == 1);
24 if (&IsParam("profanityCheck") and &hasProfanity($rhs)) {
25 &performReply("please, watch your language.");
30 if (&IsFlag("t") ne "t" && &IsFlag("o") ne "o") {
31 &msg($who, "permission denied.");
32 &status("alert: $who wanted to teach me.");
37 if ($mhs !~ /^(is|are)$/i) {
38 &ERROR("UNKNOWN verb: $mhs.");
42 # check if the arguments are too long to be stored in our table.
44 $toolong++ if (length $lhs > $param{'maxKeySize'});
45 $toolong++ if (length $rhs > $param{'maxDataSize'});
47 &performAddressedReply("that's too long");
52 my $also = ($rhs =~ s/^-?also //i);
53 my $also_or = ($also and $rhs =~ s/\s+(or|\|\|)\s+//);
56 if (&IsChanConf("freshmeatForFactoid")) {
57 # todo: "name" is invalid for fm ][
58 if ( &sqlSelect("freshmeat", "name", { name => $lhs } ) ) {
59 &msg($who, "permission denied. (freshmeat)");
60 &status("alert: $who wanted to teach me something that freshmeat already has info on.");
65 # factoid arguments handler.
66 # must start with a non-variable
67 if (&IsChanConf("factoidArguments") and $lhs =~ /^[^\$]+.*\$/) {
68 &status("Update: Factoid Arguments found.");
69 &status("Update: orig lhs => '$lhs'.");
70 &status("Update: orig rhs => '$rhs'.");
75 while ($lhs =~ s/\$(\S+)/(.*?)/) {
78 last if ($count >= 10);
82 &msg($who, "error: could not SAR properly.");
83 &DEBUG("error: lhs => '$lhs' rhs => '$rhs'.");
87 my $z = join(',',@list);
90 &status("Update: new lhs => '$lhs' rhs => '$rhs'.");
94 my $exists = &getFactoid($lhs);
97 # nice 'are' hack (or work-around).
98 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
99 &status("Update: 'are' hack detected.");
101 $rhs = "<REPLY> are ". $rhs;
104 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
107 &performAddressedReply("okay");
109 &sqlReplace("factoids", {
111 created_time => time(), # modified time.
113 factoid_value => $rhs,
116 if (!defined $rhs or $rhs eq "") {
117 &ERROR("Update: rhs1 == NULL.");
124 if ($exists eq $rhs) {
125 # this catches the following situation: (right or wrong?)
127 # "test is also test"
128 &performAddressedReply("i already had it that way");
132 if ($also) { # 'is also'.
133 if ($exists =~ /^<REPLY> see /i) {
134 &DEBUG("Update.pl: todo: append to linked factoid.");
137 if ($also_or) { # 'is also ||'.
138 $rhs = $exists.' || '.$rhs;
140 # if ($exists =~ s/\,\s*$/, /) {
141 if ($exists =~ /\,\s*$/) {
142 &DEBUG("current has trailing comma, just append as is");
143 &DEBUG("Up: exists => $exists");
144 &DEBUG("Up: rhs => $rhs");
146 # $rhs = $exists." ".$rhs; # keep comma.
149 if ($exists =~ /\.\s*$/) {
150 &DEBUG("current has trailing period, just append as is with 2 WS");
151 &DEBUG("Up: exists => $exists");
152 &DEBUG("Up: rhs => $rhs");
155 # $rhs = $exists." ".$rhs; # keep comma.
158 if ($rhs =~ /^[A-Z]/) {
159 if ($rhs =~ /\w+\s*$/) {
160 &status("auto insert period to factoid.");
161 $rhs = $exists.". ".$rhs;
162 } else { # '?' or '.' assumed at end.
163 &status("orig factoid already had trailing symbol; not adding period.");
164 $rhs = $exists." ".$rhs;
166 } elsif ($exists =~ /[\,\.\-]\s*$/) {
167 &VERB("U: current has trailing symbols; inserting whitespace + new.",2);
168 $rhs = $exists." ".$rhs;
169 } elsif ($rhs =~ /^\./) {
170 &VERB("U: new text has ^.; appending directly",2);
173 $rhs = $exists.', or '.$rhs;
177 # max length check again.
178 if (length $rhs > $param{'maxDataSize'}) {
179 if (length $rhs > length $exists) {
180 &performAddressedReply("that's too long");
183 &status("Update: new length is still longer than maxDataSize but less than before, we'll let it go.");
187 &performAddressedReply("okay");
190 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
191 &sqlReplace("factoids", {
194 modified_time => time(),
195 factoid_value => $rhs,
198 if (!defined $rhs or $rhs eq "") {
199 &ERROR("Update: rhs1 == NULL.");
201 } else { # not "also"
203 if (!$correction_plausible) { # "no, blah is ..."
205 &performStrictReply("...but \002$lhs\002 is already something else...");
206 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
211 my $author = &getFactInfo($lhs, "created_by") || "";
213 if (IsFlag("m") ne "m" && IsFlag("o") ne "o" &&
214 $author !~ /^\Q$who\E\!/i
216 &msg($who, "you can't change that factoid.");
220 &performAddressedReply("okay");
223 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
225 &sqlReplace("factoids", {
228 modified_time => time(),
229 factoid_value => $rhs,
232 if (!defined $rhs or $rhs eq "") {
233 &ERROR("Update: rhs1 == NULL.");