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.");
42 # join, must be done before outsider checking.
43 if ($message =~ /^join(\s+(.*))?\s*$/i) {
44 return 'join: not addr' unless ($addressed);
46 $2 =~ /^($mask{chan})(,(\S+))?/;
47 my($thischan, $key) = (lc $1, $3);
48 my $chankey = lc $thischan;
49 $chankey .= " $key" if (defined $key);
51 if ($thischan eq "") {
56 if (&IsFlag("o") ne "o") {
57 if (!exists $chanconf{$thischan}) {
58 &msg($who, "I am not allowed to join $thischan.");
62 if (&validChan($thischan)) {
63 &msg($who,"I'm already on $thischan...");
67 $cache{join}{$thischan} = $who; # used for on_join self.
70 &status("JOIN $chankey <$who>");
71 &msg($who, "joining $chankey");
77 if ($msgType =~ /private/ and $message =~ s/^identify//) {
78 $message =~ s/^\s+|\s+$//g;
79 my @array = split / /, $message;
81 if ($who =~ /^_default$/i) {
82 &pSReply("you are too eleet.");
86 if (!scalar @array or scalar @array > 2) {
91 my $do_nick = $array[1] || $who;
93 if (!exists $users{$do_nick}) {
94 &pSReply("nick $do_nick is not in user list.");
98 my $crypt = $users{$do_nick}{PASS};
99 if (!defined $crypt) {
100 &pSReply("user $do_nick has no passwd set.");
104 if (!&ckpasswd($array[0], $crypt)) {
105 &pSReply("invalid passwd for $do_nick.");
109 my $mask = "*!$user@".&makeHostMask($host);
110 ### TODO: prevent adding multiple dupe masks?
111 ### TODO: make &addHostMask() CMD?
112 &pSReply("Added $mask for $do_nick...");
113 $users{$do_nick}{HOSTS}{$mask} = 1;
119 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
122 foreach (keys %channels) {
123 next unless (&IsNickInChan($who,$_));
129 if (!$found and scalar(keys %channels)) {
130 &status("OUTSIDER <$who> $message");
135 # User Processing, for all users.
138 return 'returned from pCH' if &parseCmdHook("main",$message);
140 $retval = &userCommands();
141 return unless (defined $retval);
142 return if ($retval eq $noreply);
146 # once useless messages have been parsed out, we match them.
149 # confused? is this for infobot communications?
150 foreach (keys %{$lang{'confused'}}) {
153 next unless ($message =~ /^\Q$y\E\s*/);
157 # hello. [took me a while to fix this. -xk]
158 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
159 return '' unless ($talkok);
161 # 'mynick: hi' or 'hi mynick' or 'hi'.
162 &status("somebody said hello");
164 # 50% chance of replying to a random greeting when not addressed
165 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
166 &status("not returning unaddressed greeting");
170 # customized random message.
171 my $tmp = (rand() < 0.5) ? ", $who" : "";
172 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
177 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
178 my $reply = &getRandom(keys %{$lang{'howareyou'}});
180 &performReply($reply);
186 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
187 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
189 return 'praise: no addr' unless ($addressed);
191 &status("random praise detected");
193 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
194 &performStrictReply($tmp.":)");
200 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
201 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
203 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
213 if ($msgType =~ /public/ and $message =~ s/^\+//) {
214 &status("found '+' flag; setting msgType to public.");
215 $force_public_reply++;
220 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
221 return '' unless (&hasParam("karma"));
223 my($term,$inc) = (lc $1,$2);
225 if ($msgType !~ /public/i) {
226 &msg($who, "karma must be done in public!");
230 if (lc($term) eq lc($who)) {
231 &msg($who, "please don't karma yourself");
235 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
242 &dbSet("karma", "nick",$term,"karma",$karma);
247 # here's where the external routines get called.
248 # if they return anything but null, that's the "answer".
250 if ( &parseCmdHook("extra",$message) ) {
251 return 'DID SOMETHING IN PCH.';
256 return 'SOMETHING 1';
259 ### FIXME: should this only apply to public messages?
261 &DEBUG("floodwho => '$floodwho'.");
262 delete $flood{$floodwho}{$message};
263 &status("short return due to unknown command.");
268 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
270 } elsif ($param{'DBType'} =~ /^none$/i) {
271 return "NO FACTOIDS.";
273 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
281 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
283 &status("infobot <$nuh> identified") unless $bots{$nuh};
289 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
290 my ($target,$item) = ($1,$2);
293 &status(":INFOBOT:QUERY $who: $message");
295 if ($_ = &getFactoid($item)) {
296 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
299 return 'INFOBOT QUERY';
300 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
301 my ($target,$item) = ($1,$2);
303 &status(":INFOBOT:REPLY $who: $message");
305 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
307 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
308 &msg($target, "$who knew: $lhs $mhs $rhs");
311 $rhs = "<REPLY> are" if ($mhs eq "are");
312 &setFactInfo($lhs, "factoid_value", $rhs);
315 return 'INFOBOT REPLY';
317 &ERROR(":INFOBOT:UNKNOWN $who: $message");
318 return 'INFOBOT UNKNOWN';
324 if ($message =~ s/^forget\s+//i) {
325 return 'forget: no addr' unless ($addressed);
327 my $faqtoid = $message;
328 if ($faqtoid eq "") {
333 $faqtoid =~ tr/A-Z/a-z/;
334 my $result = &getFactoid($faqtoid);
336 if (defined $result) {
337 my $author = &getFactInfo($faqtoid, "created_by");
338 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
339 &msg($who, "you don't have access to remove that factoid");
343 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
345 if (&IsParam("factoidDeleteDelay")) {
346 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
347 ### TODO: check if the "backup" exists and overwrite it
348 my $check = &getFactoid("$faqtoid #DEL#");
350 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
352 &setFactInfo($faqtoid, "modified_by", $who);
353 &setFactInfo($faqtoid, "modified_time", time());
355 &status("forget: not overwriting backup!");
358 &status("forget: <$who> '$faqtoid' =is=> '$result'");
360 &delFactoid($faqtoid);
362 &performReply("i forgot $faqtoid");
366 &performReply("i didn't have anything called '$faqtoid'");
372 # factoid unforget/undelete.
373 if ($message =~ s/^un(forget|delete)\s+//i) {
374 return 'unforget: no addr' unless ($addressed);
376 if (!&IsParam("factoidDeleteDelay")) {
377 &performReply("safe delete has been disable so what is there to undelete?");
381 my $faqtoid = $message;
382 if ($faqtoid eq "") {
387 $faqtoid =~ tr/A-Z/a-z/;
388 my $result = &getFactoid($faqtoid." #DEL#");
389 my $check = &getFactoid($faqtoid);
391 if (!defined $result) {
392 &performReply("i didn't have anything ('$faqtoid') to undelete.");
396 &DEBUG("unforget: check => $check");
397 if (defined $check) {
398 &performReply("cannot undeleted '$faqtoid' because it already exists?");
402 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
404 ### delete info. modified_ isn't really used.
405 &setFactInfo($faqtoid, "modified_by", "");
406 &setFactInfo($faqtoid, "modified_time", 0);
408 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
410 $count{'Undelete'}++;
416 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
417 return 'lock: no addr 2' unless ($addressed);
419 my $function = lc $1;
422 if ($faqtoid eq "") {
427 if (&getFactoid($faqtoid) eq "") {
428 &msg($who, "factoid \002$faqtoid\002 does not exist");
432 if ($function eq "lock") {
433 # strongly requested by #debian on 19991028. -xk
434 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
435 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
436 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
442 &CmdUnLock($faqtoid);
449 if ($message =~ s/^rename(\s+|$)//) {
450 return 'rename: no addr' unless ($addressed);
452 if ($message eq "") {
457 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
458 my($from,$to) = (lc $1, lc $2);
460 my $result = &getFactoid($from);
461 if (defined $result) {
462 my $author = &getFactInfo($from, "created_by");
463 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
464 &msg($who, "It's not yours to modify.");
468 if ($_ = &getFactoid($to)) {
469 &performReply("destination factoid already exists.");
473 &setFactInfo($from,"factoid_key",$to);
475 &status("rename: <$who> '$from' is now '$to'");
476 &performReply("i renamed '$from' to '$to'");
478 &performReply("i didn't have anything called '$from'");
481 &msg($who,"error: wrong format. ask me about 'help rename'.");
487 # factoid substitution. (X =~ s/A/B/FLAG)
488 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
489 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
490 return 'subst: no addr' unless ($addressed);
493 if ($np =~ /$delim/) {
494 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
499 if (my $result = &getFactoid($faqtoid)) {
500 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
503 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
504 if (length $result > $param{'maxDataSize'}) {
505 &performReply("that's too long");
508 &setFactInfo($faqtoid, "factoid_value", $result);
509 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
512 &performReply("that doesn't contain '$op'");
515 &performReply("i didn't have anything called '$faqtoid'");
522 # Fix up $message for question.
525 s/^hey([, ]+)where/where/i;
527 s/where can i find/where is/i;
528 s/how about/where is/i;
531 # clear the string of useless words.
532 s/^(stupid )?q(uestion)?:\s+//i;
533 s/^(does )?(any|ne)(1|one|body) know //i;
535 s/^[uh]+m*[,\.]* +//i;
539 s/^(gee|boy|golly|gosh)([, ]+)//i;
540 s/^(well|and|but|or|yes)([, ]+)//i;
542 s/^o+[hk]+(a+y+)?([,. ]+)//i;
543 s/^g(eez|osh|olly)([,. ]+)//i;
544 s/^w(ow|hee|o+ho+)([,. ]+)//i;
545 s/^heya?,?( folks)?([,. ]+)//i;
548 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
549 $correction_plausible = 1;
550 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
552 $correction_plausible = 0;
555 my $result = &doQuestion($message);
556 if (!defined $result or $result eq $noreply) {
557 return 'result from doQ undef.';
560 if (defined $result and $result !~ /^0?$/) { # question.
561 &status("question: <$who> $message");
562 $count{'Question'}++;
563 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
564 &loadMyModule("perlMath");
565 my $newresult = &perlMath();
567 if (defined $newresult and $newresult ne "") {
568 $result = $newresult;
569 &status("math: <$who> $message => $result");
573 if ($result !~ /^0?$/) {
574 &performStrictReply($result);
578 # why would a friendly bot get passed here?
579 if (&IsParam("friendlyBots")) {
580 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
584 if (!defined &doStatement($message)) {
588 return unless ($addressed);
590 if (length $message > 64) {
591 &status("unparseable-moron: $message");
592 &performReply( &getRandom(keys %{$lang{'moron'}}) );
597 &status("unparseable: $message");
598 &performReply( &getRandom(keys %{$lang{'dunno'}}) );