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.");
34 # nice 'are' hack (or work-around).
35 if ($mhs =~ /^are$/i and $rhs !~ /<\S+>/) {
37 $rhs = "<REPLY> are ". $rhs;
41 if ($mhs !~ /^is$/i) {
42 &ERROR("UNKNOWN verb: $mhs.");
46 # check if the arguments are too long to be stored in our table.
47 if (length($lhs) > $param{'maxKeySize'} or
48 length($rhs) > $param{'maxDataSize'})
50 &performAddressedReply("that's too long");
58 my $also = ($rhs =~ s/^also //i);
59 my $also_or = ($also and $rhs =~ s/\s+(or|\|\|)\s+//);
61 if (&IsParam("freshmeatForFactoid")) {
62 if (&dbGet("freshmeat", "name", $lhs, "name")) {
63 &msg($who, "permission denied. (freshmeat)");
64 &status("alert: $who wanted to teach me something that freshmeat already has info on.");
69 if (my $exists = &getFactoid($lhs)) { # factoid exists.
72 if ($exists eq $rhs) {
73 &performAddressedReply("i already had it that way");
77 if ($also) { # 'is also'.
78 if ($also_or) { # 'is also ||'.
79 $rhs = $exists.' || '.$rhs;
81 if ($rhs =~ /^[A-Z]/) {
82 if ($rhs =~ /\w+\s*$/) {
83 &status("auto insert period to factoid.");
84 $rhs = $exists.". ".$rhs;
85 } else { # '?' or '.' assumed at end.
86 &status("orig factoid already had trailing symbol; not adding period.");
87 $rhs = $exists." ".$rhs;
89 } elsif ($exists =~ /\,\s*$/) {
90 $rhs = $exists." ".$rhs;
91 } elsif ($rhs =~ /^\./) {
94 $rhs = $exists.', or '.$rhs;
98 # max length check again.
99 if (length($rhs) > $param{'maxDataSize'}) {
100 &performAddressedReply("that's too long");
104 &performAddressedReply("okay");
107 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
108 &AddModified($lhs,$nuh);
109 &setFactInfo($lhs, "factoid_value", $rhs);
110 } else { # not "also"
111 if ($correction_plausible) { # "no, blah is ..."
112 my $author = &getFactInfo($lhs, "created_by");
114 &DEBUG("Update: check: '$author' == '$who' ?");
116 if (IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) {
117 &msg($who, "you can't change that factoid.");
121 &performAddressedReply("okay");
124 &status("update: <$who> \'$lhs\' =$mhs=> \'$rhs\'; was \'$exists\'");
127 &setFactInfo($lhs,"created_by", $nuh);
128 &setFactInfo($lhs,"created_time", time());
129 &setFactInfo($lhs,"factoid_value", $rhs);
130 } else { # "blah is ..."
132 &performStrictReply("...but \002$lhs\002 is already something else...");
133 &status("FAILED update: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
138 } else { # not exists.
139 &status("enter: <$who> \'$lhs\' =$mhs=> \'$rhs\'");
142 &performAddressedReply("okay");
144 &setFactInfo($lhs,"created_by", $nuh);
145 &setFactInfo($lhs,"created_time", time());
146 &setFactInfo($lhs,"factoid_value", $rhs);
149 return "$lhs $mhs $rhs";