2 # Update.pl: Add or modify factoids in the db.
9 if (&IsParam("useStrict")) { use strict; }
12 my($lhs, $mhs, $rhs) = @_;
14 $lhs =~ s/^i (heard|think) //i;
15 $lhs =~ s/^some(one|1|body) said //i;
19 return $noreply if (&IsLocked($lhs) == 1);
22 if (&IsParam("profanityCheck") and &hasProfanity($rhs)) {
23 &msg($who, "please, watch your language.");
28 if (&IsFlag("t") ne "t") {
29 &msg($who, "permission denied.");
30 &status("alert: $who wanted to teach me.");
35 if ($mhs !~ /^(is|are)$/i) {
36 &ERROR("UNKNOWN verb: $mhs.");
40 # check if the arguments are too long to be stored in our table.
41 if (length($lhs) > $param{'maxKeySize'} or
42 length($rhs) > $param{'maxDataSize'})
44 &performAddressedReply("that's too long");
52 my $also = ($rhs =~ s/^also //i);
53 my $also_or = ($also and $rhs =~ s/\s+(or|\|\|)\s+//);
55 if (&IsParam("freshmeatForFactoid")) {
56 if (&dbGet("freshmeat", "name", $lhs, "name")) {
57 &msg($who, "permission denied. (freshmeat)");
58 &status("alert: $who wanted to teach me something that freshmeat already has info on.");
63 if (my $exists = &getFactoid($lhs)) { # factoid exists.
64 if ($exists eq $rhs) {
65 &performAddressedReply("i already had it that way");
69 if ($also) { # 'is also'.
70 if ($also_or) { # 'is also ||'.
71 $rhs = $exists.' || '.$rhs;
73 # if ($exists =~ s/\,\s*$/, /) {
74 if ($exists =~ /\,\s*$/) {
75 &DEBUG("current has trailing comma, just append as is");
77 # $rhs = $exists." ".$rhs; # keep comma.
80 if ($exists =~ /\.\s*$/) {
81 &DEBUG("current has trailing period, just append as is with 2 WS");
84 # $rhs = $exists." ".$rhs; # keep comma.
87 if ($rhs =~ /^[A-Z]/) {
88 if ($rhs =~ /\w+\s*$/) {
89 &status("auto insert period to factoid.");
90 $rhs = $exists.". ".$rhs;
91 } else { # '?' or '.' assumed at end.
92 &status("orig factoid already had trailing symbol; not adding period.");
93 $rhs = $exists." ".$rhs;
95 } elsif ($exists =~ /[\,\.\-]\s*$/) {
96 &VERB("U: current has trailing symbols; inserting whitespace + new.",2);
97 $rhs = $exists." ".$rhs;
98 } elsif ($rhs =~ /^\./) {
99 &VERB("U: new text has ^.; appending directly",2);
102 $rhs = $exists.', or '.$rhs;
106 # max length check again.
107 if (length($rhs) > $param{'maxDataSize'}) {
108 &performAddressedReply("that's too long");
112 &performAddressedReply("okay");
115 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
116 &AddModified($lhs,$nuh);
117 &setFactInfo($lhs, "factoid_value", $rhs);
118 } else { # not "also"
119 if ($correction_plausible) { # "no, blah is ..."
120 my $author = &getFactInfo($lhs, "created_by") || "";
122 if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
123 &msg($who, "you can't change that factoid.");
127 &performAddressedReply("okay");
130 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
133 &setFactInfo($lhs,"created_by", $nuh);
134 &setFactInfo($lhs,"created_time", time());
135 &setFactInfo($lhs,"factoid_value", $rhs);
136 } else { # "blah is ..."
138 &performStrictReply("...but \002$lhs\002 is already something else...");
139 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
144 } else { # not exists.
146 # nice 'are' hack (or work-around).
147 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
148 &DEBUG("Update: 'are' hack detected.");
150 $rhs = "<REPLY> are ". $rhs;
153 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
156 &performAddressedReply("okay");
158 &setFactInfo($lhs,"created_by", $nuh);
159 &setFactInfo($lhs,"created_time", time());
160 &setFactInfo($lhs,"factoid_value", $rhs);
163 return "$lhs $mhs $rhs";