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 = $thischan;
54 $chankey .= " $key" if (defined $key);
56 if ($thischan eq "") {
61 # Thanks to Eden Li (tile) for the channel key patch
62 my @chans = split(/[\s\t]+/, $param{'join_channels'});
63 if (!grep /^$thischan$/i, @chans) {
64 if (&IsFlag("o") ne "o") {
65 &msg($who, "I am not allowed to join $thischan.");
70 if (&validChan($thischan) and &IsFlag("o") ne "o") {
71 &msg($who,"I'm already on $thischan...");
74 $joinverb{$thischan} = $who; # used for on_join self.
77 &status("JOIN $chankey <$who>");
78 &msg($who, "joining $chankey");
84 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
87 foreach (keys %channels) {
88 next unless (&IsNickInChan($who,$_));
94 if (!$found and scalar(keys %channels)) {
95 &status("OUTSIDER <$who> $message");
100 # User Processing, for all users.
103 return 'returned from pCH' if &parseCmdHook("main",$message);
105 $retval = &userCommands();
106 return unless (defined $retval);
107 return if ($retval eq $noreply);
111 if ($msgType =~ /private/ and $message =~ s/^identify//) {
112 $message =~ s/^\s+|\s+$//g;
113 my @array = split / /, $message;
115 if ($who =~ /^_default$/i) {
116 &pSReply("you are too eleet.");
120 if (!scalar @array or scalar @array > 2) {
125 my $do_nick = $array[1] || $who;
127 if (!exists $users{$do_nick}) {
128 &pSReply("nick $do_nick is not in user list.");
132 my $crypt = $users{$do_nick}{PASS};
133 if (!defined $crypt) {
134 &pSReply("user $do_nick has no passwd set.");
138 if (!&ckpass($array[0], $crypt)) {
139 &pSReply("invalid passwd for $do_nick.");
143 my $mask = "*!$user@".&makeHostMask($host);
144 ### TODO: prevent adding multiple dupe masks?
145 ### TODO: make &addHostMask() CMD?
146 &pSReply("Added $mask for $do_nick...");
147 $users{$do_nick}{HOSTS}{$mask} = 1;
153 # once useless messages have been parsed out, we match them.
156 # confused? is this for infobot communications?
157 foreach (keys %{$lang{'confused'}}) {
160 next unless ($message =~ /^\Q$y\E\s*/);
164 # hello. [took me a while to fix this. -xk]
165 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
166 return '' unless ($talkok);
168 # 'mynick: hi' or 'hi mynick' or 'hi'.
169 &status("somebody said hello");
171 # 50% chance of replying to a random greeting when not addressed
172 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
173 &status("not returning unaddressed greeting");
177 # customized random message.
178 my $tmp = (rand() < 0.5) ? ", $who" : "";
179 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
184 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
185 my $reply = &getRandom(keys %{$lang{'howareyou'}});
187 &performReply($reply);
193 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
194 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
196 return 'praise: no addr' unless ($addressed);
198 &status("random praise detected");
200 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
201 &performStrictReply($tmp.":)");
207 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
208 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
209 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
211 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
221 if ($msgType =~ /public/ and $message =~ s/^\+//) {
222 &status("found '+' flag; setting msgType to public.");
223 $force_public_reply++;
229 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
230 return '' unless (&hasParam("karma"));
232 my($term,$inc) = (lc $1,$2);
234 if ($msgType !~ /public/i) {
235 &msg($who, "karma must be done in public!");
239 if (lc($term) eq lc($who)) {
240 &msg($who, "please don't karma yourself");
244 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
251 &dbSet("karma", "nick",$term,"karma",$karma);
256 # here's where the external routines get called.
257 # if they return anything but null, that's the "answer".
259 if ( &parseCmdHook("extra",$message) ) {
260 return 'DID SOMETHING IN PCH.';
265 return 'SOMETHING 1';
268 ### FIXME: should this only apply to public messages?
270 &DEBUG("floodwho => '$floodwho'.");
271 delete $flood{$floodwho}{$message};
272 &status("short return due to unknown command.");
277 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
279 } elsif ($param{'DBType'} =~ /^none$/i) {
280 return "NO FACTOIDS.";
282 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
290 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
292 &status("infobot <$nuh> identified") unless $bots{$nuh};
298 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
299 my ($target,$item) = ($1,$2);
302 &status(":INFOBOT:QUERY $who: $message");
304 if ($_ = &getFactoid($item)) {
305 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
308 return 'INFOBOT QUERY';
309 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
310 my ($target,$item) = ($1,$2);
312 &status(":INFOBOT:REPLY $who: $message");
314 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
316 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
317 &msg($target, "$who knew: $lhs $mhs $rhs");
320 $rhs = "<REPLY> are" if ($mhs eq "are");
321 &setFactInfo($lhs, "factoid_value", $rhs);
324 return 'INFOBOT REPLY';
326 &ERROR(":INFOBOT:UNKNOWN $who: $message");
327 return 'INFOBOT UNKNOWN';
333 if ($message =~ s/^forget\s+//i) {
334 return 'forget: no addr' unless ($addressed);
336 my $faqtoid = $message;
337 if ($faqtoid eq "") {
342 $faqtoid =~ tr/A-Z/a-z/;
343 my $result = &getFactoid($faqtoid);
345 if (defined $result) {
346 my $author = &getFactInfo($faqtoid, "created_by");
347 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
348 &msg($who, "you don't have access to remove that factoid");
352 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
354 if (&IsParam("factoidDeleteDelay")) {
355 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
356 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
358 ### delete info. modified_ isn't really used.
359 &setFactInfo($faqtoid, "modified_by", $who);
360 &setFactInfo($faqtoid, "modified_time", time());
362 &status("forget: <$who> '$faqtoid' =is=> '$result'");
363 &delFactoid($faqtoid);
366 &performReply("i forgot $faqtoid");
370 &performReply("i didn't have anything called '$faqtoid'");
376 # factoid unforget/undelete.
377 if ($message =~ s/^un(forget|delete)\s+//i) {
378 return 'unforget: no addr' unless ($addressed);
380 if (!&IsParam("factoidDeleteDelay")) {
381 &performReply("safe delete has been disable so what is there to undelete?");
385 my $faqtoid = $message;
386 if ($faqtoid eq "") {
391 $faqtoid =~ tr/A-Z/a-z/;
392 my $result = &getFactoid($faqtoid." #DEL#");
393 my $check = &getFactoid($faqtoid);
395 if (!defined $result) {
396 &performReply("i didn't have anything ('$faqtoid') to undelete.");
400 if (defined $check) {
401 &performReply("cannot undeleted '$faqtoid' because it already exists?");
405 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
407 ### delete info. modified_ isn't really used.
408 &setFactInfo($faqtoid, "modified_by", "");
409 &setFactInfo($faqtoid, "modified_time", 0);
411 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
413 $count{'Undelete'}++;
419 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
420 return 'lock: no addr 2' unless ($addressed);
422 my $function = lc $1;
425 if ($faqtoid eq "") {
430 # strongly requested by #debian on 19991028. -xk
431 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
432 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
433 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
437 if (&getFactoid($faqtoid) eq "") {
438 &msg($who, "factoid \002$faqtoid\002 does not exist");
442 if ($function eq "lock") {
445 &CmdUnLock($faqtoid);
452 if ($message =~ s/^rename(\s+|$)//) {
453 return 'rename: no addr' unless ($addressed);
455 if ($message eq "") {
460 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
461 my($from,$to) = (lc $1, lc $2);
463 my $result = &getFactoid($from);
464 if (defined $result) {
465 my $author = &getFactInfo($from, "created_by");
466 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
467 &msg($who, "It's not yours to modify.");
471 if ($_ = &getFactoid($to)) {
472 &performReply("destination factoid already exists.");
476 &setFactInfo($from,"factoid_key",$to);
478 &status("rename: <$who> '$from' is now '$to'");
479 &performReply("i renamed '$from' to '$to'");
481 &performReply("i didn't have anything called '$from'");
484 &msg($who,"error: wrong format. ask me about 'help rename'.");
490 # factoid substitution. (X =~ s/A/B/FLAG)
491 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
492 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
493 return 'subst: no addr' unless ($addressed);
496 if ($np =~ /$delim/) {
497 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
502 if (my $result = &getFactoid($faqtoid)) {
503 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
506 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
507 if (length $result > $param{'maxDataSize'}) {
508 &performReply("that's too long");
511 &setFactInfo($faqtoid, "factoid_value", $result);
512 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
515 &performReply("that doesn't contain '$op'");
518 &performReply("i didn't have anything called '$faqtoid'");
525 # Fix up $message for question.
528 s/^hey([, ]+)where/where/i;
530 s/where can i find/where is/i;
531 s/how about/where is/i;
534 # clear the string of useless words.
535 s/^(stupid )?q(uestion)?:\s+//i;
536 s/^(does )?(any|ne)(1|one|body) know //i;
538 s/^[uh]+m*[,\.]* +//i;
542 s/^(gee|boy|golly|gosh)([, ]+)//i;
543 s/^(well|and|but|or|yes)([, ]+)//i;
545 s/^o+[hk]+(a+y+)?([,. ]+)//i;
546 s/^g(eez|osh|olly)([,. ]+)//i;
547 s/^w(ow|hee|o+ho+)([,. ]+)//i;
548 s/^heya?,?( folks)?([,. ]+)//i;
551 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
552 $correction_plausible = 1;
553 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
555 $correction_plausible = 0;
558 my $result = &doQuestion($message);
559 if (!defined $result or $result eq $noreply) {
560 return 'result from doQ undef.';
563 if (defined $result and $result ne "") { # question.
564 &status("question: <$who> $message");
565 $count{'Question'}++;
566 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
567 &loadMyModule("perlMath");
568 my $newresult = &perlMath();
570 if (defined $newresult and $newresult ne "") {
571 $result = $newresult;
572 &status("math: <$who> $message => $result");
577 &performStrictReply($result);
580 # why would a friendly bot get passed here?
581 if (&IsParam("friendlyBots")) {
582 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
586 if (defined &doStatement($message)) {
590 return unless ($addressed);
592 if (length $message > 64) {
593 &status("unparseable-moron: $message");
594 &performReply( &getRandom(keys %{$lang{'moron'}}) );
599 &status("unparseable: $message");
600 &performReply( &getRandom(keys %{$lang{'dunno'}}) );