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.
108 if ($message =~ /^\Q$ident\E\s*\?*$/i) {
109 &status("feedback addressing from $who");
111 &performReply("yes?");
116 # confused? is this for infobot communications?
117 foreach (keys %{$lang{'confused'}}) {
120 next unless ($message =~ /^\Q$y\E\s*/);
124 # hello. [took me a while to fix this. -xk]
125 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
126 return '' unless ($talkok);
128 # 'mynick: hi' or 'hi mynick' or 'hi'.
129 &status("somebody said hello");
131 # 50% chance of replying to a random greeting when not addressed
132 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
133 &status("not returning unaddressed greeting");
137 # customized random message.
138 my $tmp = (rand() < 0.5) ? ", $who" : "";
139 &performStrictReply(&getRandom(keys %{$lang{'hello'}}) . $tmp);
144 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
145 my $reply = &getRandom(keys %{$lang{'howareyou'}});
147 &performReply($reply);
153 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
154 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
156 return 'praise: no addr' unless ($addressed);
158 &status("random praise detected");
160 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
161 &performStrictReply($tmp.":)");
167 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
168 &DEBUG("thanks: talkok => '$talkok', addressed => '$addressed'.");
169 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
171 &performReply( &getRandom(keys %{$lang{'welcome'}}) );
181 if ($msgType =~ /public/ and $message =~ s/^\+//) {
182 &status("found '+' flag; setting msgType to public.");
183 $force_public_reply++;
189 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
190 return '' unless (&hasParam("karma"));
192 my($term,$inc) = (lc $1,$2);
194 if ($msgType !~ /public/i) {
195 &msg($who, "karma must be done in public!");
199 if (lc($term) eq lc($who)) {
200 &msg($who, "please don't karma yourself");
204 my $karma = &dbGet("karma", "nick",$term,"karma") || 0;
211 &dbSet("karma", "nick",$term,"karma",$karma);
216 # here's where the external routines get called.
217 # if they return anything but null, that's the "answer".
221 &performStrictReply($er) if ($er ne $noreply);
222 return 'SOMETHING 1';
225 ### FIXME: should this only apply to public messages?
227 &DEBUG("floodwho => '$floodwho'.");
228 delete $flood{$floodwho}{$message};
229 &status("short return due to unknown command.");
234 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
236 } elsif ($param{'DBType'} =~ /^none$/i) {
237 return "NO FACTOIDS.";
239 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
247 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
249 &status("infobot <$nuh> identified") unless $bots{$nuh};
255 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
256 my ($target,$item) = ($1,$2);
259 &status(":INFOBOT:QUERY $who: $message");
261 if ($_ = &getFactoid($item)) {
262 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
265 return 'INFOBOT QUERY';
266 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
267 my ($target,$item) = ($1,$2);
269 &status(":INFOBOT:REPLY $who: $message");
271 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
273 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
274 &msg($target, "$who knew: $lhs $mhs $rhs");
277 $rhs = "<REPLY> are" if ($mhs eq "are");
278 &setFactInfo($lhs, "factoid_value", $rhs);
281 return 'INFOBOT REPLY';
283 &ERROR(":INFOBOT:UNKNOWN $who: $message");
284 return 'INFOBOT UNKNOWN';
290 if ($message =~ s/^forget\s+//i) {
291 return 'forget: no addr' unless ($addressed);
293 my $faqtoid = $message;
294 if ($faqtoid eq "") {
299 $faqtoid =~ tr/A-Z/a-z/;
300 my $result = &getFactoid($faqtoid);
302 if (defined $result) {
303 my $author = &getFactInfo($faqtoid, "created_by");
304 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
305 &msg($who, "you don't have access to remove that factoid");
309 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
311 &status("forget: <$who> '$faqtoid' =is=> '$result'");
312 &delFactoid($faqtoid);
314 &performReply("i forgot $faqtoid");
318 &performReply("i didn't have anything called '$faqtoid'");
325 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
326 return 'lock: no addr 2' unless ($addressed);
328 my $function = lc $1;
331 if ($faqtoid eq "") {
336 # strongly requested by #debian on 19991028. -xk
337 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
338 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
339 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
343 if (&getFactoid($faqtoid) eq "") {
344 &msg($who, "factoid \002$faqtoid\002 does not exist");
348 if ($function eq "lock") {
351 &CmdUnLock($faqtoid);
358 if ($message =~ s/^rename(\s+|$)//) {
359 return 'rename: no addr' unless ($addressed);
361 if ($message eq "") {
366 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
367 my($from,$to) = (lc $1, lc $2);
369 my $result = &getFactoid($from);
370 if (defined $result) {
371 my $author = &getFactInfo($from, "created_by");
372 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
373 &msg($who, "It's not yours to modify.");
377 if ($_ = &getFactoid($to)) {
378 &performReply("destination factoid already exists.");
382 &setFactInfo($from,"factoid_key",$to);
384 &status("rename: <$who> '$from' is now '$to'");
385 &performReply("i renamed '$from' to '$to'");
387 &performReply("i didn't have anything called '$from'");
390 &msg($who,"error: wrong format. ask me about 'help rename'.");
396 # factoid substitution. (X =~ s/A/B/FLAG)
397 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
398 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
399 return 'subst: no addr' unless ($addressed);
402 if ($np =~ /$delim/) {
403 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
408 if (my $result = &getFactoid($faqtoid)) {
409 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
412 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
413 if (length $result > $param{'maxDataSize'}) {
414 &performReply("that's too long");
417 &setFactInfo($faqtoid, "factoid_value", $result);
418 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
421 &performReply("that doesn't contain '$op'");
424 &performReply("i didn't have anything called '$faqtoid'");
431 # Fix up $message for question.
434 s/^hey([, ]+)where/where/i;
436 s/where can i find/where is/i;
437 s/how about/where is/i;
440 # clear the string of useless words.
441 s/^(stupid )?q(uestion)?:\s+//i;
442 s/^(does )?(any|ne)(1|one|body) know //i;
444 s/^[uh]+m*[,\.]* +//i;
448 s/^(gee|boy|golly|gosh)([, ]+)//i;
449 s/^(well|and|but|or|yes)([, ]+)//i;
451 s/^o+[hk]+(a+y+)?([,. ]+)//i;
452 s/^g(eez|osh|olly)([,. ]+)//i;
453 s/^w(ow|hee|o+ho+)([,. ]+)//i;
454 s/^heya?,?( folks)?([,. ]+)//i;
457 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
458 $correction_plausible = 1;
459 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
461 $correction_plausible = 0;
464 my $result = &doQuestion($message);
466 return 'result is $noreply' if ($result eq $noreply);
468 if (defined $result and $result ne "") { # question.
469 &status("question: <$who> $message");
470 $count{'Question'}++;
471 } elsif (&IsParam("perlMath") and $addressed) { # perl math.
472 &loadMyModule("perlMath");
473 my $newresult = &perlMath();
475 if (defined $newresult and $newresult ne "") {
476 $result = $newresult;
477 &status("math: <$who> $message => $result");
482 &performStrictReply($result);
485 # why would a friendly bot get passed here?
486 if (&IsParam("friendlyBots")) {
487 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
491 if ($_ = &doStatement($message)) {
496 &status("unparseable: $message");
497 &performReply( &getRandom(keys %{$lang{'dunno'}}) );