2 ### Process.pl: Kevin Lenzo 1997-1999
6 # process the incoming message
11 use vars qw($who $msgType $addressed $message $ident $user $host $chan
12 $learnok $talkok $force_public_reply $noreply $addrchar
13 $literal $addressedother $userHandle $lobotomized);
14 use vars qw(%channels %users %param %cache %chanconf %mask %orig %lang
18 $learnok = 0; # Able to learn?
19 $talkok = 0; # Able to yap?
20 $force_public_reply = 0;
23 return 'X' if $who eq $ident; # self-message.
24 return 'addressedother set' if ($addressedother);
26 $talkok = ($param{'addressing'} =~ /^OPTIONAL$/i or $addressed);
27 $learnok = ($param{'learn'} =~ /^HUNGRY$/i or $addressed);
31 # hack to support channel +o as "+o" in bot user file.
32 # requires +O in user file.
33 # is $who arg lowercase?
34 if (exists $channels{$chan}{o}{ $orig{who} } && &IsFlag("O") eq "O") {
35 &status("Gave $who/$chan +o (+O)\'ness");
36 $users{$userHandle}{FLAGS} .= "o";
39 # check if we have our head intact.
41 if ($addressed and IsFlag("o") eq "o") {
42 my $delta_time = time() - ($cache{lobotomy}{$who} || 0);
43 &msg($who, "give me an unlobotomy.") if ($delta_time > 60*60);
44 $cache{lobotomy}{$who} = time();
50 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
51 if ($msgType =~ /public/ and $addressed) {
52 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
53 "while you sent a message to me ${msgType}ly.");
59 # join, must be done before outsider checking.
60 if ($message =~ /^join(\s+(.*))?\s*$/i) {
61 return 'join: not addr' unless ($addressed);
63 $2 =~ /^($mask{chan})(,(\S+))?/;
64 my($thischan, $key) = (lc $1, $3);
65 my $chankey = lc $thischan;
66 $chankey .= " $key" if (defined $key);
68 if ($thischan eq "") {
73 if (&IsFlag("o") ne "o") {
74 if (!exists $chanconf{$thischan}) {
75 &msg($who, "I am not allowed to join $thischan.");
79 if (&validChan($thischan)) {
80 &msg($who,"warn: I'm already on $thischan, joining anyway...");
84 $cache{join}{$thischan} = $who; # used for on_join self.
87 &status("JOIN $chankey <$who>");
88 &msg($who, "joining $chankey");
89 &joinNextChan(); # hack.
95 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
96 $message =~ s/^\s+|\s+$//g;
97 my @array = split / /, $message;
99 if ($who =~ /^_default$/i) {
100 &pSReply("you are too eleet.");
104 if (!scalar @array or scalar @array > 2) {
109 my $do_nick = $array[1] || $who;
111 if (!exists $users{$do_nick}) {
112 &pSReply("nick $do_nick is not in user list.");
116 my $crypt = $users{$do_nick}{PASS};
117 if (!defined $crypt) {
118 &pSReply("user $do_nick has no passwd set.");
122 if (!&ckpasswd($array[0], $crypt)) {
123 &pSReply("invalid passwd for $do_nick.");
127 my $mask = "*!$user@".&makeHostMask($host);
128 ### TODO: prevent adding multiple dupe masks?
129 ### TODO: make &addHostMask() CMD?
130 &pSReply("Added $mask for $do_nick...");
131 $users{$do_nick}{HOSTS}{$mask} = 1;
137 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
138 $message =~ s/^\s+|\s+$//g;
139 my @array = split ' ', $message;
141 if ($who =~ /^_default$/i) {
142 &pSReply("you are too eleet.");
146 if (scalar @array != 1) {
151 # todo: use &getUser()?
153 foreach (keys %users) {
154 if ($users{$_}{FLAGS} =~ /n/) {
160 if (!exists $users{$who} and !$first) {
161 &pSReply("nick $who is not in user list.");
166 &pSReply("First time user... adding you as Master.");
167 $users{$who}{FLAGS} = "mrsteon";
170 my $crypt = $users{$who}{PASS};
171 if (defined $crypt) {
172 &pSReply("user $who already has pass set.");
176 if (!defined $host) {
177 &WARN("pass: host == NULL.");
181 if (!scalar keys %{ $users{$who}{HOSTS} }) {
182 my $mask = "*!$user@".&makeHostMask($host);
183 &pSReply("Added hostmask '\002$mask\002' to $who");
184 $users{$who}{HOSTS}{$mask} = 1;
187 $crypt = &mkcrypt($array[0]);
188 $users{$who}{PASS} = $crypt;
189 &pSReply("new pass for $who, crypt $crypt.");
195 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
198 foreach (keys %channels) {
199 # don't test for $channel{_default} elsewhere !!!
200 next if (/^\s*$/ || /^_?default$/);
201 next unless (&IsNickInChan($who,$_));
207 if (!$found and scalar(keys %channels)) {
208 &status("OUTSIDER <$who> $message");
214 if ($msgType =~ /public/ and $message =~ s/^\+//) {
215 &status("Process: '+' flag detected; changing reply to public");
217 $who = $chan; # major hack to fix &msg().
218 $force_public_reply++;
219 # notice is still NOTICE but to whole channel => good.
222 # User Processing, for all users.
225 return 'returned from pCH' if &parseCmdHook("main",$message);
227 $retval = &userCommands();
228 return unless (defined $retval);
229 return if ($retval eq $noreply);
233 # once useless messages have been parsed out, we match them.
236 # confused? is this for infobot communications?
237 foreach (keys %{ $lang{'confused'} }) {
240 next unless ($message =~ /^\Q$y\E\s*/);
244 # hello. [took me a while to fix this. -xk]
245 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
246 return '' unless ($talkok);
248 # 'mynick: hi' or 'hi mynick' or 'hi'.
249 &status("somebody said hello");
251 # 50% chance of replying to a random greeting when not addressed
252 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
253 &status("not returning unaddressed greeting");
257 # customized random message.
258 my $tmp = (rand() < 0.5) ? ", $who" : "";
259 &pSReply( &getRandom(keys %{ $lang{'hello'} }) . $tmp );
264 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
265 my $reply = &getRandom(keys %{ $lang{'howareyou'} });
267 &performReply($reply);
273 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
274 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
276 return 'praise: no addr' unless ($addressed);
278 &status("random praise detected");
280 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
287 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
288 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
290 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
299 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
300 return '' unless (&hasParam("karma"));
301 # well... since it is policy to do bot functions before factoids
302 # karma gets hit if, for example, "g++" is issued.
303 # only way to request it is to put a question mark at the end.
305 my($term,$inc) = (lc $1,$2);
307 if ($msgType !~ /public/i) {
308 &msg($who, "karma must be done in public!");
312 if (lc $term eq lc $who) {
313 &msg($who, "please don't karma yourself");
317 my $karma = &dbGet("stats", "counter",
318 "nick=".&dbQuote($term)." AND type='karma'") || 0;
326 { nick => $term, type => "karma" }, # WHERE
327 # { counter => $karma } # WHAT
328 { -counter => "counter+1" }
334 # here's where the external routines get called.
335 # if they return anything but null, that's the "answer".
337 if ( &parseCmdHook("extra",$message) ) {
338 return 'DID SOMETHING IN PCH.';
343 return 'SOMETHING 1';
346 if (0 and $addrchar) {
347 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
352 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|sqlite|pgsql|dbm)/i) {
354 } elsif ($param{'DBType'} =~ /^none$/i) {
355 return "NO FACTOIDS.";
357 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");