2 ### Process.pl: Kevin Lenzo 1997-1999
6 # process the incoming message
9 if (&IsParam("useStrict")) { use strict; }
12 $learnok = 0; # Able to learn?
13 $talkok = 0; # Able to yap?
14 $force_public_reply = 0;
16 return 'X' if $who eq $ident; # self-message.
17 return 'addressedother set' if ($addressedother);
19 $talkok = ($param{'addressing'} =~ /^OPTIONAL$/i or $addressed);
20 $learnok = ($param{'learn'} =~ /^HUNGRY$/i or $addressed);
24 # check if we have our head intact.
26 if ($addressed and IsFlag("o") eq "o") {
27 &msg($who, "give me an unlobotomy.");
33 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
34 if ($msgType =~ /public/ and $addressed) {
35 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
36 "while you sent a message to me ${msgType}ly.");
47 # join, must be done before outsider checking.
48 if ($message =~ /^join(\s+(.*))?\s*$/i) {
49 return 'join: not addr' unless ($addressed);
51 $2 =~ /^($mask{chan})(,(\S+))?/;
52 my($thischan, $key) = (lc $1, $3);
53 my $chankey = lc $thischan;
54 $chankey .= " $key" if (defined $key);
56 if ($thischan eq "") {
61 if (&IsFlag("o") ne "o") {
62 if (!exists $chanconf{$thischan}) {
63 &msg($who, "I am not allowed to join $thischan.");
67 if (&validChan($thischan)) {
68 &msg($who,"I'm already on $thischan...");
72 $joinverb{$thischan} = $who; # used for on_join self.
75 &status("JOIN $chankey <$who>");
76 &msg($who, "joining $chankey");
82 if ($msgType =~ /private/ and $message =~ s/^identify//) {
83 $message =~ s/^\s+|\s+$//g;
84 my @array = split / /, $message;
86 if ($who =~ /^_default$/i) {
87 &pSReply("you are too eleet.");
91 if (!scalar @array or scalar @array > 2) {
96 my $do_nick = $array[1] || $who;
98 if (!exists $users{$do_nick}) {
99 &pSReply("nick $do_nick is not in user list.");
103 my $crypt = $users{$do_nick}{PASS};
104 if (!defined $crypt) {
105 &pSReply("user $do_nick has no passwd set.");
109 if (!&ckpasswd($array[0], $crypt)) {
110 &pSReply("invalid passwd for $do_nick.");
114 my $mask = "*!$user@".&makeHostMask($host);
115 ### TODO: prevent adding multiple dupe masks?
116 ### TODO: make &addHostMask() CMD?
117 &pSReply("Added $mask for $do_nick...");
118 $users{$do_nick}{HOSTS}{$mask} = 1;
124 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
127 foreach (keys %channels) {
128 next unless (&IsNickInChan($who,$_));
134 if (!$found and scalar(keys %channels)) {
135 &status("OUTSIDER <$who> $message");
140 # User Processing, for all users.
143 return 'returned from pCH' if &parseCmdHook("main",$message);
145 $retval = &userCommands();
146 return unless (defined $retval);
147 return if ($retval eq $noreply);
151 # once useless messages have been parsed out, we match them.
154 # confused? is this for infobot communications?
155 foreach (keys %{$lang{'confused'}}) {
158 next unless ($message =~ /^\Q$y\E\s*/);
162 # hello. [took me a while to fix this. -xk]
163 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
164 return '' unless ($talkok);
166 # 'mynick: hi' or 'hi mynick' or 'hi'.
167 &status("somebody said hello");
169 # 50% chance of replying to a random greeting when not addressed
170 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
171 &status("not returning unaddressed greeting");
175 # customized random message.
176 my $tmp = (rand() < 0.5) ? ", $who" : "";
177 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
182 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
183 my $reply = &getRandom(keys %{$lang{'howareyou'}});
185 &performReply($reply);
191 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
192 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
194 return 'praise: no addr' unless ($addressed);
196 &status("random praise detected");
198 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
199 &performStrictReply($tmp.":)");
205 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
206 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
208 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
218 if ($msgType =~ /public/ and $message =~ s/^\+//) {
219 &status("found '+' flag; setting msgType to public.");
220 $force_public_reply++;
226 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
227 return '' unless (&hasParam("karma"));
229 my($term,$inc) = (lc $1,$2);
231 if ($msgType !~ /public/i) {
232 &msg($who, "karma must be done in public!");
236 if (lc($term) eq lc($who)) {
237 &msg($who, "please don't karma yourself");
241 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
248 &dbSet("karma", "nick",$term,"karma",$karma);
253 # here's where the external routines get called.
254 # if they return anything but null, that's the "answer".
256 if ( &parseCmdHook("extra",$message) ) {
257 return 'DID SOMETHING IN PCH.';
262 return 'SOMETHING 1';
265 ### FIXME: should this only apply to public messages?
267 &DEBUG("floodwho => '$floodwho'.");
268 delete $flood{$floodwho}{$message};
269 &status("short return due to unknown command.");
274 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
276 } elsif ($param{'DBType'} =~ /^none$/i) {
277 return "NO FACTOIDS.";
279 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
287 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
289 &status("infobot <$nuh> identified") unless $bots{$nuh};
295 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
296 my ($target,$item) = ($1,$2);
299 &status(":INFOBOT:QUERY $who: $message");
301 if ($_ = &getFactoid($item)) {
302 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
305 return 'INFOBOT QUERY';
306 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
307 my ($target,$item) = ($1,$2);
309 &status(":INFOBOT:REPLY $who: $message");
311 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
313 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
314 &msg($target, "$who knew: $lhs $mhs $rhs");
317 $rhs = "<REPLY> are" if ($mhs eq "are");
318 &setFactInfo($lhs, "factoid_value", $rhs);
321 return 'INFOBOT REPLY';
323 &ERROR(":INFOBOT:UNKNOWN $who: $message");
324 return 'INFOBOT UNKNOWN';
330 if ($message =~ s/^forget\s+//i) {
331 return 'forget: no addr' unless ($addressed);
333 my $faqtoid = $message;
334 if ($faqtoid eq "") {
339 $faqtoid =~ tr/A-Z/a-z/;
340 my $result = &getFactoid($faqtoid);
342 if (defined $result) {
343 my $author = &getFactInfo($faqtoid, "created_by");
344 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
345 &msg($who, "you don't have access to remove that factoid");
349 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
351 if (&IsParam("factoidDeleteDelay")) {
352 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
353 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
355 ### delete info. modified_ isn't really used.
356 &setFactInfo($faqtoid, "modified_by", $who);
357 &setFactInfo($faqtoid, "modified_time", time());
359 &status("forget: <$who> '$faqtoid' =is=> '$result'");
360 &delFactoid($faqtoid);
363 &performReply("i forgot $faqtoid");
367 &performReply("i didn't have anything called '$faqtoid'");
373 # factoid unforget/undelete.
374 if ($message =~ s/^un(forget|delete)\s+//i) {
375 return 'unforget: no addr' unless ($addressed);
377 if (!&IsParam("factoidDeleteDelay")) {
378 &performReply("safe delete has been disable so what is there to undelete?");
382 my $faqtoid = $message;
383 if ($faqtoid eq "") {
388 $faqtoid =~ tr/A-Z/a-z/;
389 my $result = &getFactoid($faqtoid." #DEL#");
390 my $check = &getFactoid($faqtoid);
392 if (!defined $result) {
393 &performReply("i didn't have anything ('$faqtoid') to undelete.");
397 if (defined $check) {
398 &performReply("cannot undeleted '$faqtoid' because it already exists?");
402 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
404 ### delete info. modified_ isn't really used.
405 &setFactInfo($faqtoid, "modified_by", "");
406 &setFactInfo($faqtoid, "modified_time", 0);
408 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
410 $count{'Undelete'}++;
416 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
417 return 'lock: no addr 2' unless ($addressed);
419 my $function = lc $1;
422 if ($faqtoid eq "") {
427 # strongly requested by #debian on 19991028. -xk
428 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
429 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
430 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
434 if (&getFactoid($faqtoid) eq "") {
435 &msg($who, "factoid \002$faqtoid\002 does not exist");
439 if ($function eq "lock") {
442 &CmdUnLock($faqtoid);
449 if ($message =~ s/^rename(\s+|$)//) {
450 return 'rename: no addr' unless ($addressed);
452 if ($message eq "") {
457 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
458 my($from,$to) = (lc $1, lc $2);
460 my $result = &getFactoid($from);
461 if (defined $result) {
462 my $author = &getFactInfo($from, "created_by");
463 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
464 &msg($who, "It's not yours to modify.");
468 if ($_ = &getFactoid($to)) {
469 &performReply("destination factoid already exists.");
473 &setFactInfo($from,"factoid_key",$to);
475 &status("rename: <$who> '$from' is now '$to'");
476 &performReply("i renamed '$from' to '$to'");
478 &performReply("i didn't have anything called '$from'");
481 &msg($who,"error: wrong format. ask me about 'help rename'.");
487 # factoid substitution. (X =~ s/A/B/FLAG)
488 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
489 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
490 return 'subst: no addr' unless ($addressed);
493 if ($np =~ /$delim/) {
494 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
499 if (my $result = &getFactoid($faqtoid)) {
500 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
503 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
504 if (length $result > $param{'maxDataSize'}) {
505 &performReply("that's too long");
508 &setFactInfo($faqtoid, "factoid_value", $result);
509 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
512 &performReply("that doesn't contain '$op'");
515 &performReply("i didn't have anything called '$faqtoid'");
522 # Fix up $message for question.
525 s/^hey([, ]+)where/where/i;
527 s/where can i find/where is/i;
528 s/how about/where is/i;
531 # clear the string of useless words.
532 s/^(stupid )?q(uestion)?:\s+//i;
533 s/^(does )?(any|ne)(1|one|body) know //i;
535 s/^[uh]+m*[,\.]* +//i;
539 s/^(gee|boy|golly|gosh)([, ]+)//i;
540 s/^(well|and|but|or|yes)([, ]+)//i;
542 s/^o+[hk]+(a+y+)?([,. ]+)//i;
543 s/^g(eez|osh|olly)([,. ]+)//i;
544 s/^w(ow|hee|o+ho+)([,. ]+)//i;
545 s/^heya?,?( folks)?([,. ]+)//i;
548 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
549 $correction_plausible = 1;
550 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
552 $correction_plausible = 0;
555 my $result = &doQuestion($message);
556 if (!defined $result or $result eq $noreply) {
557 return 'result from doQ undef.';
560 if (defined $result and $result !~ /^0?$/) { # question.
561 &status("question: <$who> $message");
562 $count{'Question'}++;
563 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
564 &loadMyModule("perlMath");
565 my $newresult = &perlMath();
567 if (defined $newresult and $newresult ne "") {
568 $result = $newresult;
569 &status("math: <$who> $message => $result");
573 if ($result !~ /^0?$/) {
574 &performStrictReply($result);
578 # why would a friendly bot get passed here?
579 if (&IsParam("friendlyBots")) {
580 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
584 if (!defined &doStatement($message)) {
588 return unless ($addressed);
590 if (length $message > 64) {
591 &status("unparseable-moron: $message");
592 &performReply( &getRandom(keys %{$lang{'moron'}}) );
597 &status("unparseable: $message");
598 &performReply( &getRandom(keys %{$lang{'dunno'}}) );