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()?
137 my $first = (scalar keys %users) ? 1 : 0;
138 if (!exists $users{$who} and !$first) {
139 &pSReply("nick $who is not in user list.");
144 &pSReply("first time user... adding you as master.");
145 $users{$who}{FLAGS} = "mrsteon";
148 my $crypt = $users{$who}{PASS};
149 if (defined $crypt) {
150 &pSReply("user $who already has pass set.");
154 if (!defined $host) {
155 &WARN("pass: host == NULL.");
159 if (!scalar keys %{ $users{$who}{HOSTS} }) {
160 my $mask = "*!$user@".&makeHostMask($host);
161 &pSReply("added mask $mask to $who.");
162 $users{$who}{HOSTS}{$mask} = 1;
165 $crypt = &mkcrypt($array[0]);
166 $users{$who}{PASS} = $crypt;
167 &pSReply("new pass for $who, crypt $crypt.");
173 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
176 foreach (keys %channels) {
177 next unless (&IsNickInChan($who,$_));
183 if (!$found and scalar(keys %channels)) {
184 &status("OUTSIDER <$who> $message");
190 if ($msgType =~ /public/ and $message =~ s/^\+//) {
191 &status("Process: '+' flag detected; changing reply to public");
193 $who = $chan; # major hack to fix &msg().
194 $force_public_reply++;
195 # notice is still NOTICE but to whole channel => good.
198 # User Processing, for all users.
201 return 'returned from pCH' if &parseCmdHook("main",$message);
203 $retval = &userCommands();
204 return unless (defined $retval);
205 return if ($retval eq $noreply);
209 # once useless messages have been parsed out, we match them.
212 # confused? is this for infobot communications?
213 foreach (keys %{ $lang{'confused'} }) {
216 next unless ($message =~ /^\Q$y\E\s*/);
220 # hello. [took me a while to fix this. -xk]
221 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
222 return '' unless ($talkok);
224 # 'mynick: hi' or 'hi mynick' or 'hi'.
225 &status("somebody said hello");
227 # 50% chance of replying to a random greeting when not addressed
228 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
229 &status("not returning unaddressed greeting");
233 # customized random message.
234 my $tmp = (rand() < 0.5) ? ", $who" : "";
235 &performStrictReply(&getRandom(keys %{ $lang{'hello'} }) . $tmp);
240 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
241 my $reply = &getRandom(keys %{ $lang{'howareyou'} });
243 &performReply($reply);
249 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
250 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
252 return 'praise: no addr' unless ($addressed);
254 &status("random praise detected");
256 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
257 &performStrictReply($tmp.":)");
263 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
264 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
266 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
274 if ($message =~ s/^literal\s+//i) {
275 &status("literal ask of '$message'.");
280 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
281 return '' unless (&hasParam("karma"));
283 my($term,$inc) = (lc $1,$2);
285 if ($msgType !~ /public/i) {
286 &msg($who, "karma must be done in public!");
290 if (lc($term) eq lc($who)) {
291 &msg($who, "please don't karma yourself");
295 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
302 &dbSet("karma", "nick",$term,"karma",$karma);
307 # here's where the external routines get called.
308 # if they return anything but null, that's the "answer".
310 if ( &parseCmdHook("extra",$message) ) {
311 return 'DID SOMETHING IN PCH.';
316 return 'SOMETHING 1';
319 if (0 and $addrchar) {
320 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
325 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
327 } elsif ($param{'DBType'} =~ /^none$/i) {
328 return "NO FACTOIDS.";
330 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
338 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
340 &status("infobot <$nuh> identified") unless $bots{$nuh};
346 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
347 my ($target,$item) = ($1,$2);
350 &status(":INFOBOT:QUERY $who: $message");
352 if ($_ = &getFactoid($item)) {
353 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
356 return 'INFOBOT QUERY';
357 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
358 my ($target,$item) = ($1,$2);
360 &status(":INFOBOT:REPLY $who: $message");
362 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
364 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
365 &msg($target, "$who knew: $lhs $mhs $rhs");
368 $rhs = "<REPLY> are" if ($mhs eq "are");
369 &setFactInfo($lhs, "factoid_value", $rhs);
372 return 'INFOBOT REPLY';
374 &ERROR(":INFOBOT:UNKNOWN $who: $message");
375 return 'INFOBOT UNKNOWN';
380 if ($message =~ s/^forget\s+//i) {
381 return 'forget: no addr' unless ($addressed);
383 my $faqtoid = $message;
384 if ($faqtoid eq "") {
389 $faqtoid =~ tr/A-Z/a-z/;
390 my $result = &getFactoid($faqtoid);
392 if (defined $result) {
393 my $author = &getFactInfo($faqtoid, "created_by");
394 if (IsFlag("r") ne "r") {
395 &msg($who, "you don't have access to remove factoids");
399 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
401 if (&IsParam("factoidDeleteDelay")) {
402 if ($faqtoid =~ /#DEL#/ and !&IsFlag("o")) {
403 &msg($who, "cannot delete it ($faqtoid).");
406 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
407 ### TODO: check if the "backup" exists and overwrite it
408 my $check = &getFactoid("$faqtoid #DEL#");
410 if ($faqtoid !~ /#DEL#/) {
411 my $new = $faqtoid." #DEL#";
412 &setFactInfo($faqtoid, "factoid_key", $new);
413 &setFactInfo($new, "modified_by", $who);
414 &setFactInfo($new, "modified_time", time());
416 &status("not backing up $faqtoid.");
419 &status("forget: not overwriting backup!");
422 &status("forget: <$who> '$faqtoid' =is=> '$result'");
424 &delFactoid($faqtoid);
426 &performReply("i forgot $faqtoid");
430 &performReply("i didn't have anything called '$faqtoid'");
436 # factoid unforget/undelete.
437 if ($message =~ s/^un(forget|delete)\s+//i) {
438 return 'unforget: no addr' unless ($addressed);
440 if (!&IsParam("factoidDeleteDelay")) {
441 &performReply("safe delete has been disable so what is there to undelete?");
445 my $faqtoid = $message;
446 if ($faqtoid eq "") {
451 $faqtoid =~ tr/A-Z/a-z/;
452 my $result = &getFactoid($faqtoid." #DEL#");
453 my $check = &getFactoid($faqtoid);
455 if (!defined $result) {
456 &performReply("i didn't have anything ('$faqtoid') to undelete.");
460 &DEBUG("unforget: check => $check");
461 if (defined $check) {
462 &performReply("cannot undeleted '$faqtoid' because it already exists?");
466 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
468 ### delete info. modified_ isn't really used.
469 &setFactInfo($faqtoid, "modified_by", "");
470 &setFactInfo($faqtoid, "modified_time", 0);
472 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
474 $count{'Undelete'}++;
480 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
481 return 'lock: no addr 2' unless ($addressed);
483 my $function = lc $1;
486 if ($faqtoid eq "") {
491 if (&getFactoid($faqtoid) eq "") {
492 &msg($who, "factoid \002$faqtoid\002 does not exist");
496 if ($function eq "lock") {
497 # strongly requested by #debian on 19991028. -xk
498 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
499 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
500 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
506 &CmdUnLock($faqtoid);
513 if ($message =~ s/^rename(\s+|$)//) {
514 return 'rename: no addr' unless ($addressed);
516 if ($message eq "") {
521 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
522 my($from,$to) = (lc $1, lc $2);
524 my $result = &getFactoid($from);
525 if (defined $result) {
526 my $author = &getFactInfo($from, "created_by");
528 if (&IsFlag("m") or $author =~ /^\Q$who\E\!/i) {
529 &msg($who, "It's not yours to modify.");
533 if ($_ = &getFactoid($to)) {
534 &performReply("destination factoid already exists.");
538 &setFactInfo($from,"factoid_key",$to);
540 &status("rename: <$who> '$from' is now '$to'");
541 &performReply("i renamed '$from' to '$to'");
543 &performReply("i didn't have anything called '$from'");
546 &msg($who,"error: wrong format. ask me about 'help rename'.");
552 # factoid substitution. (X =~ s/A/B/FLAG)
553 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
554 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
555 return 'subst: no addr' unless ($addressed);
558 if ($np =~ /$delim/) {
559 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
564 if (my $result = &getFactoid($faqtoid)) {
565 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
568 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
569 if (length $result > $param{'maxDataSize'}) {
570 &performReply("that's too long");
573 &setFactInfo($faqtoid, "factoid_value", $result);
574 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
577 &performReply("that doesn't contain '$op'");
580 &performReply("i didn't have anything called '$faqtoid'");
586 # Fix up $message for question.
587 my $question = $message;
590 s/^hey([, ]+)where/where/i;
593 s/where can i find/where is/i;
594 s/how about/where is/i;
597 # clear the string of useless words.
598 s/^(stupid )?q(uestion)?:\s+//i;
599 s/^(does )?(any|ne)(1|one|body) know //i;
601 s/^[uh]+m*[,\.]* +//i;
605 s/^(gee|boy|golly|gosh)([, ]+)//i;
606 s/^(well|and|but|or|yes)([, ]+)//i;
608 s/^o+[hk]+(a+y+)?([,. ]+)//i;
609 s/^g(eez|osh|olly)([,. ]+)//i;
610 s/^w(ow|hee|o+ho+)([,. ]+)//i;
611 s/^heya?,?( folks)?([,. ]+)//i;
614 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
615 $correction_plausible = 1;
616 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
618 $correction_plausible = 0;
621 my $result = &doQuestion($question);
622 if (!defined $result or $result eq $noreply) {
623 return 'result from doQ undef.';
626 if (defined $result and $result !~ /^0?$/) { # question.
627 &status("question: <$who> $message");
628 $count{'Question'}++;
629 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
630 &loadMyModule("perlMath");
631 my $newresult = &perlMath();
633 if (defined $newresult and $newresult ne "") {
634 $cmdstats{'Maths'}++;
635 $result = $newresult;
636 &status("math: <$who> $message => $result");
640 if ($result !~ /^0?$/) {
641 &performStrictReply($result);
645 # why would a friendly bot get passed here?
646 if (&IsParam("friendlyBots")) {
647 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
651 if (!defined &doStatement($message)) {
655 return unless ($addressed);
657 if (length $message > 64) {
658 &status("unparseable-moron: $message");
659 &performReply( &getRandom(keys %{ $lang{'moron'} }) );
664 &status("unparseable: $message");
665 &performReply( &getRandom(keys %{ $lang{'dunno'} }) );