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 # once useless messages have been parsed out, we match them.
114 # confused? is this for infobot communications?
115 foreach (keys %{$lang{'confused'}}) {
118 next unless ($message =~ /^\Q$y\E\s*/);
122 # hello. [took me a while to fix this. -xk]
123 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
124 return '' unless ($talkok);
126 # 'mynick: hi' or 'hi mynick' or 'hi'.
127 &status("somebody said hello");
129 # 50% chance of replying to a random greeting when not addressed
130 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
131 &status("not returning unaddressed greeting");
135 # customized random message.
136 my $tmp = (rand() < 0.5) ? ", $who" : "";
137 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
142 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
143 my $reply = &getRandom(keys %{$lang{'howareyou'}});
145 &performReply($reply);
151 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
152 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
154 return 'praise: no addr' unless ($addressed);
156 &status("random praise detected");
158 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
159 &performStrictReply($tmp.":)");
165 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
166 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
167 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
169 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
179 if ($msgType =~ /public/ and $message =~ s/^\+//) {
180 &status("found '+' flag; setting msgType to public.");
181 $force_public_reply++;
187 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
188 return '' unless (&hasParam("karma"));
190 my($term,$inc) = (lc $1,$2);
192 if ($msgType !~ /public/i) {
193 &msg($who, "karma must be done in public!");
197 if (lc($term) eq lc($who)) {
198 &msg($who, "please don't karma yourself");
202 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
209 &dbSet("karma", "nick",$term,"karma",$karma);
214 # here's where the external routines get called.
215 # if they return anything but null, that's the "answer".
217 if ( &parseCmdHook("extra",$message) ) {
218 return 'DID SOMETHING IN PCH.';
223 return 'SOMETHING 1';
226 ### FIXME: should this only apply to public messages?
228 &DEBUG("floodwho => '$floodwho'.");
229 delete $flood{$floodwho}{$message};
230 &status("short return due to unknown command.");
235 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
237 } elsif ($param{'DBType'} =~ /^none$/i) {
238 return "NO FACTOIDS.";
240 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
248 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
250 &status("infobot <$nuh> identified") unless $bots{$nuh};
256 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
257 my ($target,$item) = ($1,$2);
260 &status(":INFOBOT:QUERY $who: $message");
262 if ($_ = &getFactoid($item)) {
263 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
266 return 'INFOBOT QUERY';
267 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
268 my ($target,$item) = ($1,$2);
270 &status(":INFOBOT:REPLY $who: $message");
272 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
274 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
275 &msg($target, "$who knew: $lhs $mhs $rhs");
278 $rhs = "<REPLY> are" if ($mhs eq "are");
279 &setFactInfo($lhs, "factoid_value", $rhs);
282 return 'INFOBOT REPLY';
284 &ERROR(":INFOBOT:UNKNOWN $who: $message");
285 return 'INFOBOT UNKNOWN';
291 if ($message =~ s/^forget\s+//i) {
292 return 'forget: no addr' unless ($addressed);
294 my $faqtoid = $message;
295 if ($faqtoid eq "") {
300 $faqtoid =~ tr/A-Z/a-z/;
301 my $result = &getFactoid($faqtoid);
303 if (defined $result) {
304 my $author = &getFactInfo($faqtoid, "created_by");
305 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
306 &msg($who, "you don't have access to remove that factoid");
310 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
312 if (&IsParam("factoidDeleteDelay")) {
313 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
314 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
316 ### delete info. modified_ isn't really used.
317 &setFactInfo($faqtoid, "modified_by", $who);
318 &setFactInfo($faqtoid, "modified_time", time());
320 &status("forget: <$who> '$faqtoid' =is=> '$result'");
321 &delFactoid($faqtoid);
324 &performReply("i forgot $faqtoid");
328 &performReply("i didn't have anything called '$faqtoid'");
334 # factoid unforget/undelete.
335 if ($message =~ s/^un(forget|delete)\s+//i) {
336 return 'unforget: no addr' unless ($addressed);
338 if (!&IsParam("factoidDeleteDelay")) {
339 &performReply("safe delete has been disable so what is there to undelete?");
343 my $faqtoid = $message;
344 if ($faqtoid eq "") {
349 $faqtoid =~ tr/A-Z/a-z/;
350 my $result = &getFactoid($faqtoid." #DEL#");
351 my $check = &getFactoid($faqtoid);
353 if (!defined $result) {
354 &performReply("i didn't have anything ('$faqtoid') to undelete.");
358 if (defined $check) {
359 &performReply("cannot undeleted '$faqtoid' because it already exists?");
363 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
365 ### delete info. modified_ isn't really used.
366 &setFactInfo($faqtoid, "modified_by", "");
367 &setFactInfo($faqtoid, "modified_time", 0);
369 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
371 $count{'Undelete'}++;
377 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
378 return 'lock: no addr 2' unless ($addressed);
380 my $function = lc $1;
383 if ($faqtoid eq "") {
388 # strongly requested by #debian on 19991028. -xk
389 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
390 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
391 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
395 if (&getFactoid($faqtoid) eq "") {
396 &msg($who, "factoid \002$faqtoid\002 does not exist");
400 if ($function eq "lock") {
403 &CmdUnLock($faqtoid);
410 if ($message =~ s/^rename(\s+|$)//) {
411 return 'rename: no addr' unless ($addressed);
413 if ($message eq "") {
418 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
419 my($from,$to) = (lc $1, lc $2);
421 my $result = &getFactoid($from);
422 if (defined $result) {
423 my $author = &getFactInfo($from, "created_by");
424 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
425 &msg($who, "It's not yours to modify.");
429 if ($_ = &getFactoid($to)) {
430 &performReply("destination factoid already exists.");
434 &setFactInfo($from,"factoid_key",$to);
436 &status("rename: <$who> '$from' is now '$to'");
437 &performReply("i renamed '$from' to '$to'");
439 &performReply("i didn't have anything called '$from'");
442 &msg($who,"error: wrong format. ask me about 'help rename'.");
448 # factoid substitution. (X =~ s/A/B/FLAG)
449 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
450 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
451 return 'subst: no addr' unless ($addressed);
454 if ($np =~ /$delim/) {
455 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
460 if (my $result = &getFactoid($faqtoid)) {
461 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
464 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
465 if (length $result > $param{'maxDataSize'}) {
466 &performReply("that's too long");
469 &setFactInfo($faqtoid, "factoid_value", $result);
470 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
473 &performReply("that doesn't contain '$op'");
476 &performReply("i didn't have anything called '$faqtoid'");
483 # Fix up $message for question.
486 s/^hey([, ]+)where/where/i;
488 s/where can i find/where is/i;
489 s/how about/where is/i;
492 # clear the string of useless words.
493 s/^(stupid )?q(uestion)?:\s+//i;
494 s/^(does )?(any|ne)(1|one|body) know //i;
496 s/^[uh]+m*[,\.]* +//i;
500 s/^(gee|boy|golly|gosh)([, ]+)//i;
501 s/^(well|and|but|or|yes)([, ]+)//i;
503 s/^o+[hk]+(a+y+)?([,. ]+)//i;
504 s/^g(eez|osh|olly)([,. ]+)//i;
505 s/^w(ow|hee|o+ho+)([,. ]+)//i;
506 s/^heya?,?( folks)?([,. ]+)//i;
509 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
510 $correction_plausible = 1;
511 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
513 $correction_plausible = 0;
516 my $result = &doQuestion($message);
517 if (!defined $result or $result eq $noreply) {
518 return 'result from doQ undef.';
521 if (defined $result and $result ne "") { # question.
522 &status("question: <$who> $message");
523 $count{'Question'}++;
524 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
525 &loadMyModule("perlMath");
526 my $newresult = &perlMath();
528 if (defined $newresult and $newresult ne "") {
529 $result = $newresult;
530 &status("math: <$who> $message => $result");
535 &performStrictReply($result);
538 # why would a friendly bot get passed here?
539 if (&IsParam("friendlyBots")) {
540 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
544 if (defined &doStatement($message)) {
548 return unless ($addressed);
550 if (length $message > 64) {
551 &status("unparseable-moron: $message");
552 &performReply( &getRandom(keys %{$lang{'moron'}}) );
557 &status("unparseable: $message");
558 &performReply( &getRandom(keys %{$lang{'dunno'}}) );