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)) {
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.
101 return '$noreply from userC' if &userCommands() eq $noreply;
104 # once useless messages have been parsed out, we match them.
107 # confused? is this for infobot communications?
108 foreach (keys %{$lang{'confused'}}) {
111 next unless ($message =~ /^\Q$y\E\s*/);
115 # hello. [took me a while to fix this. -xk]
116 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
117 return '' unless ($talkok);
119 # 'mynick: hi' or 'hi mynick' or 'hi'.
120 &status("somebody said hello");
122 # 50% chance of replying to a random greeting when not addressed
123 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
124 &status("not returning unaddressed greeting");
128 # customized random message.
129 my $tmp = (rand() < 0.5) ? ", $who" : "";
130 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
135 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
136 my $reply = &getRandom(keys %{$lang{'howareyou'}});
138 &performReply($reply);
144 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
145 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
147 return 'praise: no addr' unless ($addressed);
149 &status("random praise detected");
151 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
152 &performStrictReply($tmp.":)");
158 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
159 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
160 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
162 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
172 if ($msgType =~ /public/ and $message =~ s/^\+//) {
173 &status("found '+' flag; setting msgType to public.");
174 $force_public_reply++;
180 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
181 return '' unless (&hasParam("karma"));
183 my($term,$inc) = (lc $1,$2);
185 if ($msgType !~ /public/i) {
186 &msg($who, "karma must be done in public!");
190 if (lc($term) eq lc($who)) {
191 &msg($who, "please don't karma yourself");
195 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
202 &dbSet("karma", "nick",$term,"karma",$karma);
207 # here's where the external routines get called.
208 # if they return anything but null, that's the "answer".
210 if (&parseCmdHook()) {
211 return 'DID SOMETHING IN PCH.';
216 &performStrictReply($er) if ($er ne $noreply);
217 return 'SOMETHING 1';
220 ### FIXME: should this only apply to public messages?
222 &DEBUG("floodwho => '$floodwho'.");
223 delete $flood{$floodwho}{$message};
224 &status("short return due to unknown command.");
229 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
231 } elsif ($param{'DBType'} =~ /^none$/i) {
232 return "NO FACTOIDS.";
234 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
242 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
244 &status("infobot <$nuh> identified") unless $bots{$nuh};
250 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
251 my ($target,$item) = ($1,$2);
254 &status(":INFOBOT:QUERY $who: $message");
256 if ($_ = &getFactoid($item)) {
257 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
260 return 'INFOBOT QUERY';
261 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
262 my ($target,$item) = ($1,$2);
264 &status(":INFOBOT:REPLY $who: $message");
266 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
268 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
269 &msg($target, "$who knew: $lhs $mhs $rhs");
272 $rhs = "<REPLY> are" if ($mhs eq "are");
273 &setFactInfo($lhs, "factoid_value", $rhs);
276 return 'INFOBOT REPLY';
278 &ERROR(":INFOBOT:UNKNOWN $who: $message");
279 return 'INFOBOT UNKNOWN';
285 if ($message =~ s/^forget\s+//i) {
286 return 'forget: no addr' unless ($addressed);
288 my $faqtoid = $message;
289 if ($faqtoid eq "") {
294 $faqtoid =~ tr/A-Z/a-z/;
295 my $result = &getFactoid($faqtoid);
297 if (defined $result) {
298 my $author = &getFactInfo($faqtoid, "created_by");
299 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
300 &msg($who, "you don't have access to remove that factoid");
304 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
306 if (&IsParam("factoidDeleteDelay")) {
307 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
308 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
310 ### delete info. modified_ isn't really used.
311 &setFactInfo($faqtoid, "modified_by", $who);
312 &setFactInfo($faqtoid, "modified_time", time());
314 &status("forget: <$who> '$faqtoid' =is=> '$result'");
315 &delFactoid($faqtoid);
318 &performReply("i forgot $faqtoid");
322 &performReply("i didn't have anything called '$faqtoid'");
328 # factoid unforget/undelete.
329 if ($message =~ s/^un(forget|delete)\s+//i) {
330 return 'unforget: no addr' unless ($addressed);
332 if (!&IsParam("factoidDeleteDelay")) {
333 &performReply("safe delete has been disable so what is there to undelete?");
337 my $faqtoid = $message;
338 if ($faqtoid eq "") {
343 $faqtoid =~ tr/A-Z/a-z/;
344 my $result = &getFactoid($faqtoid." #DEL#");
345 my $check = &getFactoid($faqtoid);
347 if (!defined $result) {
348 &performReply("i didn't have anything ('$faqtoid') to undelete.");
352 if (defined $check) {
353 &performReply("cannot undeleted '$faqtoid' because it already exists?");
357 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
359 ### delete info. modified_ isn't really used.
360 &setFactInfo($faqtoid, "modified_by", "");
361 &setFactInfo($faqtoid, "modified_time", 0);
363 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
365 $count{'Undelete'}++;
371 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
372 return 'lock: no addr 2' unless ($addressed);
374 my $function = lc $1;
377 if ($faqtoid eq "") {
382 # strongly requested by #debian on 19991028. -xk
383 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
384 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
385 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
389 if (&getFactoid($faqtoid) eq "") {
390 &msg($who, "factoid \002$faqtoid\002 does not exist");
394 if ($function eq "lock") {
397 &CmdUnLock($faqtoid);
404 if ($message =~ s/^rename(\s+|$)//) {
405 return 'rename: no addr' unless ($addressed);
407 if ($message eq "") {
412 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
413 my($from,$to) = (lc $1, lc $2);
415 my $result = &getFactoid($from);
416 if (defined $result) {
417 my $author = &getFactInfo($from, "created_by");
418 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
419 &msg($who, "It's not yours to modify.");
423 if ($_ = &getFactoid($to)) {
424 &performReply("destination factoid already exists.");
428 &setFactInfo($from,"factoid_key",$to);
430 &status("rename: <$who> '$from' is now '$to'");
431 &performReply("i renamed '$from' to '$to'");
433 &performReply("i didn't have anything called '$from'");
436 &msg($who,"error: wrong format. ask me about 'help rename'.");
442 # factoid substitution. (X =~ s/A/B/FLAG)
443 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
444 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
445 return 'subst: no addr' unless ($addressed);
448 if ($np =~ /$delim/) {
449 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
454 if (my $result = &getFactoid($faqtoid)) {
455 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
458 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
459 if (length $result > $param{'maxDataSize'}) {
460 &performReply("that's too long");
463 &setFactInfo($faqtoid, "factoid_value", $result);
464 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
467 &performReply("that doesn't contain '$op'");
470 &performReply("i didn't have anything called '$faqtoid'");
477 # Fix up $message for question.
480 s/^hey([, ]+)where/where/i;
482 s/where can i find/where is/i;
483 s/how about/where is/i;
486 # clear the string of useless words.
487 s/^(stupid )?q(uestion)?:\s+//i;
488 s/^(does )?(any|ne)(1|one|body) know //i;
490 s/^[uh]+m*[,\.]* +//i;
494 s/^(gee|boy|golly|gosh)([, ]+)//i;
495 s/^(well|and|but|or|yes)([, ]+)//i;
497 s/^o+[hk]+(a+y+)?([,. ]+)//i;
498 s/^g(eez|osh|olly)([,. ]+)//i;
499 s/^w(ow|hee|o+ho+)([,. ]+)//i;
500 s/^heya?,?( folks)?([,. ]+)//i;
503 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
504 $correction_plausible = 1;
505 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
507 $correction_plausible = 0;
510 my $result = &doQuestion($message);
512 return 'result is $noreply' if ($result eq $noreply);
514 if (defined $result and $result ne "") { # question.
515 &status("question: <$who> $message");
516 $count{'Question'}++;
517 } elsif (&IsParam("perlMath") and $addressed) { # perl math.
518 &loadMyModule("perlMath");
519 my $newresult = &perlMath();
521 if (defined $newresult and $newresult ne "") {
522 $result = $newresult;
523 &status("math: <$who> $message => $result");
528 &performStrictReply($result);
531 # why would a friendly bot get passed here?
532 if (&IsParam("friendlyBots")) {
533 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
537 if ($_ = &doStatement($message)) {
542 &status("unparseable: $message");
543 &performReply( &getRandom(keys %{$lang{'dunno'}}) );