2 # Update.pl: Add or modify factoids in the db.
9 if (&IsParam("useStrict")) { use strict; }
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") {
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 (&dbGet("freshmeat", "name", $lhs, "name")) {
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 if (&IsChanConf("factoidArguments") and $lhs =~ /\$/) {
67 &status("Update: Factoid Arguments found.");
68 &status("Update: orig lhs => '$lhs'.");
69 &status("Update: orig rhs => '$rhs'.");
74 while ($lhs =~ s/\$(\S+)/(.*?)/) {
77 last if ($count >= 10);
81 &msg($who, "error: could not SAR properly.");
82 &DEBUG("error: lhs => '$lhs'.");
83 &DEBUG("error: rhs => '$rhs'.");
87 my $z = join(',',@list);
90 &status("Update: new lhs => '$lhs'.");
91 &status("Update: new rhs => '$rhs'.");
95 my $exists = &getFactoid($lhs);
98 # nice 'are' hack (or work-around).
99 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
100 &status("Update: 'are' hack detected.");
102 $rhs = "<REPLY> are ". $rhs;
105 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
108 &performAddressedReply("okay");
110 &setFactInfo($lhs,"created_by", $nuh);
111 &setFactInfo($lhs,"created_time", time());
112 &setFactInfo($lhs,"factoid_value", $rhs);
114 if (!defined $rhs or $rhs eq "") {
115 &ERROR("Update: rhs1 == NULL.");
122 if ($exists eq $rhs) {
123 &performAddressedReply("i already had it that way");
127 if ($also) { # 'is also'.
128 if ($exists =~ /^<REPLY> see /i) {
129 &DEBUG("todo: append to linked factoid.");
132 if ($also_or) { # 'is also ||'.
133 $rhs = $exists.' || '.$rhs;
135 # if ($exists =~ s/\,\s*$/, /) {
136 if ($exists =~ /\,\s*$/) {
137 &DEBUG("current has trailing comma, just append as is");
138 &DEBUG("Up: exists => $exists");
139 &DEBUG("Up: rhs => $rhs");
141 # $rhs = $exists." ".$rhs; # keep comma.
144 if ($exists =~ /\.\s*$/) {
145 &DEBUG("current has trailing period, just append as is with 2 WS");
146 &DEBUG("Up: exists => $exists");
147 &DEBUG("Up: rhs => $rhs");
150 # $rhs = $exists." ".$rhs; # keep comma.
153 if ($rhs =~ /^[A-Z]/) {
154 if ($rhs =~ /\w+\s*$/) {
155 &status("auto insert period to factoid.");
156 $rhs = $exists.". ".$rhs;
157 } else { # '?' or '.' assumed at end.
158 &status("orig factoid already had trailing symbol; not adding period.");
159 $rhs = $exists." ".$rhs;
161 } elsif ($exists =~ /[\,\.\-]\s*$/) {
162 &VERB("U: current has trailing symbols; inserting whitespace + new.",2);
163 $rhs = $exists." ".$rhs;
164 } elsif ($rhs =~ /^\./) {
165 &VERB("U: new text has ^.; appending directly",2);
168 $rhs = $exists.', or '.$rhs;
172 # max length check again.
173 if (length $rhs > $param{'maxDataSize'}) {
174 if (length $rhs > length $exists) {
175 &performAddressedReply("that's too long");
178 &status("Update: new length is still longer than maxDataSize but less than before, we'll let it go.");
182 &performAddressedReply("okay");
185 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
186 &AddModified($lhs,$nuh);
187 &setFactInfo($lhs, "factoid_value", $rhs);
189 if (!defined $rhs or $rhs eq "") {
190 &ERROR("Update: rhs1 == NULL.");
192 } else { # not "also"
194 if (!$correction_plausible) { # "no, blah is ..."
196 &performStrictReply("...but \002$lhs\002 is already something else...");
197 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
202 my $author = &getFactInfo($lhs, "created_by") || "";
204 if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
205 &msg($who, "you can't change that factoid.");
209 &performAddressedReply("okay");
212 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
215 &setFactInfo($lhs,"created_by", $nuh);
216 &setFactInfo($lhs,"created_time", time());
217 &setFactInfo($lhs,"factoid_value", $rhs);
219 if (!defined $rhs or $rhs eq "") {
220 &ERROR("Update: rhs1 == NULL.");