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 $mask = "*!$user@".&makeHostMask($host);
133 ### TODO: prevent adding multiple dupe masks?
134 ### TODO: make &addHostMask() CMD?
135 &pSReply("Added $mask for $do_nick...");
136 $users{$do_nick}{HOSTS}{$mask} = 1;
142 # once useless messages have been parsed out, we match them.
145 # confused? is this for infobot communications?
146 foreach (keys %{$lang{'confused'}}) {
149 next unless ($message =~ /^\Q$y\E\s*/);
153 # hello. [took me a while to fix this. -xk]
154 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
155 return '' unless ($talkok);
157 # 'mynick: hi' or 'hi mynick' or 'hi'.
158 &status("somebody said hello");
160 # 50% chance of replying to a random greeting when not addressed
161 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
162 &status("not returning unaddressed greeting");
166 # customized random message.
167 my $tmp = (rand() < 0.5) ? ", $who" : "";
168 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
173 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
174 my $reply = &getRandom(keys %{$lang{'howareyou'}});
176 &performReply($reply);
182 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
183 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
185 return 'praise: no addr' unless ($addressed);
187 &status("random praise detected");
189 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
190 &performStrictReply($tmp.":)");
196 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
197 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
198 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
200 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
210 if ($msgType =~ /public/ and $message =~ s/^\+//) {
211 &status("found '+' flag; setting msgType to public.");
212 $force_public_reply++;
218 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
219 return '' unless (&hasParam("karma"));
221 my($term,$inc) = (lc $1,$2);
223 if ($msgType !~ /public/i) {
224 &msg($who, "karma must be done in public!");
228 if (lc($term) eq lc($who)) {
229 &msg($who, "please don't karma yourself");
233 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
240 &dbSet("karma", "nick",$term,"karma",$karma);
245 # here's where the external routines get called.
246 # if they return anything but null, that's the "answer".
248 if ( &parseCmdHook("extra",$message) ) {
249 return 'DID SOMETHING IN PCH.';
254 return 'SOMETHING 1';
257 ### FIXME: should this only apply to public messages?
259 &DEBUG("floodwho => '$floodwho'.");
260 delete $flood{$floodwho}{$message};
261 &status("short return due to unknown command.");
266 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
268 } elsif ($param{'DBType'} =~ /^none$/i) {
269 return "NO FACTOIDS.";
271 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
279 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
281 &status("infobot <$nuh> identified") unless $bots{$nuh};
287 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
288 my ($target,$item) = ($1,$2);
291 &status(":INFOBOT:QUERY $who: $message");
293 if ($_ = &getFactoid($item)) {
294 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
297 return 'INFOBOT QUERY';
298 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
299 my ($target,$item) = ($1,$2);
301 &status(":INFOBOT:REPLY $who: $message");
303 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
305 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
306 &msg($target, "$who knew: $lhs $mhs $rhs");
309 $rhs = "<REPLY> are" if ($mhs eq "are");
310 &setFactInfo($lhs, "factoid_value", $rhs);
313 return 'INFOBOT REPLY';
315 &ERROR(":INFOBOT:UNKNOWN $who: $message");
316 return 'INFOBOT UNKNOWN';
322 if ($message =~ s/^forget\s+//i) {
323 return 'forget: no addr' unless ($addressed);
325 my $faqtoid = $message;
326 if ($faqtoid eq "") {
331 $faqtoid =~ tr/A-Z/a-z/;
332 my $result = &getFactoid($faqtoid);
334 if (defined $result) {
335 my $author = &getFactInfo($faqtoid, "created_by");
336 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
337 &msg($who, "you don't have access to remove that factoid");
341 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
343 if (&IsParam("factoidDeleteDelay")) {
344 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
345 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
347 ### delete info. modified_ isn't really used.
348 &setFactInfo($faqtoid, "modified_by", $who);
349 &setFactInfo($faqtoid, "modified_time", time());
351 &status("forget: <$who> '$faqtoid' =is=> '$result'");
352 &delFactoid($faqtoid);
355 &performReply("i forgot $faqtoid");
359 &performReply("i didn't have anything called '$faqtoid'");
365 # factoid unforget/undelete.
366 if ($message =~ s/^un(forget|delete)\s+//i) {
367 return 'unforget: no addr' unless ($addressed);
369 if (!&IsParam("factoidDeleteDelay")) {
370 &performReply("safe delete has been disable so what is there to undelete?");
374 my $faqtoid = $message;
375 if ($faqtoid eq "") {
380 $faqtoid =~ tr/A-Z/a-z/;
381 my $result = &getFactoid($faqtoid." #DEL#");
382 my $check = &getFactoid($faqtoid);
384 if (!defined $result) {
385 &performReply("i didn't have anything ('$faqtoid') to undelete.");
389 if (defined $check) {
390 &performReply("cannot undeleted '$faqtoid' because it already exists?");
394 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
396 ### delete info. modified_ isn't really used.
397 &setFactInfo($faqtoid, "modified_by", "");
398 &setFactInfo($faqtoid, "modified_time", 0);
400 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
402 $count{'Undelete'}++;
408 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
409 return 'lock: no addr 2' unless ($addressed);
411 my $function = lc $1;
414 if ($faqtoid eq "") {
419 # strongly requested by #debian on 19991028. -xk
420 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
421 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
422 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
426 if (&getFactoid($faqtoid) eq "") {
427 &msg($who, "factoid \002$faqtoid\002 does not exist");
431 if ($function eq "lock") {
434 &CmdUnLock($faqtoid);
441 if ($message =~ s/^rename(\s+|$)//) {
442 return 'rename: no addr' unless ($addressed);
444 if ($message eq "") {
449 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
450 my($from,$to) = (lc $1, lc $2);
452 my $result = &getFactoid($from);
453 if (defined $result) {
454 my $author = &getFactInfo($from, "created_by");
455 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
456 &msg($who, "It's not yours to modify.");
460 if ($_ = &getFactoid($to)) {
461 &performReply("destination factoid already exists.");
465 &setFactInfo($from,"factoid_key",$to);
467 &status("rename: <$who> '$from' is now '$to'");
468 &performReply("i renamed '$from' to '$to'");
470 &performReply("i didn't have anything called '$from'");
473 &msg($who,"error: wrong format. ask me about 'help rename'.");
479 # factoid substitution. (X =~ s/A/B/FLAG)
480 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
481 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
482 return 'subst: no addr' unless ($addressed);
485 if ($np =~ /$delim/) {
486 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
491 if (my $result = &getFactoid($faqtoid)) {
492 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
495 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
496 if (length $result > $param{'maxDataSize'}) {
497 &performReply("that's too long");
500 &setFactInfo($faqtoid, "factoid_value", $result);
501 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
504 &performReply("that doesn't contain '$op'");
507 &performReply("i didn't have anything called '$faqtoid'");
514 # Fix up $message for question.
517 s/^hey([, ]+)where/where/i;
519 s/where can i find/where is/i;
520 s/how about/where is/i;
523 # clear the string of useless words.
524 s/^(stupid )?q(uestion)?:\s+//i;
525 s/^(does )?(any|ne)(1|one|body) know //i;
527 s/^[uh]+m*[,\.]* +//i;
531 s/^(gee|boy|golly|gosh)([, ]+)//i;
532 s/^(well|and|but|or|yes)([, ]+)//i;
534 s/^o+[hk]+(a+y+)?([,. ]+)//i;
535 s/^g(eez|osh|olly)([,. ]+)//i;
536 s/^w(ow|hee|o+ho+)([,. ]+)//i;
537 s/^heya?,?( folks)?([,. ]+)//i;
540 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
541 $correction_plausible = 1;
542 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
544 $correction_plausible = 0;
547 my $result = &doQuestion($message);
548 if (!defined $result or $result eq $noreply) {
549 return 'result from doQ undef.';
552 if (defined $result and $result ne "") { # question.
553 &status("question: <$who> $message");
554 $count{'Question'}++;
555 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
556 &loadMyModule("perlMath");
557 my $newresult = &perlMath();
559 if (defined $newresult and $newresult ne "") {
560 $result = $newresult;
561 &status("math: <$who> $message => $result");
566 &performStrictReply($result);
569 # why would a friendly bot get passed here?
570 if (&IsParam("friendlyBots")) {
571 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
575 if (defined &doStatement($message)) {
579 return unless ($addressed);
581 if (length $message > 64) {
582 &status("unparseable-moron: $message");
583 &performReply( &getRandom(keys %{$lang{'moron'}}) );
588 &status("unparseable: $message");
589 &performReply( &getRandom(keys %{$lang{'dunno'}}) );