2 ### Process.pl: Kevin Lenzo 1997-1999
6 # process the incoming message
12 $learnok = 0; # Able to learn?
13 $talkok = 0; # Able to yap?
14 $force_public_reply = 0;
17 return 'X' if $who eq $ident; # self-message.
18 return 'addressedother set' if ($addressedother);
20 $talkok = ($param{'addressing'} =~ /^OPTIONAL$/i or $addressed);
21 $learnok = ($param{'learn'} =~ /^HUNGRY$/i or $addressed);
25 # check if we have our head intact.
27 if ($addressed and IsFlag("o") eq "o") {
28 my $delta_time = time() - ($cache{lobotomy}{$who} || 0);
29 &msg($who, "give me an unlobotomy.") if ($delta_time > 60*60);
30 $cache{lobotomy}{$who} = time();
36 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
37 if ($msgType =~ /public/ and $addressed) {
38 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
39 "while you sent a message to me ${msgType}ly.");
45 # join, must be done before outsider checking.
46 if ($message =~ /^join(\s+(.*))?\s*$/i) {
47 return 'join: not addr' unless ($addressed);
49 $2 =~ /^($mask{chan})(,(\S+))?/;
50 my($thischan, $key) = (lc $1, $3);
51 my $chankey = lc $thischan;
52 $chankey .= " $key" if (defined $key);
54 if ($thischan eq "") {
59 if (&IsFlag("o") ne "o") {
60 if (!exists $chanconf{$thischan}) {
61 &msg($who, "I am not allowed to join $thischan.");
65 if (&validChan($thischan)) {
66 &msg($who,"warn: I'm already on $thischan, joining anyway...");
70 $cache{join}{$thischan} = $who; # used for on_join self.
73 &status("JOIN $chankey <$who>");
74 &msg($who, "joining $chankey");
75 &joinNextChan(); # hack.
81 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
82 $message =~ s/^\s+|\s+$//g;
83 my @array = split / /, $message;
85 if ($who =~ /^_default$/i) {
86 &pSReply("you are too eleet.");
90 if (!scalar @array or scalar @array > 2) {
95 my $do_nick = $array[1] || $who;
97 if (!exists $users{$do_nick}) {
98 &pSReply("nick $do_nick is not in user list.");
102 my $crypt = $users{$do_nick}{PASS};
103 if (!defined $crypt) {
104 &pSReply("user $do_nick has no passwd set.");
108 if (!&ckpasswd($array[0], $crypt)) {
109 &pSReply("invalid passwd for $do_nick.");
113 my $mask = "*!$user@".&makeHostMask($host);
114 ### TODO: prevent adding multiple dupe masks?
115 ### TODO: make &addHostMask() CMD?
116 &pSReply("Added $mask for $do_nick...");
117 $users{$do_nick}{HOSTS}{$mask} = 1;
123 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
124 $message =~ s/^\s+|\s+$//g;
125 my @array = split ' ', $message;
127 if ($who =~ /^_default$/i) {
128 &pSReply("you are too eleet.");
132 if (scalar @array != 1) {
137 # todo: use &getUser()?
139 foreach (keys %users) {
140 if ($users{$_}{FLAGS} =~ /n/) {
146 if (!exists $users{$who} and !$first) {
147 &pSReply("nick $who is not in user list.");
152 &pSReply("First time user... adding you as Master.");
153 $users{$who}{FLAGS} = "mrsteon";
156 my $crypt = $users{$who}{PASS};
157 if (defined $crypt) {
158 &pSReply("user $who already has pass set.");
162 if (!defined $host) {
163 &WARN("pass: host == NULL.");
167 if (!scalar keys %{ $users{$who}{HOSTS} }) {
168 my $mask = "*!$user@".&makeHostMask($host);
169 &pSReply("Added hostmask '\002$mask\002' to $who");
170 $users{$who}{HOSTS}{$mask} = 1;
173 $crypt = &mkcrypt($array[0]);
174 $users{$who}{PASS} = $crypt;
175 &pSReply("new pass for $who, crypt $crypt.");
181 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
184 foreach (keys %channels) {
185 next unless (&IsNickInChan($who,$_));
191 if (!$found and scalar(keys %channels)) {
192 &status("OUTSIDER <$who> $message");
198 if ($msgType =~ /public/ and $message =~ s/^\+//) {
199 &status("Process: '+' flag detected; changing reply to public");
201 $who = $chan; # major hack to fix &msg().
202 $force_public_reply++;
203 # notice is still NOTICE but to whole channel => good.
206 # User Processing, for all users.
209 return 'returned from pCH' if &parseCmdHook("main",$message);
211 $retval = &userCommands();
212 return unless (defined $retval);
213 return if ($retval eq $noreply);
217 # once useless messages have been parsed out, we match them.
220 # confused? is this for infobot communications?
221 foreach (keys %{ $lang{'confused'} }) {
224 next unless ($message =~ /^\Q$y\E\s*/);
228 # hello. [took me a while to fix this. -xk]
229 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
230 return '' unless ($talkok);
232 # 'mynick: hi' or 'hi mynick' or 'hi'.
233 &status("somebody said hello");
235 # 50% chance of replying to a random greeting when not addressed
236 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
237 &status("not returning unaddressed greeting");
241 # customized random message.
242 my $tmp = (rand() < 0.5) ? ", $who" : "";
243 &pSReply( &getRandom(keys %{ $lang{'hello'} }) . $tmp );
248 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
249 my $reply = &getRandom(keys %{ $lang{'howareyou'} });
251 &performReply($reply);
257 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
258 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
260 return 'praise: no addr' unless ($addressed);
262 &status("random praise detected");
264 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
271 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
272 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
274 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
283 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
284 return '' unless (&hasParam("karma"));
286 my($term,$inc) = (lc $1,$2);
288 if ($msgType !~ /public/i) {
289 &msg($who, "karma must be done in public!");
293 if (lc $term eq lc $who) {
294 &msg($who, "please don't karma yourself");
298 my $karma = &dbGet("stats", "counter", "nick=".&dbQuote($term).
299 " AND type='karma'") || 0;
307 { nick => $term, type => "karma" },
308 { counter => $karma }
314 # here's where the external routines get called.
315 # if they return anything but null, that's the "answer".
317 if ( &parseCmdHook("extra",$message) ) {
318 return 'DID SOMETHING IN PCH.';
323 return 'SOMETHING 1';
326 if (0 and $addrchar) {
327 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
332 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pgsql|dbm)/i) {
334 } elsif ($param{'DBType'} =~ /^none$/i) {
335 return "NO FACTOIDS.";
337 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");