2 # Misc.pl: Miscellaneous stuff.
4 # Version: v0.1 (20010906)
8 if (&IsParam("useStrict")) { use strict; }
10 # Usage: &validFactoid($lhs,$rhs);
16 # allow the following only if they have been made on purpose.
17 if ($rhs ne "" and $rhs !~ /^</) {
18 / \Q$ident$/i and last; # someone said i'm something.
20 /^(it|that|there|what)('s)?(\s+|$)/ and last;
21 /^you('re)?(\s+|$)/ and last;
23 /^(where|who|why|when|how)(\s+|$)/ and last;
24 /^(this|that|these|those|they)(\s+|$)/ and last;
25 /^(every(one|body)|we) / and last;
31 /^add topic / and last; # topic management.
32 /( add$| add |^add )/ and last; # borked teach statement.
33 /^learn / and last; # teach. damn morons.
34 /^tell (\S+) about / and last; # tell.
35 /\=\~/ and last; # substituition.
36 /^\S+ to \S+ \S+/ and last; # babelfish.
38 /^\=/ and last; # botnick = heh is.
39 /wants you to know/ and last;
44 (/^'/ and /'$/) and last;
45 (/^"/ and /"$/) and last;
48 /\=\>/ and last; # '=>'.
49 /\;\;/ and last; # ';;'.
50 /\|\|/ and last; # '||'.
52 /^\Q$ident\E[\'\,\: ]/ and last;# dupe addressed.
54 /\\$/ and last; # forgot shift for '?'.
62 /^h(is|er) / and last;
70 /^supposedly/ and last;
75 # nasty bug I introduced _somehow_, probably by fixMySQLBug().
79 # weird/special stuff. also old blootbot or stock infobot bugs.
80 $rhs =~ /( \Q$ident\E's|\Q$ident\E's )/i and last; # ownership.
83 $rhs =~ /^\Q$lhs /i and last;
84 last if ($rhs =~ /^is /i and / is$/);
94 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
96 &status("infobot <$nuh> identified") unless $bots{$nuh};
102 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
103 my ($target,$item) = ($1,$2);
106 &status(":INFOBOT:QUERY $who: $message");
108 if ($_ = &getFactoid($item)) {
109 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
112 return 'INFOBOT QUERY';
113 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
114 my ($target,$item) = ($1,$2);
116 &status(":INFOBOT:REPLY $who: $message");
118 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
120 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
121 &msg($target, "$who knew: $lhs $mhs $rhs");
124 $rhs = "<REPLY> are" if ($mhs eq "are");
125 &setFactInfo($lhs, "factoid_value", $rhs);
128 return 'INFOBOT REPLY';
130 &ERROR(":INFOBOT:UNKNOWN $who: $message");
131 return 'INFOBOT UNKNOWN';
136 if ($message =~ s/^forget\s+//i) {
137 return 'forget: no addr' unless ($addressed);
139 my $faqtoid = $message;
140 if ($faqtoid eq "") {
145 $faqtoid =~ tr/A-Z/a-z/;
146 my $result = &getFactoid($faqtoid);
148 # if it doesn't exist, well... it doesn't!
149 if (!defined $result) {
150 &performReply("i didn't have anything called '$faqtoid'");
154 my $author = &getFactInfo($faqtoid, "created_by");
155 my $count = &getFactInfo($faqtoid, "requested_count") || 0;
156 my $limit = &getChanConfDefault(
157 "factoidPreventForgetLimit", 100, $chan);
158 my $limitage = &getChanConfDefault(
159 "factoidPreventForgetLimitTime", 180, $chan);
160 my $t = &getFactInfo($faqtoid, "created_time") || 0;
161 my $age = time() - $t;
163 # lets scale limitage from 1 (nearly 0) to $limit (full time).
164 $limitage = $limitage*($count+1)/$limit if ($count < $limit);
166 my $isau = (defined $author and &IsHostMatch($author) == 2) ? 1 : 0;
167 my $isop = (&IsFlag("o") eq "o") ? 1 : 0;
169 if (IsFlag("r") ne "r") {
170 &msg($who, "you don't have access to remove factoids");
174 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
177 ### lets go do some checking.
180 # factoidPreventForgetLimitTime:
181 if (!($isop or $isau) and $age/(60*60*24) > $limitage) {
182 &msg($who, "cannot remove factoid '$faqtoid' since it is protected by Time.");
186 # factoidPreventForgetLimit:
187 if (!($isop or $isau) and $limit and $count > $limit) {
188 &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)");
192 # this may eat some memory.
193 # prevent deletion if other factoids redirect to it.
194 # todo: use hash instead of array.
196 if (&getChanConf("factoidPreventForgetRedirect")) {
197 &status("Factoids/Core: forget: checking for redirect factoids");
198 @list = &searchTable("factoids", "factoid_key",
199 "factoid_value", "^<REPLY> see ");
205 my $v = &getFactInfo($f, "factoid_value");
206 my $fsafe = quotemeta($faqtoid);
207 next unless ($v =~ /^<REPLY> ?see( also)? $fsafe\.?$/i);
209 &DEBUG("Factoids/Core: match! ($f || $faqtoid)");
213 # todo: warn for op aswell, but allow force delete.
214 if (!$isop and $match) {
215 &msg($who, "uhm, other (redirection) factoids depend on this one.");
220 if (!$isop and &IsHostMatch($author) != 2) {
221 $cache{forget}{$h}++;
224 if ($cache{forget}{$h} > 3) {
225 &msg($who, "Stop abusing forget!");
229 # todo: make forget limit configurable.
230 # todo: make forget ignore time configurable.
231 if ($cache{forget}{$h} > 5) {
232 &ignoreAdd(&makeHostMask($nuh), "*", 3*24*60*60, "abuse of forget");
233 &msg($who, "forget: Suck it!");
239 if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
240 if (!($isop or $isau) and $faqtoid =~ / #DEL#$/) {
241 &msg($who, "cannot delete it ($faqtoid).");
245 &status("forgot (safe delete): '$faqtoid' - ". scalar(localtime));
246 ### TODO: check if the "backup" exists and overwrite it
247 my $check = &getFactoid("$faqtoid #DEL#");
249 if (!defined $check or $check =~ /^\s*$/) {
250 if ($faqtoid !~ / #DEL#$/) {
251 my $new = $faqtoid." #DEL#";
253 my $backup = &getFactoid($new);
255 &DEBUG("forget: not overwriting backup: $faqtoid");
257 &status("forget: backing up '$faqtoid'");
258 &setFactInfo($faqtoid, "factoid_key", $new);
259 &setFactInfo($new, "modified_by", $who);
260 &setFactInfo($new, "modified_time", time());
264 &status("forget: not backing up $faqtoid.");
268 &status("forget: not overwriting backup!");
272 &status("forget: <$who> '$faqtoid' =is=> '$result'");
273 &delFactoid($faqtoid);
275 &performReply("i forgot $faqtoid");
282 # factoid unforget/undelete.
283 if ($message =~ s/^un(forget|delete)\s+//i) {
284 return 'unforget: no addr' unless ($addressed);
287 $i++ if (&IsParam("factoidDeleteDelay"));
288 $i++ if (&IsChanConf("factoidDeleteDelay"));
290 &performReply("safe delete has been disable so what is there to undelete?");
294 my $faqtoid = $message;
295 if ($faqtoid eq "") {
300 $faqtoid =~ tr/A-Z/a-z/;
301 my $result = &getFactoid($faqtoid." #DEL#");
302 my $check = &getFactoid($faqtoid);
304 if (defined $check) {
305 &performReply("cannot undeleted '$faqtoid' because it already exists!");
309 if (!defined $result) {
310 &performReply("that factoid was not backedup :/");
314 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
315 # &setFactInfo($faqtoid, "modified_by", "");
316 # &setFactInfo($faqtoid, "modified_time", 0);
318 $check = &getFactoid($faqtoid);
319 # todo: check if $faqtoid." #DEL#" exists?
320 if (defined $check) {
321 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
322 $count{'Undelete'}++;
324 &performReply("did not recover '$faqtoid'. What happened?");
331 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
332 return 'lock: no addr 2' unless ($addressed);
334 my $function = lc $1;
337 if ($faqtoid eq "") {
342 if (&getFactoid($faqtoid) eq "") {
343 &msg($who, "factoid \002$faqtoid\002 does not exist");
347 if ($function eq "lock") {
348 # strongly requested by #debian on 19991028. -xk
349 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
350 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
351 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
357 &CmdUnLock($faqtoid);
364 if ($message =~ s/^rename(\s+|$)//) {
365 return 'rename: no addr' unless ($addressed);
367 if ($message eq "") {
372 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
373 my($from,$to) = (lc $1, lc $2);
375 my $result = &getFactoid($from);
376 if (defined $result) {
377 my $author = &getFactInfo($from, "created_by");
379 if (0 and !&IsFlag("m") or $author !~ /^\Q$who\E\!/i) {
380 &msg($who, "It's not yours to modify.");
384 if ($_ = &getFactoid($to)) {
385 &performReply("destination factoid already exists.");
389 &setFactInfo($from,"factoid_key",$to);
391 &status("rename: <$who> '$from' is now '$to'");
392 &performReply("i renamed '$from' to '$to'");
394 &performReply("i didn't have anything called '$from'");
397 &msg($who,"error: wrong format. ask me about 'help rename'.");
403 # factoid substitution. (X =~ s/A/B/FLAG)
404 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
405 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
406 return 'subst: no addr' unless ($addressed);
409 if ($np =~ /$delim/) {
410 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
415 if (my $result = &getFactoid($faqtoid)) {
416 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
419 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
421 if (length $result > $param{'maxDataSize'}) {
422 &performReply("that's too long");
426 my $faqauth = &getFactInfo($faqtoid, "created_by");
427 if ((length $result)*2 < length $was and
428 &IsFlag("o") ne "o" and
429 &IsHostMask($faqauth) != 2
431 &performReply("too drastic change of factoid.");
434 &setFactInfo($faqtoid, "factoid_value", $result);
435 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
438 &performReply("that doesn't contain '$op'");
441 &performReply("i didn't have anything called '$faqtoid'");
447 # Fix up $message for question.
448 my $question = $message;
451 s/^hey([, ]+)where/where/i;
454 s/where can i find/where is/i;
455 s/how about/where is/i;
458 # clear the string of useless words.
459 s/^(stupid )?q(uestion)?:\s+//i;
460 s/^(does )?(any|ne)(1|one|body) know //i;
462 s/^[uh]+m*[,\.]* +//i;
466 s/^(gee|boy|golly|gosh)([, ]+)//i;
467 s/^(well|and|but|or|yes)([, ]+)//i;
469 s/^o+[hk]+(a+y+)?([,. ]+)//i;
470 s/^g(eez|osh|olly)([,. ]+)//i;
471 s/^w(ow|hee|o+ho+)([,. ]+)//i;
472 s/^heya?,?( folks)?([,. ]+)//i;
475 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
476 $correction_plausible = 1;
477 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
479 $correction_plausible = 0;
482 my $result = &doQuestion($question);
483 if (!defined $result or $result eq $noreply) {
484 return 'result from doQ undef.';
487 if (defined $result and $result !~ /^0?$/) { # question.
488 &status("question: <$who> $message");
489 $count{'Question'}++;
490 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
491 &loadMyModule("perlMath");
492 my $newresult = &perlMath();
494 if (defined $newresult and $newresult ne "") {
495 $cmdstats{'Maths'}++;
496 $result = $newresult;
497 &status("math: <$who> $message => $result");
501 if ($result !~ /^0?$/) {
502 &performStrictReply($result);
506 # why would a friendly bot get passed here?
507 if (&IsParam("friendlyBots")) {
508 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
512 if (!defined &doStatement($message)) {
516 return unless ($addressed);
518 if (length $message > 64) {
519 &status("unparseable-moron: $message");
520 # &performReply( &getRandom(keys %{ $lang{'moron'} }) );
523 &performReply("You are moron \002#". $count{'Moron'} ."\002");
527 &status("unparseable: $message");
528 &performReply( &getRandom(keys %{ $lang{'dunno'} }) );