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".
213 &performStrictReply($er) if ($er ne $noreply);
214 return 'SOMETHING 1';
217 ### FIXME: should this only apply to public messages?
219 &DEBUG("floodwho => '$floodwho'.");
220 delete $flood{$floodwho}{$message};
221 &status("short return due to unknown command.");
226 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pg|postgres|dbm)/i) {
228 } elsif ($param{'DBType'} =~ /^none$/i) {
229 return "NO FACTOIDS.";
231 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");
239 if ($msgType =~ /private/ and $message =~ s/^:INFOBOT://) {
241 &status("infobot <$nuh> identified") unless $bots{$nuh};
247 if ($message =~ /^QUERY (<.*?>) (.*)/) { # query.
248 my ($target,$item) = ($1,$2);
251 &status(":INFOBOT:QUERY $who: $message");
253 if ($_ = &getFactoid($item)) {
254 &msg($who, ":INFOBOT:REPLY $target $item =is=> $_");
257 return 'INFOBOT QUERY';
258 } elsif ($message =~ /^REPLY <(.*?)> (.*)/) { # reply.
259 my ($target,$item) = ($1,$2);
261 &status(":INFOBOT:REPLY $who: $message");
263 my ($lhs,$mhs,$rhs) = $item =~ /^(.*?) =(.*?)=> (.*)/;
265 if ($param{'acceptUrl'} !~ /REQUIRE/ or $rhs =~ /(http|ftp|mailto|telnet|file):/) {
266 &msg($target, "$who knew: $lhs $mhs $rhs");
269 $rhs = "<REPLY> are" if ($mhs eq "are");
270 &setFactInfo($lhs, "factoid_value", $rhs);
273 return 'INFOBOT REPLY';
275 &ERROR(":INFOBOT:UNKNOWN $who: $message");
276 return 'INFOBOT UNKNOWN';
282 if ($message =~ s/^forget\s+//i) {
283 return 'forget: no addr' unless ($addressed);
285 my $faqtoid = $message;
286 if ($faqtoid eq "") {
291 $faqtoid =~ tr/A-Z/a-z/;
292 my $result = &getFactoid($faqtoid);
294 if (defined $result) {
295 my $author = &getFactInfo($faqtoid, "created_by");
296 if (IsFlag("r") ne "r" && $author =~ /^\Q$who\E\!/i) {
297 &msg($who, "you don't have access to remove that factoid");
301 return 'locked factoid' if (&IsLocked($faqtoid) == 1);
303 &status("forget: <$who> '$faqtoid' =is=> '$result'");
304 &delFactoid($faqtoid);
306 &performReply("i forgot $faqtoid");
310 &performReply("i didn't have anything called '$faqtoid'");
317 if ($message =~ /^((un)?lock)(\s+(.*))?\s*?$/i) {
318 return 'lock: no addr 2' unless ($addressed);
320 my $function = lc $1;
323 if ($faqtoid eq "") {
328 # strongly requested by #debian on 19991028. -xk
329 if (1 and $faqtoid !~ /^\Q$who\E$/i and &IsFlag("o") ne "o") {
330 &msg($who,"sorry, locking cannot be used since it can be abused unneccesarily.");
331 &status("Replace 1 with 0 in Process.pl#~324 for locking support.");
335 if (&getFactoid($faqtoid) eq "") {
336 &msg($who, "factoid \002$faqtoid\002 does not exist");
340 if ($function eq "lock") {
343 &CmdUnLock($faqtoid);
350 if ($message =~ s/^rename(\s+|$)//) {
351 return 'rename: no addr' unless ($addressed);
353 if ($message eq "") {
358 if ($message =~ /^'(.*)'\s+'(.*)'$/) {
359 my($from,$to) = (lc $1, lc $2);
361 my $result = &getFactoid($from);
362 if (defined $result) {
363 my $author = &getFactInfo($from, "created_by");
364 if (&IsFlag("m") and $author =~ /^\Q$who\E\!/i) {
365 &msg($who, "It's not yours to modify.");
369 if ($_ = &getFactoid($to)) {
370 &performReply("destination factoid already exists.");
374 &setFactInfo($from,"factoid_key",$to);
376 &status("rename: <$who> '$from' is now '$to'");
377 &performReply("i renamed '$from' to '$to'");
379 &performReply("i didn't have anything called '$from'");
382 &msg($who,"error: wrong format. ask me about 'help rename'.");
388 # factoid substitution. (X =~ s/A/B/FLAG)
389 if ($message =~ m|^(.*?)\s+=~\s+s([/,#])(.+?)\2(.*?)\2([a-z]*);?\s*$|) {
390 my ($faqtoid,$delim,$op,$np,$flags) = (lc $1, $2, $3, $4, $5);
391 return 'subst: no addr' unless ($addressed);
394 if ($np =~ /$delim/) {
395 &msg($who,"looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
400 if (my $result = &getFactoid($faqtoid)) {
401 return 'subst: locked' if (&IsLocked($faqtoid) == 1);
404 if (($flags eq "g" && $result =~ s/\Q$op/$np/gi) || $result =~ s/\Q$op/$np/i) {
405 if (length $result > $param{'maxDataSize'}) {
406 &performReply("that's too long");
409 &setFactInfo($faqtoid, "factoid_value", $result);
410 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
413 &performReply("that doesn't contain '$op'");
416 &performReply("i didn't have anything called '$faqtoid'");
423 # Fix up $message for question.
426 s/^hey([, ]+)where/where/i;
428 s/where can i find/where is/i;
429 s/how about/where is/i;
432 # clear the string of useless words.
433 s/^(stupid )?q(uestion)?:\s+//i;
434 s/^(does )?(any|ne)(1|one|body) know //i;
436 s/^[uh]+m*[,\.]* +//i;
440 s/^(gee|boy|golly|gosh)([, ]+)//i;
441 s/^(well|and|but|or|yes)([, ]+)//i;
443 s/^o+[hk]+(a+y+)?([,. ]+)//i;
444 s/^g(eez|osh|olly)([,. ]+)//i;
445 s/^w(ow|hee|o+ho+)([,. ]+)//i;
446 s/^heya?,?( folks)?([,. ]+)//i;
449 if ($addressed and $message =~ s/^no([, ]+)(\Q$ident\E\,+)?\s*//i) {
450 $correction_plausible = 1;
451 &status("correction is plausible, initial negative and nick deleted ($&)") if ($param{VERBOSITY});
453 $correction_plausible = 0;
456 my $result = &doQuestion($message);
458 return 'result is $noreply' if ($result eq $noreply);
460 if (defined $result and $result ne "") { # question.
461 &status("question: <$who> $message");
462 $count{'Question'}++;
463 } elsif (&IsParam("perlMath") and $addressed) { # perl math.
464 &loadMyModule("perlMath");
465 my $newresult = &perlMath();
467 if (defined $newresult and $newresult ne "") {
468 $result = $newresult;
469 &status("math: <$who> $message => $result");
474 &performStrictReply($result);
477 # why would a friendly bot get passed here?
478 if (&IsParam("friendlyBots")) {
479 return if (grep lc($_) eq lc($who), split(/\s+/, $param{'friendlyBots'}));
483 if ($_ = &doStatement($message)) {
488 &status("unparseable: $message");
489 &performReply( &getRandom(keys %{$lang{'dunno'}}) );