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=".&dbQuote($term).
298 " AND type='karma'") || 0;
306 { nick => $term, type => "karma" },
307 { counter => $karma }
313 # here's where the external routines get called.
314 # if they return anything but null, that's the "answer".
316 if ( &parseCmdHook("extra",$message) ) {
317 return 'DID SOMETHING IN PCH.';
322 return 'SOMETHING 1';
325 if (0 and $addrchar) {
326 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
331 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
333 } elsif ($param{'DBType'} =~ /^none$/i) {
334 return "NO FACTOIDS.";
336 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
344 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
346 &status("infobot <$nuh> identified") unless $bots{$nuh};
352 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
353 my ($target,$item) = ($1,$2);
356 &status(":INFOBOT:QUERY $who: $message");
358 if ($_ = &getFactoid($item)) {
359 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
362 return 'INFOBOT QUERY';
363 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
364 my ($target,$item) = ($1,$2);
366 &status(":INFOBOT:REPLY $who: $message");
368 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
370 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
371 &msg($target, "$who knew: $lhs $mhs $rhs");
374 $rhs = "<REPLY> are" if ($mhs eq "are");
375 &setFactInfo($lhs, "factoid_value", $rhs);
378 return 'INFOBOT REPLY';
380 &ERROR(":INFOBOT:UNKNOWN $who: $message");
381 return 'INFOBOT UNKNOWN';
386 if ($message =~ s/^forget\s+//i) {
387 return 'forget: no addr' unless ($addressed);
389 my $faqtoid = $message;
390 if ($faqtoid eq "") {
395 $faqtoid =~ tr/A-Z/a-z/;
396 my $result = &getFactoid($faqtoid);
398 if (defined $result) {
399 my $author = &getFactInfo($faqtoid, "created_by");
400 my $count = &getFactInfo($faqtoid, "requested_count") || 0;
401 my $limit = &getChanConfDefault("factoidPreventForgetLimit",
404 &DEBUG("forget: limit = $limit");
405 &DEBUG("forget: count = $count");
407 if (IsFlag("r") ne "r") {
408 &msg($who, "you don't have access to remove factoids");
412 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
414 # factoidPreventForgetLimit:
415 if ($limit and $count > $limit and (&IsFlag("o") ne "o")) {
416 &msg($who, "will not delete '$faqtoid', count > limit ($count > $limit)");
420 if (&IsParam("factoidDeleteDelay") or &IsChanConf("factoidDeleteDelay")) {
421 if ($faqtoid =~ / #DEL#$/ and !&IsFlag("o")) {
422 &msg($who, "cannot delete it ($faqtoid).");
426 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
427 ### TODO: check if the "backup" exists and overwrite it
428 my $check = &getFactoid("$faqtoid #DEL#");
430 if (!defined $check or $check =~ /^\s*$/) {
431 if ($faqtoid !~ / #DEL#$/) {
432 my $new = $faqtoid." #DEL#";
434 my $backup = &getFactoid($faqtoid);
435 # this looks weird but does it work?
437 &DEBUG("forget: not overwriting backup: $faqtoid");
439 &status("forget: backing up '$faqtoid'");
440 &setFactInfo($faqtoid, "factoid_key", $new);
441 &setFactInfo($new, "modified_by", $who);
442 &setFactInfo($new, "modified_time", time());
446 &status("forget: not backing up $faqtoid.");
450 &status("forget: not overwriting backup!");
454 &status("forget: <$who> '$faqtoid' =is=> '$result'");
456 &delFactoid($faqtoid);
458 &performReply("i forgot $faqtoid");
462 &performReply("i didn't have anything called '$faqtoid'");
468 # factoid unforget/undelete.
469 if ($message =~ s/^un(forget|delete)\s+//i) {
470 return 'unforget: no addr' unless ($addressed);
473 $i++ if (&IsParam("factoidDeleteDelay"));
474 $i++ if (&IsChanConf("factoidDeleteDelay"));
476 &performReply("safe delete has been disable so what is there to undelete?");
480 my $faqtoid = $message;
481 if ($faqtoid eq "") {
486 $faqtoid =~ tr/A-Z/a-z/;
487 my $result = &getFactoid($faqtoid." #DEL#");
488 my $check = &getFactoid($faqtoid);
490 if (!defined $result) {
491 &performReply("i didn't have anything ('$faqtoid') to undelete.");
495 if (defined $check) {
496 &performReply("cannot undeleted '$faqtoid' because it already exists?");
500 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
502 ### delete info. modified_ isn't really used.
503 &setFactInfo($faqtoid, "modified_by", "");
504 &setFactInfo($faqtoid, "modified_time", 0);
506 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
508 $count{'Undelete'}++;
514 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
515 return 'lock: no addr 2' unless ($addressed);
517 my $function = lc $1;
520 if ($faqtoid eq "") {
525 if (&getFactoid($faqtoid) eq "") {
526 &msg($who, "factoid \002$faqtoid\002 does not exist");
530 if ($function eq "lock") {
531 # strongly requested by #debian on 19991028. -xk
532 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
533 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
534 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
540 &CmdUnLock($faqtoid);
547 if ($message =~ s/^rename(\s+|$)//) {
548 return 'rename: no addr' unless ($addressed);
550 if ($message eq "") {
555 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
556 my($from,$to) = (lc $1, lc $2);
558 my $result = &getFactoid($from);
559 if (defined $result) {
560 my $author = &getFactInfo($from, "created_by");
562 if (&IsFlag("m") or $author =~ /^\Q$who\E\!/i) {
563 &msg($who, "It's not yours to modify.");
567 if ($_ = &getFactoid($to)) {
568 &performReply("destination factoid already exists.");
572 &setFactInfo($from,"factoid_key",$to);
574 &status("rename: <$who> '$from' is now '$to'");
575 &performReply("i renamed '$from' to '$to'");
577 &performReply("i didn't have anything called '$from'");
580 &msg($who,"error: wrong format. ask me about 'help rename'.");
586 # factoid substitution. (X =~ s/A/B/FLAG)
587 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
588 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
589 return 'subst: no addr' unless ($addressed);
592 if ($np =~ /$delim/) {
593 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
598 if (my $result = &getFactoid($faqtoid)) {
599 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
602 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
603 if (length $result > $param{'maxDataSize'}) {
604 &performReply("that's too long");
607 &setFactInfo($faqtoid, "factoid_value", $result);
608 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
611 &performReply("that doesn't contain '$op'");
614 &performReply("i didn't have anything called '$faqtoid'");
620 # Fix up $message for question.
621 my $question = $message;
624 s/^hey([, ]+)where/where/i;
627 s/where can i find/where is/i;
628 s/how about/where is/i;
631 # clear the string of useless words.
632 s/^(stupid )?q(uestion)?:\s+//i;
633 s/^(does )?(any|ne)(1|one|body) know //i;
635 s/^[uh]+m*[,\.]* +//i;
639 s/^(gee|boy|golly|gosh)([, ]+)//i;
640 s/^(well|and|but|or|yes)([, ]+)//i;
642 s/^o+[hk]+(a+y+)?([,. ]+)//i;
643 s/^g(eez|osh|olly)([,. ]+)//i;
644 s/^w(ow|hee|o+ho+)([,. ]+)//i;
645 s/^heya?,?( folks)?([,. ]+)//i;
648 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
649 $correction_plausible = 1;
650 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
652 $correction_plausible = 0;
655 my $result = &doQuestion($question);
656 if (!defined $result or $result eq $noreply) {
657 return 'result from doQ undef.';
660 if (defined $result and $result !~ /^0?$/) { # question.
661 &status("question: <$who> $message");
662 $count{'Question'}++;
663 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
664 &loadMyModule("perlMath");
665 my $newresult = &perlMath();
667 if (defined $newresult and $newresult ne "") {
668 $cmdstats{'Maths'}++;
669 $result = $newresult;
670 &status("math: <$who> $message => $result");
674 if ($result !~ /^0?$/) {
675 &performStrictReply($result);
679 # why would a friendly bot get passed here?
680 if (&IsParam("friendlyBots")) {
681 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
685 if (!defined &doStatement($message)) {
689 return unless ($addressed);
691 if (length $message > 64) {
692 &status("unparseable-moron: $message");
693 # &performReply( &getRandom(keys %{ $lang{'moron'} }) );
696 &performReply("You are moron \002#". $count{'Moron'} ."\002");
700 &status("unparseable: $message");
701 &performReply( &getRandom(keys %{ $lang{'dunno'} }) );