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 ($msgType =~ /private/ and $message =~ s/^identify//) {
85 $message =~ s/^\s+|\s+$//g;
86 my @array = split / /, $message;
88 if ($who =~ /^_default$/i) {
89 &pSReply("you are too eleet.");
93 if (!scalar @array or scalar @array > 2) {
98 my $do_nick = $array[1] || $who;
100 if (!exists $users{$do_nick}) {
101 &pSReply("nick $do_nick is not in user list.");
105 my $crypt = $users{$do_nick}{PASS};
106 if (!defined $crypt) {
107 &pSReply("user $do_nick has no passwd set.");
111 if (!&ckpasswd($array[0], $crypt)) {
112 &pSReply("invalid passwd for $do_nick.");
116 my $mask = "*!$user@".&makeHostMask($host);
117 ### TODO: prevent adding multiple dupe masks?
118 ### TODO: make &addHostMask() CMD?
119 &pSReply("Added $mask for $do_nick...");
120 $users{$do_nick}{HOSTS}{$mask} = 1;
126 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
129 foreach (keys %channels) {
130 next unless (&IsNickInChan($who,$_));
136 if (!$found and scalar(keys %channels)) {
137 &status("OUTSIDER <$who> $message");
142 # User Processing, for all users.
145 return 'returned from pCH' if &parseCmdHook("main",$message);
147 $retval = &userCommands();
148 return unless (defined $retval);
149 return if ($retval eq $noreply);
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 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
210 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
220 if ($msgType =~ /public/ and $message =~ s/^\+//) {
221 &status("found '+' flag; setting msgType to public.");
222 $force_public_reply++;
228 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
229 return '' unless (&hasParam("karma"));
231 my($term,$inc) = (lc $1,$2);
233 if ($msgType !~ /public/i) {
234 &msg($who, "karma must be done in public!");
238 if (lc($term) eq lc($who)) {
239 &msg($who, "please don't karma yourself");
243 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
250 &dbSet("karma", "nick",$term,"karma",$karma);
255 # here's where the external routines get called.
256 # if they return anything but null, that's the "answer".
258 if ( &parseCmdHook("extra",$message) ) {
259 return 'DID SOMETHING IN PCH.';
264 return 'SOMETHING 1';
267 ### FIXME: should this only apply to public messages?
269 &DEBUG("floodwho => '$floodwho'.");
270 delete $flood{$floodwho}{$message};
271 &status("short return due to unknown command.");
276 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
278 } elsif ($param{'DBType'} =~ /^none$/i) {
279 return "NO FACTOIDS.";
281 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
289 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
291 &status("infobot <$nuh> identified") unless $bots{$nuh};
297 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
298 my ($target,$item) = ($1,$2);
301 &status(":INFOBOT:QUERY $who: $message");
303 if ($_ = &getFactoid($item)) {
304 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
307 return 'INFOBOT QUERY';
308 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
309 my ($target,$item) = ($1,$2);
311 &status(":INFOBOT:REPLY $who: $message");
313 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
315 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
316 &msg($target, "$who knew: $lhs $mhs $rhs");
319 $rhs = "<REPLY> are" if ($mhs eq "are");
320 &setFactInfo($lhs, "factoid_value", $rhs);
323 return 'INFOBOT REPLY';
325 &ERROR(":INFOBOT:UNKNOWN $who: $message");
326 return 'INFOBOT UNKNOWN';
332 if ($message =~ s/^forget\s+//i) {
333 return 'forget: no addr' unless ($addressed);
335 my $faqtoid = $message;
336 if ($faqtoid eq "") {
341 $faqtoid =~ tr/A-Z/a-z/;
342 my $result = &getFactoid($faqtoid);
344 if (defined $result) {
345 my $author = &getFactInfo($faqtoid, "created_by");
346 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
347 &msg($who, "you don't have access to remove that factoid");
351 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
353 if (&IsParam("factoidDeleteDelay")) {
354 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
355 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
357 ### delete info. modified_ isn't really used.
358 &setFactInfo($faqtoid, "modified_by", $who);
359 &setFactInfo($faqtoid, "modified_time", time());
361 &status("forget: <$who> '$faqtoid' =is=> '$result'");
362 &delFactoid($faqtoid);
365 &performReply("i forgot $faqtoid");
369 &performReply("i didn't have anything called '$faqtoid'");
375 # factoid unforget/undelete.
376 if ($message =~ s/^un(forget|delete)\s+//i) {
377 return 'unforget: no addr' unless ($addressed);
379 if (!&IsParam("factoidDeleteDelay")) {
380 &performReply("safe delete has been disable so what is there to undelete?");
384 my $faqtoid = $message;
385 if ($faqtoid eq "") {
390 $faqtoid =~ tr/A-Z/a-z/;
391 my $result = &getFactoid($faqtoid." #DEL#");
392 my $check = &getFactoid($faqtoid);
394 if (!defined $result) {
395 &performReply("i didn't have anything ('$faqtoid') to undelete.");
399 if (defined $check) {
400 &performReply("cannot undeleted '$faqtoid' because it already exists?");
404 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
406 ### delete info. modified_ isn't really used.
407 &setFactInfo($faqtoid, "modified_by", "");
408 &setFactInfo($faqtoid, "modified_time", 0);
410 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
412 $count{'Undelete'}++;
418 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
419 return 'lock: no addr 2' unless ($addressed);
421 my $function = lc $1;
424 if ($faqtoid eq "") {
429 # strongly requested by #debian on 19991028. -xk
430 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
431 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
432 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
436 if (&getFactoid($faqtoid) eq "") {
437 &msg($who, "factoid \002$faqtoid\002 does not exist");
441 if ($function eq "lock") {
444 &CmdUnLock($faqtoid);
451 if ($message =~ s/^rename(\s+|$)//) {
452 return 'rename: no addr' unless ($addressed);
454 if ($message eq "") {
459 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
460 my($from,$to) = (lc $1, lc $2);
462 my $result = &getFactoid($from);
463 if (defined $result) {
464 my $author = &getFactInfo($from, "created_by");
465 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
466 &msg($who, "It's not yours to modify.");
470 if ($_ = &getFactoid($to)) {
471 &performReply("destination factoid already exists.");
475 &setFactInfo($from,"factoid_key",$to);
477 &status("rename: <$who> '$from' is now '$to'");
478 &performReply("i renamed '$from' to '$to'");
480 &performReply("i didn't have anything called '$from'");
483 &msg($who,"error: wrong format. ask me about 'help rename'.");
489 # factoid substitution. (X =~ s/A/B/FLAG)
490 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
491 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
492 return 'subst: no addr' unless ($addressed);
495 if ($np =~ /$delim/) {
496 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
501 if (my $result = &getFactoid($faqtoid)) {
502 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
505 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
506 if (length $result > $param{'maxDataSize'}) {
507 &performReply("that's too long");
510 &setFactInfo($faqtoid, "factoid_value", $result);
511 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
514 &performReply("that doesn't contain '$op'");
517 &performReply("i didn't have anything called '$faqtoid'");
524 # Fix up $message for question.
527 s/^hey([, ]+)where/where/i;
529 s/where can i find/where is/i;
530 s/how about/where is/i;
533 # clear the string of useless words.
534 s/^(stupid )?q(uestion)?:\s+//i;
535 s/^(does )?(any|ne)(1|one|body) know //i;
537 s/^[uh]+m*[,\.]* +//i;
541 s/^(gee|boy|golly|gosh)([, ]+)//i;
542 s/^(well|and|but|or|yes)([, ]+)//i;
544 s/^o+[hk]+(a+y+)?([,. ]+)//i;
545 s/^g(eez|osh|olly)([,. ]+)//i;
546 s/^w(ow|hee|o+ho+)([,. ]+)//i;
547 s/^heya?,?( folks)?([,. ]+)//i;
550 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
551 $correction_plausible = 1;
552 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
554 $correction_plausible = 0;
557 my $result = &doQuestion($message);
558 if (!defined $result or $result eq $noreply) {
559 return 'result from doQ undef.';
562 if (defined $result and $result !~ /^0?$/) { # question.
563 &status("question: <$who> $message");
564 $count{'Question'}++;
565 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
566 &loadMyModule("perlMath");
567 my $newresult = &perlMath();
569 if (defined $newresult and $newresult ne "") {
570 $result = $newresult;
571 &status("math: <$who> $message => $result");
575 if ($result !~ /^0?$/) {
576 &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'}}) );