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.
102 return '$noreply from pCH' if &parseCmdHook("main",$message);
103 return '$noreply from userC' if &userCommands() eq $noreply;
107 # once useless messages have been parsed out, we match them.
110 # confused? is this for infobot communications?
111 foreach (keys %{$lang{'confused'}}) {
114 next unless ($message =~ /^\Q$y\E\s*/);
118 # hello. [took me a while to fix this. -xk]
119 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
120 return '' unless ($talkok);
122 # 'mynick: hi' or 'hi mynick' or 'hi'.
123 &status("somebody said hello");
125 # 50% chance of replying to a random greeting when not addressed
126 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
127 &status("not returning unaddressed greeting");
131 # customized random message.
132 my $tmp = (rand() < 0.5) ? ", $who" : "";
133 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
138 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
139 my $reply = &getRandom(keys %{$lang{'howareyou'}});
141 &performReply($reply);
147 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
148 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
150 return 'praise: no addr' unless ($addressed);
152 &status("random praise detected");
154 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
155 &performStrictReply($tmp.":)");
161 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
162 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
163 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
165 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
175 if ($msgType =~ /public/ and $message =~ s/^\+//) {
176 &status("found '+' flag; setting msgType to public.");
177 $force_public_reply++;
183 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
184 return '' unless (&hasParam("karma"));
186 my($term,$inc) = (lc $1,$2);
188 if ($msgType !~ /public/i) {
189 &msg($who, "karma must be done in public!");
193 if (lc($term) eq lc($who)) {
194 &msg($who, "please don't karma yourself");
198 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
205 &dbSet("karma", "nick",$term,"karma",$karma);
210 # here's where the external routines get called.
211 # if they return anything but null, that's the "answer".
213 if ( &parseCmdHook("extra",$message) ) {
214 return 'DID SOMETHING IN PCH.';
219 &performStrictReply($er) if ($er ne $noreply);
220 return 'SOMETHING 1';
223 ### FIXME: should this only apply to public messages?
225 &DEBUG("floodwho => '$floodwho'.");
226 delete $flood{$floodwho}{$message};
227 &status("short return due to unknown command.");
232 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
234 } elsif ($param{'DBType'} =~ /^none$/i) {
235 return "NO FACTOIDS.";
237 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
245 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
247 &status("infobot <$nuh> identified") unless $bots{$nuh};
253 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
254 my ($target,$item) = ($1,$2);
257 &status(":INFOBOT:QUERY $who: $message");
259 if ($_ = &getFactoid($item)) {
260 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
263 return 'INFOBOT QUERY';
264 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
265 my ($target,$item) = ($1,$2);
267 &status(":INFOBOT:REPLY $who: $message");
269 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
271 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
272 &msg($target, "$who knew: $lhs $mhs $rhs");
275 $rhs = "<REPLY> are" if ($mhs eq "are");
276 &setFactInfo($lhs, "factoid_value", $rhs);
279 return 'INFOBOT REPLY';
281 &ERROR(":INFOBOT:UNKNOWN $who: $message");
282 return 'INFOBOT UNKNOWN';
288 if ($message =~ s/^forget\s+//i) {
289 return 'forget: no addr' unless ($addressed);
291 my $faqtoid = $message;
292 if ($faqtoid eq "") {
297 $faqtoid =~ tr/A-Z/a-z/;
298 my $result = &getFactoid($faqtoid);
300 if (defined $result) {
301 my $author = &getFactInfo($faqtoid, "created_by");
302 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
303 &msg($who, "you don't have access to remove that factoid");
307 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
309 if (&IsParam("factoidDeleteDelay")) {
310 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
311 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
313 ### delete info. modified_ isn't really used.
314 &setFactInfo($faqtoid, "modified_by", $who);
315 &setFactInfo($faqtoid, "modified_time", time());
317 &status("forget: <$who> '$faqtoid' =is=> '$result'");
318 &delFactoid($faqtoid);
321 &performReply("i forgot $faqtoid");
325 &performReply("i didn't have anything called '$faqtoid'");
331 # factoid unforget/undelete.
332 if ($message =~ s/^un(forget|delete)\s+//i) {
333 return 'unforget: no addr' unless ($addressed);
335 if (!&IsParam("factoidDeleteDelay")) {
336 &performReply("safe delete has been disable so what is there to undelete?");
340 my $faqtoid = $message;
341 if ($faqtoid eq "") {
346 $faqtoid =~ tr/A-Z/a-z/;
347 my $result = &getFactoid($faqtoid." #DEL#");
348 my $check = &getFactoid($faqtoid);
350 if (!defined $result) {
351 &performReply("i didn't have anything ('$faqtoid') to undelete.");
355 if (defined $check) {
356 &performReply("cannot undeleted '$faqtoid' because it already exists?");
360 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
362 ### delete info. modified_ isn't really used.
363 &setFactInfo($faqtoid, "modified_by", "");
364 &setFactInfo($faqtoid, "modified_time", 0);
366 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
368 $count{'Undelete'}++;
374 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
375 return 'lock: no addr 2' unless ($addressed);
377 my $function = lc $1;
380 if ($faqtoid eq "") {
385 # strongly requested by #debian on 19991028. -xk
386 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
387 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
388 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
392 if (&getFactoid($faqtoid) eq "") {
393 &msg($who, "factoid \002$faqtoid\002 does not exist");
397 if ($function eq "lock") {
400 &CmdUnLock($faqtoid);
407 if ($message =~ s/^rename(\s+|$)//) {
408 return 'rename: no addr' unless ($addressed);
410 if ($message eq "") {
415 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
416 my($from,$to) = (lc $1, lc $2);
418 my $result = &getFactoid($from);
419 if (defined $result) {
420 my $author = &getFactInfo($from, "created_by");
421 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
422 &msg($who, "It's not yours to modify.");
426 if ($_ = &getFactoid($to)) {
427 &performReply("destination factoid already exists.");
431 &setFactInfo($from,"factoid_key",$to);
433 &status("rename: <$who> '$from' is now '$to'");
434 &performReply("i renamed '$from' to '$to'");
436 &performReply("i didn't have anything called '$from'");
439 &msg($who,"error: wrong format. ask me about 'help rename'.");
445 # factoid substitution. (X =~ s/A/B/FLAG)
446 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
447 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
448 return 'subst: no addr' unless ($addressed);
451 if ($np =~ /$delim/) {
452 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
457 if (my $result = &getFactoid($faqtoid)) {
458 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
461 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
462 if (length $result > $param{'maxDataSize'}) {
463 &performReply("that's too long");
466 &setFactInfo($faqtoid, "factoid_value", $result);
467 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
470 &performReply("that doesn't contain '$op'");
473 &performReply("i didn't have anything called '$faqtoid'");
480 # Fix up $message for question.
483 s/^hey([, ]+)where/where/i;
485 s/where can i find/where is/i;
486 s/how about/where is/i;
489 # clear the string of useless words.
490 s/^(stupid )?q(uestion)?:\s+//i;
491 s/^(does )?(any|ne)(1|one|body) know //i;
493 s/^[uh]+m*[,\.]* +//i;
497 s/^(gee|boy|golly|gosh)([, ]+)//i;
498 s/^(well|and|but|or|yes)([, ]+)//i;
500 s/^o+[hk]+(a+y+)?([,. ]+)//i;
501 s/^g(eez|osh|olly)([,. ]+)//i;
502 s/^w(ow|hee|o+ho+)([,. ]+)//i;
503 s/^heya?,?( folks)?([,. ]+)//i;
506 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
507 $correction_plausible = 1;
508 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
510 $correction_plausible = 0;
513 my $result = &doQuestion($message);
515 return 'result is $noreply' if ($result eq $noreply);
517 if (defined $result and $result ne "") { # question.
518 &status("question: <$who> $message");
519 $count{'Question'}++;
520 } elsif (&IsParam("perlMath") and $addressed) { # perl math.
521 &loadMyModule("perlMath");
522 my $newresult = &perlMath();
524 if (defined $newresult and $newresult ne "") {
525 $result = $newresult;
526 &status("math: <$who> $message => $result");
531 &performStrictReply($result);
534 # why would a friendly bot get passed here?
535 if (&IsParam("friendlyBots")) {
536 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
540 if ($_ = &doStatement($message)) {
545 if (length $message < 64) {
546 &status("unparseable: $message");
547 &performReply( &getRandom(keys %{$lang{'dunno'}}) );
549 &status("unparse-ignore: $message");