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 # hack to support channel +o as "+o" in bot user file.
26 # requires +O in user file.
27 # is $who arg lowercase?
28 if (exists $channels{$chan}{o}{ $orig{who} } && &IsFlag("O") eq "O") {
29 &status("Gave $who/$chan +o (+O)\'ness");
30 $users{$userHandle}{FLAGS} =~ s/o//g;
31 $users{$userHandle}{FLAGS} .= "o";
34 # check if we have our head intact.
36 if ($addressed and IsFlag("o") eq "o") {
37 my $delta_time = time() - ($cache{lobotomy}{$who} || 0);
38 &msg($who, "give me an unlobotomy.") if ($delta_time > 60*60);
39 $cache{lobotomy}{$who} = time();
45 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
46 if ($msgType =~ /public/ and $addressed) {
47 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
48 "while you sent a message to me ${msgType}ly.");
54 # join, must be done before outsider checking.
55 if ($message =~ /^join(\s+(.*))?\s*$/i) {
56 return 'join: not addr' unless ($addressed);
58 $2 =~ /^($mask{chan})(,(\S+))?/;
59 my($thischan, $key) = (lc $1, $3);
60 my $chankey = lc $thischan;
61 $chankey .= " $key" if (defined $key);
63 if ($thischan eq "") {
68 if (&IsFlag("o") ne "o") {
69 if (!exists $chanconf{$thischan}) {
70 &msg($who, "I am not allowed to join $thischan.");
74 if (&validChan($thischan)) {
75 &msg($who,"warn: I'm already on $thischan, joining anyway...");
79 $cache{join}{$thischan} = $who; # used for on_join self.
82 &status("JOIN $chankey <$who>");
83 &msg($who, "joining $chankey");
84 &joinNextChan(); # hack.
90 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
91 $message =~ s/^\s+|\s+$//g;
92 my @array = split / /, $message;
94 if ($who =~ /^_default$/i) {
95 &pSReply("you are too eleet.");
99 if (!scalar @array or scalar @array > 2) {
104 my $do_nick = $array[1] || $who;
106 if (!exists $users{$do_nick}) {
107 &pSReply("nick $do_nick is not in user list.");
111 my $crypt = $users{$do_nick}{PASS};
112 if (!defined $crypt) {
113 &pSReply("user $do_nick has no passwd set.");
117 if (!&ckpasswd($array[0], $crypt)) {
118 &pSReply("invalid passwd for $do_nick.");
122 my $mask = "*!$user@".&makeHostMask($host);
123 ### TODO: prevent adding multiple dupe masks?
124 ### TODO: make &addHostMask() CMD?
125 &pSReply("Added $mask for $do_nick...");
126 $users{$do_nick}{HOSTS}{$mask} = 1;
132 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
133 $message =~ s/^\s+|\s+$//g;
134 my @array = split ' ', $message;
136 if ($who =~ /^_default$/i) {
137 &pSReply("you are too eleet.");
141 if (scalar @array != 1) {
146 # todo: use &getUser()?
148 foreach (keys %users) {
149 if ($users{$_}{FLAGS} =~ /n/) {
155 if (!exists $users{$who} and !$first) {
156 &pSReply("nick $who is not in user list.");
161 &pSReply("First time user... adding you as Master.");
162 $users{$who}{FLAGS} = "mrsteon";
165 my $crypt = $users{$who}{PASS};
166 if (defined $crypt) {
167 &pSReply("user $who already has pass set.");
171 if (!defined $host) {
172 &WARN("pass: host == NULL.");
176 if (!scalar keys %{ $users{$who}{HOSTS} }) {
177 my $mask = "*!$user@".&makeHostMask($host);
178 &pSReply("Added hostmask '\002$mask\002' to $who");
179 $users{$who}{HOSTS}{$mask} = 1;
182 $crypt = &mkcrypt($array[0]);
183 $users{$who}{PASS} = $crypt;
184 &pSReply("new pass for $who, crypt $crypt.");
190 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
193 foreach (keys %channels) {
194 next unless (&IsNickInChan($who,$_));
200 if (!$found and scalar(keys %channels)) {
201 &status("OUTSIDER <$who> $message");
207 if ($msgType =~ /public/ and $message =~ s/^\+//) {
208 &status("Process: '+' flag detected; changing reply to public");
210 $who = $chan; # major hack to fix &msg().
211 $force_public_reply++;
212 # notice is still NOTICE but to whole channel => good.
215 # User Processing, for all users.
218 return 'returned from pCH' if &parseCmdHook("main",$message);
220 $retval = &userCommands();
221 return unless (defined $retval);
222 return if ($retval eq $noreply);
226 # once useless messages have been parsed out, we match them.
229 # confused? is this for infobot communications?
230 foreach (keys %{ $lang{'confused'} }) {
233 next unless ($message =~ /^\Q$y\E\s*/);
237 # hello. [took me a while to fix this. -xk]
238 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
239 return '' unless ($talkok);
241 # 'mynick: hi' or 'hi mynick' or 'hi'.
242 &status("somebody said hello");
244 # 50% chance of replying to a random greeting when not addressed
245 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
246 &status("not returning unaddressed greeting");
250 # customized random message.
251 my $tmp = (rand() < 0.5) ? ", $who" : "";
252 &pSReply( &getRandom(keys %{ $lang{'hello'} }) . $tmp );
257 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
258 my $reply = &getRandom(keys %{ $lang{'howareyou'} });
260 &performReply($reply);
266 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
267 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
269 return 'praise: no addr' unless ($addressed);
271 &status("random praise detected");
273 my $tmp = (rand() < 0.5) ? "thanks $who " : "";
280 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
281 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
283 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
292 if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) {
293 return '' unless (&hasParam("karma"));
295 my($term,$inc) = (lc $1,$2);
297 if ($msgType !~ /public/i) {
298 &msg($who, "karma must be done in public!");
302 if (lc $term eq lc $who) {
303 &msg($who, "please don't karma yourself");
307 my $karma = &dbGet("stats", "counter", "nick=".&dbQuote($term).
308 " AND type='karma'") || 0;
316 { nick => $term, type => "karma" },
317 { counter => $karma }
323 # here's where the external routines get called.
324 # if they return anything but null, that's the "answer".
326 if ( &parseCmdHook("extra",$message) ) {
327 return 'DID SOMETHING IN PCH.';
332 return 'SOMETHING 1';
335 if (0 and $addrchar) {
336 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
341 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|pgsql|dbm)/i) {
343 } elsif ($param{'DBType'} =~ /^none$/i) {
344 return "NO FACTOIDS.";
346 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");