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;
17 return 'X' if $who eq $ident; # self-message.
18 return 'addressedother set' if ($addressedother);
20 $talkok = ($param{'addressing'} =~ /^OPTIONAL$/i or $addressed);
21 $learnok = ($param{'learn'} =~ /^HUNGRY$/i or $addressed);
25 # check if we have our head intact.
27 if ($addressed and IsFlag("o") eq "o") {
28 my $delta_time = time() - ($cache{lobotomy}{$who} || 0);
29 &msg($who, "give me an unlobotomy.") if ($delta_time > 60*60);
30 $cache{lobotomy}{$who} = time();
36 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
37 if ($msgType =~ /public/ and $addressed) {
38 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
39 "while you sent a message to me ${msgType}ly.");
45 # join, must be done before outsider checking.
46 if ($message =~ /^join(\s+(.*))?\s*$/i) {
47 return 'join: not addr' unless ($addressed);
49 $2 =~ /^($mask{chan})(,(\S+))?/;
50 my($thischan, $key) = (lc $1, $3);
51 my $chankey = lc $thischan;
52 $chankey .= " $key" if (defined $key);
54 if ($thischan eq "") {
59 if (&IsFlag("o") ne "o") {
60 if (!exists $chanconf{$thischan}) {
61 &msg($who, "I am not allowed to join $thischan.");
65 if (&validChan($thischan)) {
66 &msg($who,"warn: I'm already on $thischan, joining anyway...");
70 $cache{join}{$thischan} = $who; # used for on_join self.
73 &status("JOIN $chankey <$who>");
74 &msg($who, "joining $chankey");
80 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
81 $message =~ s/^\s+|\s+$//g;
82 my @array = split / /, $message;
84 if ($who =~ /^_default$/i) {
85 &pSReply("you are too eleet.");
89 if (!scalar @array or scalar @array > 2) {
94 my $do_nick = $array[1] || $who;
96 if (!exists $users{$do_nick}) {
97 &pSReply("nick $do_nick is not in user list.");
101 my $crypt = $users{$do_nick}{PASS};
102 if (!defined $crypt) {
103 &pSReply("user $do_nick has no passwd set.");
107 if (!&ckpasswd($array[0], $crypt)) {
108 &pSReply("invalid passwd for $do_nick.");
112 my $mask = "*!$user@".&makeHostMask($host);
113 ### TODO: prevent adding multiple dupe masks?
114 ### TODO: make &addHostMask() CMD?
115 &pSReply("Added $mask for $do_nick...");
116 $users{$do_nick}{HOSTS}{$mask} = 1;
122 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
123 $message =~ s/^\s+|\s+$//g;
124 my @array = split ' ', $message;
126 if ($who =~ /^_default$/i) {
127 &pSReply("you are too eleet.");
131 if (scalar @array != 1) {
136 # todo: use &getUser()?
138 foreach (keys %users) {
139 if ($users{$_}{FLAGS} =~ /n/) {
145 if (!exists $users{$who} and !$first) {
146 &pSReply("nick $who is not in user list.");
151 &pSReply("First time user... adding you as Master.");
152 $users{$who}{FLAGS} = "mrsteon";
155 my $crypt = $users{$who}{PASS};
156 if (defined $crypt) {
157 &pSReply("user $who already has pass set.");
161 if (!defined $host) {
162 &WARN("pass: host == NULL.");
166 if (!scalar keys %{ $users{$who}{HOSTS} }) {
167 my $mask = "*!$user@".&makeHostMask($host);
168 &pSReply("Added hostmask '\002$mask\002' to $who");
169 $users{$who}{HOSTS}{$mask} = 1;
172 $crypt = &mkcrypt($array[0]);
173 $users{$who}{PASS} = $crypt;
174 &pSReply("new pass for $who, crypt $crypt.");
180 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
183 foreach (keys %channels) {
184 next unless (&IsNickInChan($who,$_));
190 if (!$found and scalar(keys %channels)) {
191 &status("OUTSIDER <$who> $message");
197 if ($msgType =~ /public/ and $message =~ s/^\+//) {
198 &status("Process: '+' flag detected; changing reply to public");
200 $who = $chan; # major hack to fix &msg().
201 $force_public_reply++;
202 # notice is still NOTICE but to whole channel => good.
205 # User Processing, for all users.
208 return 'returned from pCH' if &parseCmdHook("main",$message);
210 $retval = &userCommands();
211 return unless (defined $retval);
212 return if ($retval eq $noreply);
216 # once useless messages have been parsed out, we match them.
219 # confused? is this for infobot communications?
220 foreach (keys %{ $lang{'confused'} }) {
223 next unless ($message =~ /^\Q$y\E\s*/);
227 # hello. [took me a while to fix this. -xk]
228 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
229 return '' unless ($talkok);
231 # 'mynick: hi' or 'hi mynick' or 'hi'.
232 &status("somebody said hello");
234 # 50% chance of replying to a random greeting when not addressed
235 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
236 &status("not returning unaddressed greeting");
240 # customized random message.
241 my $tmp = (rand() < 0.5) ? ", $who" : "";
242 &performStrictReply(&getRandom(keys %{ $lang{'hello'} }) . $tmp);
247 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
248 my $reply = &getRandom(keys %{ $lang{'howareyou'} });
250 &performReply($reply);
256 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
257 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
259 return 'praise: no addr' unless ($addressed);
261 &status("random praise detected");
263 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
264 &performStrictReply($tmp.":)");
270 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
271 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
273 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
282 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
283 return '' unless (&hasParam("karma"));
285 my($term,$inc) = (lc $1,$2);
287 if ($msgType !~ /public/i) {
288 &msg($who, "karma must be done in public!");
292 if (lc $term eq lc $who) {
293 &msg($who, "please don't karma yourself");
297 my $karma = &dbGet("stats", "counter", "nick='$term' and type='karma'") || 0;
305 { nick => $term, type => "karma" },
306 { counter => $karma }
312 # here's where the external routines get called.
313 # if they return anything but null, that's the "answer".
315 if ( &parseCmdHook("extra",$message) ) {
316 return 'DID SOMETHING IN PCH.';
321 return 'SOMETHING 1';
324 if (0 and $addrchar) {
325 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
330 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
332 } elsif ($param{'DBType'} =~ /^none$/i) {
333 return "NO FACTOIDS.";
335 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
343 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
345 &status("infobot <$nuh> identified") unless $bots{$nuh};
351 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
352 my ($target,$item) = ($1,$2);
355 &status(":INFOBOT:QUERY $who: $message");
357 if ($_ = &getFactoid($item)) {
358 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
361 return 'INFOBOT QUERY';
362 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
363 my ($target,$item) = ($1,$2);
365 &status(":INFOBOT:REPLY $who: $message");
367 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
369 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
370 &msg($target, "$who knew: $lhs $mhs $rhs");
373 $rhs = "<REPLY> are" if ($mhs eq "are");
374 &setFactInfo($lhs, "factoid_value", $rhs);
377 return 'INFOBOT REPLY';
379 &ERROR(":INFOBOT:UNKNOWN $who: $message");
380 return 'INFOBOT UNKNOWN';
385 if ($message =~ s/^forget\s+//i) {
386 return 'forget: no addr' unless ($addressed);
388 my $faqtoid = $message;
389 if ($faqtoid eq "") {
394 $faqtoid =~ tr/A-Z/a-z/;
395 my $result = &getFactoid($faqtoid);
397 if (defined $result) {
398 my $author = &getFactInfo($faqtoid, "created_by");
399 my $count = &getFactInfo($faqtoid, "requested_count") || 0;
400 my $limit = &getChanConfDefault("factoidPreventForgetLimit",
403 if (IsFlag("r") ne "r") {
404 &msg($who, "you don't have access to remove factoids");
408 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
410 # factoidPreventForgetLimit:
411 if ($limit and $count > $limit and (&IsFlag("o") ne "o")) {
412 &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)");
416 if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
417 if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) {
418 &msg($who, "cannot delete it ($faqtoid).");
422 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
423 ### TODO: check if the "backup" exists and overwrite it
424 my $check = &getFactoid("$faqtoid #DEL#");
426 if (!defined $check or $check =~ /^\s*$/) {
427 if ($faqtoid !~ / #DEL#$/) {
428 my $new = $faqtoid." #DEL#";
429 &DEBUG("Process: backing up $faqtoid to '$new'.");
431 # this looks weird but does it work?
432 &setFactInfo($faqtoid, "factoid_key", $new);
433 &setFactInfo($new, "modified_by", $who);
434 &setFactInfo($new, "modified_time", time());
437 &status("not backing up $faqtoid.");
441 &status("forget: not overwriting backup!");
445 &status("forget: <$who> '$faqtoid' =is=> '$result'");
447 &delFactoid($faqtoid);
449 &performReply("i forgot $faqtoid");
453 &performReply("i didn't have anything called '$faqtoid'");
459 # factoid unforget/undelete.
460 if ($message =~ s/^un(forget|delete)\s+//i) {
461 return 'unforget: no addr' unless ($addressed);
464 $i++ if (&IsParam("factoidDeleteDelay"));
465 $i++ if (&IsChanConf("factoidDeleteDelay"));
467 &performReply("safe delete has been disable so what is there to undelete?");
471 my $faqtoid = $message;
472 if ($faqtoid eq "") {
477 $faqtoid =~ tr/A-Z/a-z/;
478 my $result = &getFactoid($faqtoid." #DEL#");
479 my $check = &getFactoid($faqtoid);
481 if (!defined $result) {
482 &performReply("i didn't have anything ('$faqtoid') to undelete.");
486 if (defined $check) {
487 &performReply("cannot undeleted '$faqtoid' because it already exists?");
491 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
493 ### delete info. modified_ isn't really used.
494 &setFactInfo($faqtoid, "modified_by", "");
495 &setFactInfo($faqtoid, "modified_time", 0);
497 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
499 $count{'Undelete'}++;
505 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
506 return 'lock: no addr 2' unless ($addressed);
508 my $function = lc $1;
511 if ($faqtoid eq "") {
516 if (&getFactoid($faqtoid) eq "") {
517 &msg($who, "factoid \002$faqtoid\002 does not exist");
521 if ($function eq "lock") {
522 # strongly requested by #debian on 19991028. -xk
523 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
524 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
525 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
531 &CmdUnLock($faqtoid);
538 if ($message =~ s/^rename(\s+|$)//) {
539 return 'rename: no addr' unless ($addressed);
541 if ($message eq "") {
546 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
547 my($from,$to) = (lc $1, lc $2);
549 my $result = &getFactoid($from);
550 if (defined $result) {
551 my $author = &getFactInfo($from, "created_by");
553 if (&IsFlag("m") or $author =~ /^\Q$who\E\!/i) {
554 &msg($who, "It's not yours to modify.");
558 if ($_ = &getFactoid($to)) {
559 &performReply("destination factoid already exists.");
563 &setFactInfo($from,"factoid_key",$to);
565 &status("rename: <$who> '$from' is now '$to'");
566 &performReply("i renamed '$from' to '$to'");
568 &performReply("i didn't have anything called '$from'");
571 &msg($who,"error: wrong format. ask me about 'help rename'.");
577 # factoid substitution. (X =~ s/A/B/FLAG)
578 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
579 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
580 return 'subst: no addr' unless ($addressed);
583 if ($np =~ /$delim/) {
584 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
589 if (my $result = &getFactoid($faqtoid)) {
590 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
593 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
594 if (length $result > $param{'maxDataSize'}) {
595 &performReply("that's too long");
598 &setFactInfo($faqtoid, "factoid_value", $result);
599 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
602 &performReply("that doesn't contain '$op'");
605 &performReply("i didn't have anything called '$faqtoid'");
611 # Fix up $message for question.
612 my $question = $message;
615 s/^hey([, ]+)where/where/i;
618 s/where can i find/where is/i;
619 s/how about/where is/i;
622 # clear the string of useless words.
623 s/^(stupid )?q(uestion)?:\s+//i;
624 s/^(does )?(any|ne)(1|one|body) know //i;
626 s/^[uh]+m*[,\.]* +//i;
630 s/^(gee|boy|golly|gosh)([, ]+)//i;
631 s/^(well|and|but|or|yes)([, ]+)//i;
633 s/^o+[hk]+(a+y+)?([,. ]+)//i;
634 s/^g(eez|osh|olly)([,. ]+)//i;
635 s/^w(ow|hee|o+ho+)([,. ]+)//i;
636 s/^heya?,?( folks)?([,. ]+)//i;
639 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
640 $correction_plausible = 1;
641 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
643 $correction_plausible = 0;
646 my $result = &doQuestion($question);
647 if (!defined $result or $result eq $noreply) {
648 return 'result from doQ undef.';
651 if (defined $result and $result !~ /^0?$/) { # question.
652 &status("question: <$who> $message");
653 $count{'Question'}++;
654 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
655 &loadMyModule("perlMath");
656 my $newresult = &perlMath();
658 if (defined $newresult and $newresult ne "") {
659 $cmdstats{'Maths'}++;
660 $result = $newresult;
661 &status("math: <$who> $message => $result");
665 if ($result !~ /^0?$/) {
666 &performStrictReply($result);
670 # why would a friendly bot get passed here?
671 if (&IsParam("friendlyBots")) {
672 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
676 if (!defined &doStatement($message)) {
680 return unless ($addressed);
682 if (length $message > 64) {
683 &status("unparseable-moron: $message");
684 # &performReply( &getRandom(keys %{ $lang{'moron'} }) );
687 &performReply("You are moron #".$count{'Moron'}."!");
691 &status("unparseable: $message");
692 &performReply( &getRandom(keys %{ $lang{'dunno'} }) );