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 if (&dbGet("freshmeat", "name", $lhs, "name")) {
58 &msg($who, "permission denied. (freshmeat)");
59 &status("alert: $who wanted to teach me something that freshmeat already has info on.");
65 my $exists = &getFactoid($lhs);
68 # nice 'are' hack (or work-around).
69 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
70 &status("Update: 'are' hack detected.");
72 $rhs = "<REPLY> are ". $rhs;
75 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
78 &performAddressedReply("okay");
80 &setFactInfo($lhs,"created_by", $nuh);
81 &setFactInfo($lhs,"created_time", time());
82 &setFactInfo($lhs,"factoid_value", $rhs);
84 if (!defined $rhs or $rhs eq "") {
85 &ERROR("Update: rhs1 == NULL.");
92 if ($exists eq $rhs) {
93 &performAddressedReply("i already had it that way");
97 if ($also) { # 'is also'.
98 if ($exists =~ /^<REPLY> see /i) {
99 &DEBUG("todo: append to linked factoid.");
102 if ($also_or) { # 'is also ||'.
103 $rhs = $exists.' || '.$rhs;
105 # if ($exists =~ s/\,\s*$/, /) {
106 if ($exists =~ /\,\s*$/) {
107 &DEBUG("current has trailing comma, just append as is");
108 &DEBUG("Up: exists => $exists");
109 &DEBUG("Up: rhs => $rhs");
111 # $rhs = $exists." ".$rhs; # keep comma.
114 if ($exists =~ /\.\s*$/) {
115 &DEBUG("current has trailing period, just append as is with 2 WS");
116 &DEBUG("Up: exists => $exists");
117 &DEBUG("Up: rhs => $rhs");
120 # $rhs = $exists." ".$rhs; # keep comma.
123 if ($rhs =~ /^[A-Z]/) {
124 if ($rhs =~ /\w+\s*$/) {
125 &status("auto insert period to factoid.");
126 $rhs = $exists.". ".$rhs;
127 } else { # '?' or '.' assumed at end.
128 &status("orig factoid already had trailing symbol; not adding period.");
129 $rhs = $exists." ".$rhs;
131 } elsif ($exists =~ /[\,\.\-]\s*$/) {
132 &VERB("U: current has trailing symbols; inserting whitespace + new.",2);
133 $rhs = $exists." ".$rhs;
134 } elsif ($rhs =~ /^\./) {
135 &VERB("U: new text has ^.; appending directly",2);
138 $rhs = $exists.', or '.$rhs;
142 # max length check again.
143 if (length $rhs > $param{'maxDataSize'}) {
144 if (length $rhs > length $exists) {
145 &performAddressedReply("that's too long");
148 &status("Update: new length is still longer than maxDataSize but less than before, we'll let it go.");
152 &performAddressedReply("okay");
155 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
156 &AddModified($lhs,$nuh);
157 &setFactInfo($lhs, "factoid_value", $rhs);
159 if (!defined $rhs or $rhs eq "") {
160 &ERROR("Update: rhs1 == NULL.");
162 } else { # not "also"
164 if (!$correction_plausible) { # "no, blah is ..."
166 &performStrictReply("...but \002$lhs\002 is already something else...");
167 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
172 my $author = &getFactInfo($lhs, "created_by") || "";
174 if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
175 &msg($who, "you can't change that factoid.");
179 &performAddressedReply("okay");
182 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
185 &setFactInfo($lhs,"created_by", $nuh);
186 &setFactInfo($lhs,"created_time", time());
187 &setFactInfo($lhs,"factoid_value", $rhs);
189 if (!defined $rhs or $rhs eq "") {
190 &ERROR("Update: rhs1 == NULL.");