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 &DEBUG("1=>$1"); # this does not work!
54 my $also_or = ($also and $rhs =~ s/\s+(or|\|\|)\s+//);
57 if (&IsChanConf("freshmeatForFactoid")) {
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.");
66 my $exists = &getFactoid($lhs);
69 # nice 'are' hack (or work-around).
70 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
71 &DEBUG("Update: 'are' hack detected.");
73 $rhs = "<REPLY> are ". $rhs;
76 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
79 &performAddressedReply("okay");
81 &setFactInfo($lhs,"created_by", $nuh);
82 &setFactInfo($lhs,"created_time", time());
83 &setFactInfo($lhs,"factoid_value", $rhs);
85 if (!defined $rhs or $rhs eq "") {
86 &ERROR("Update: rhs1 == NULL.");
93 if ($exists eq $rhs) {
94 &performAddressedReply("i already had it that way");
98 if ($also) { # 'is also'.
99 if ($exists =~ /^<REPLY> see /i) {
100 &DEBUG("todo: append to linked factoid.");
103 if ($also_or) { # 'is also ||'.
104 $rhs = $exists.' || '.$rhs;
106 # if ($exists =~ s/\,\s*$/, /) {
107 if ($exists =~ /\,\s*$/) {
108 &DEBUG("current has trailing comma, just append as is");
110 # $rhs = $exists." ".$rhs; # keep comma.
113 if ($exists =~ /\.\s*$/) {
114 &DEBUG("current has trailing period, just append as is with 2 WS");
117 # $rhs = $exists." ".$rhs; # keep comma.
120 if ($rhs =~ /^[A-Z]/) {
121 if ($rhs =~ /\w+\s*$/) {
122 &status("auto insert period to factoid.");
123 $rhs = $exists.". ".$rhs;
124 } else { # '?' or '.' assumed at end.
125 &status("orig factoid already had trailing symbol; not adding period.");
126 $rhs = $exists." ".$rhs;
128 } elsif ($exists =~ /[\,\.\-]\s*$/) {
129 &VERB("U: current has trailing symbols; inserting whitespace + new.",2);
130 $rhs = $exists." ".$rhs;
131 } elsif ($rhs =~ /^\./) {
132 &VERB("U: new text has ^.; appending directly",2);
135 $rhs = $exists.', or '.$rhs;
139 # max length check again.
140 if (length $rhs > $param{'maxDataSize'}) {
141 if (length $rhs > length $exists) {
142 &performAddressedReply("that's too long");
145 &status("Update: new length is still longer than maxDataSize but less than before, we'll let it go.");
149 &performAddressedReply("okay");
152 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
153 &AddModified($lhs,$nuh);
154 &setFactInfo($lhs, "factoid_value", $rhs);
156 if (!defined $rhs or $rhs eq "") {
157 &ERROR("Update: rhs1 == NULL.");
159 } else { # not "also"
161 if (!$correction_plausible) { # "no, blah is ..."
163 &performStrictReply("...but \002$lhs\002 is already something else...");
164 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
169 my $author = &getFactInfo($lhs, "created_by") || "";
171 if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
172 &msg($who, "you can't change that factoid.");
176 &performAddressedReply("okay");
179 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
182 &setFactInfo($lhs,"created_by", $nuh);
183 &setFactInfo($lhs,"created_time", time());
184 &setFactInfo($lhs,"factoid_value", $rhs);
186 if (!defined $rhs or $rhs eq "") {
187 &ERROR("Update: rhs1 == NULL.");