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.';
222 if (!defined $er or $er ne $noreply) {
223 &performStrictReply($er);
224 return 'SOMETHING 1';
227 ### FIXME: should this only apply to public messages?
229 &DEBUG("floodwho => '$floodwho'.");
230 delete $flood{$floodwho}{$message};
231 &status("short return due to unknown command.");
236 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
238 } elsif ($param{'DBType'} =~ /^none$/i) {
239 return "NO FACTOIDS.";
241 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
249 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
251 &status("infobot <$nuh> identified") unless $bots{$nuh};
257 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
258 my ($target,$item) = ($1,$2);
261 &status(":INFOBOT:QUERY $who: $message");
263 if ($_ = &getFactoid($item)) {
264 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
267 return 'INFOBOT QUERY';
268 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
269 my ($target,$item) = ($1,$2);
271 &status(":INFOBOT:REPLY $who: $message");
273 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
275 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
276 &msg($target, "$who knew: $lhs $mhs $rhs");
279 $rhs = "<REPLY> are" if ($mhs eq "are");
280 &setFactInfo($lhs, "factoid_value", $rhs);
283 return 'INFOBOT REPLY';
285 &ERROR(":INFOBOT:UNKNOWN $who: $message");
286 return 'INFOBOT UNKNOWN';
292 if ($message =~ s/^forget\s+//i) {
293 return 'forget: no addr' unless ($addressed);
295 my $faqtoid = $message;
296 if ($faqtoid eq "") {
301 $faqtoid =~ tr/A-Z/a-z/;
302 my $result = &getFactoid($faqtoid);
304 if (defined $result) {
305 my $author = &getFactInfo($faqtoid, "created_by");
306 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
307 &msg($who, "you don't have access to remove that factoid");
311 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
313 if (&IsParam("factoidDeleteDelay")) {
314 &status("forgot (safe delete): <$who> '$faqtoid' =is=> '$result'");
315 &setFactInfo($faqtoid, "factoid_key", $faqtoid." #DEL#");
317 ### delete info. modified_ isn't really used.
318 &setFactInfo($faqtoid, "modified_by", $who);
319 &setFactInfo($faqtoid, "modified_time", time());
321 &status("forget: <$who> '$faqtoid' =is=> '$result'");
322 &delFactoid($faqtoid);
325 &performReply("i forgot $faqtoid");
329 &performReply("i didn't have anything called '$faqtoid'");
335 # factoid unforget/undelete.
336 if ($message =~ s/^un(forget|delete)\s+//i) {
337 return 'unforget: no addr' unless ($addressed);
339 if (!&IsParam("factoidDeleteDelay")) {
340 &performReply("safe delete has been disable so what is there to undelete?");
344 my $faqtoid = $message;
345 if ($faqtoid eq "") {
350 $faqtoid =~ tr/A-Z/a-z/;
351 my $result = &getFactoid($faqtoid." #DEL#");
352 my $check = &getFactoid($faqtoid);
354 if (!defined $result) {
355 &performReply("i didn't have anything ('$faqtoid') to undelete.");
359 if (defined $check) {
360 &performReply("cannot undeleted '$faqtoid' because it already exists?");
364 &setFactInfo($faqtoid." #DEL#", "factoid_key", $faqtoid);
366 ### delete info. modified_ isn't really used.
367 &setFactInfo($faqtoid, "modified_by", "");
368 &setFactInfo($faqtoid, "modified_time", 0);
370 &performReply("Successfully recovered '$faqtoid'. Have fun now.");
372 $count{'Undelete'}++;
378 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
379 return 'lock: no addr 2' unless ($addressed);
381 my $function = lc $1;
384 if ($faqtoid eq "") {
389 # strongly requested by #debian on 19991028. -xk
390 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
391 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
392 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
396 if (&getFactoid($faqtoid) eq "") {
397 &msg($who, "factoid \002$faqtoid\002 does not exist");
401 if ($function eq "lock") {
404 &CmdUnLock($faqtoid);
411 if ($message =~ s/^rename(\s+|$)//) {
412 return 'rename: no addr' unless ($addressed);
414 if ($message eq "") {
419 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
420 my($from,$to) = (lc $1, lc $2);
422 my $result = &getFactoid($from);
423 if (defined $result) {
424 my $author = &getFactInfo($from, "created_by");
425 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
426 &msg($who, "It's not yours to modify.");
430 if ($_ = &getFactoid($to)) {
431 &performReply("destination factoid already exists.");
435 &setFactInfo($from,"factoid_key",$to);
437 &status("rename: <$who> '$from' is now '$to'");
438 &performReply("i renamed '$from' to '$to'");
440 &performReply("i didn't have anything called '$from'");
443 &msg($who,"error: wrong format. ask me about 'help rename'.");
449 # factoid substitution. (X =~ s/A/B/FLAG)
450 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
451 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
452 return 'subst: no addr' unless ($addressed);
455 if ($np =~ /$delim/) {
456 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
461 if (my $result = &getFactoid($faqtoid)) {
462 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
465 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
466 if (length $result > $param{'maxDataSize'}) {
467 &performReply("that's too long");
470 &setFactInfo($faqtoid, "factoid_value", $result);
471 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
474 &performReply("that doesn't contain '$op'");
477 &performReply("i didn't have anything called '$faqtoid'");
484 # Fix up $message for question.
487 s/^hey([, ]+)where/where/i;
489 s/where can i find/where is/i;
490 s/how about/where is/i;
493 # clear the string of useless words.
494 s/^(stupid )?q(uestion)?:\s+//i;
495 s/^(does )?(any|ne)(1|one|body) know //i;
497 s/^[uh]+m*[,\.]* +//i;
501 s/^(gee|boy|golly|gosh)([, ]+)//i;
502 s/^(well|and|but|or|yes)([, ]+)//i;
504 s/^o+[hk]+(a+y+)?([,. ]+)//i;
505 s/^g(eez|osh|olly)([,. ]+)//i;
506 s/^w(ow|hee|o+ho+)([,. ]+)//i;
507 s/^heya?,?( folks)?([,. ]+)//i;
510 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
511 $correction_plausible = 1;
512 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
514 $correction_plausible = 0;
517 my $result = &doQuestion($message);
518 if (!defined $result or $result eq $noreply) {
519 return 'result from doQ undef.';
522 if (defined $result and $result ne "") { # question.
523 &status("question: <$who> $message");
524 $count{'Question'}++;
525 } elsif (&IsChanConf("perlMath") > 0 and $addressed) { # perl math.
526 &loadMyModule("perlMath");
527 my $newresult = &perlMath();
529 if (defined $newresult and $newresult ne "") {
530 $result = $newresult;
531 &status("math: <$who> $message => $result");
536 &performStrictReply($result);
539 # why would a friendly bot get passed here?
540 if (&IsParam("friendlyBots")) {
541 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
545 if (defined &doStatement($message)) {
549 return unless ($addressed);
551 if (length $message > 64) {
552 &status("unparseable-moron: $message");
553 &performReply( &getRandom(keys %{$lang{'moron'}}) );
558 &status("unparseable: $message");
559 &performReply( &getRandom(keys %{$lang{'dunno'}}) );