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 = 1 if ($addressed);
28 if ($param{'learn'} =~ /^HUNGRY$/i) {
36 # hack to support channel +o as "+o" in bot user file.
37 # requires +O in user file.
38 # is $who arg lowercase?
39 if (exists $channels{$chan}{o}{ $orig{who} } && &IsFlag("O") eq "O") {
40 &status("Gave $who/$chan +o (+O)\'ness");
41 $users{$userHandle}{FLAGS} .= "o";
44 # check if we have our head intact.
46 if ($addressed and IsFlag("o") eq "o") {
47 my $delta_time = time() - ($cache{lobotomy}{$who} || 0);
48 &msg($who, "give me an unlobotomy.") if ($delta_time > 60*60);
49 $cache{lobotomy}{$who} = time();
51 return 'LOBOTOMY' unless IsFlag("A");
55 if ($param{'talkMethod'} =~ /^PRIVATE$/i) {
56 if ($msgType =~ /public/ and $addressed) {
57 &msg($who, "sorry. i'm in 'PRIVATE' talkMethod mode ".
58 "while you sent a message to me ${msgType}ly.");
64 # join, must be done before outsider checking.
65 if ($message =~ /^join(\s+(.*))?\s*$/i) {
66 return 'join: not addr' unless ($addressed);
68 $2 =~ /^($mask{chan})(,(\S+))?/;
69 my($thischan, $key) = (lc $1, $3);
70 my $chankey = lc $thischan;
71 $chankey .= " $key" if (defined $key);
73 if ($thischan eq "") {
78 if ($thischan !~ /^$mask{chan}$/) {
79 &msg($who, "$thischan is not a valid channel name.");
83 if (&IsFlag("o") ne "o") {
84 if (!exists $chanconf{$thischan}) {
85 &msg($who, "I am not allowed to join $thischan.");
89 if (&validChan($thischan)) {
90 &msg($who,"warn: I'm already on $thischan, joining anyway...");
93 $cache{join}{$thischan} = $who; # used for on_join self.
96 &status("JOIN $chankey <$who>");
97 &msg($who, "joining $chankey");
98 &joinNextChan(); # hack.
104 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
105 $message =~ s/^\s+|\s+$//g;
106 my @array = split / /, $message;
108 if ($who =~ /^_default$/i) {
109 &pSReply("you are too eleet.");
113 if (!scalar @array or scalar @array > 2) {
118 my $do_nick = $array[1] || $who;
120 if (!exists $users{$do_nick}) {
121 &pSReply("nick $do_nick is not in user list.");
125 my $crypt = $users{$do_nick}{PASS};
126 if (!defined $crypt) {
127 &pSReply("user $do_nick has no passwd set.");
131 if (!&ckpasswd($array[0], $crypt)) {
132 &pSReply("invalid passwd for $do_nick.");
136 my $mask = "*!$user@".&makeHostMask($host);
137 ### TODO: prevent adding multiple dupe masks?
138 ### TODO: make &addHostMask() CMD?
139 &pSReply("Added $mask for $do_nick...");
140 $users{$do_nick}{HOSTS}{$mask} = 1;
146 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
147 $message =~ s/^\s+|\s+$//g;
148 my @array = split ' ', $message;
150 if ($who =~ /^_default$/i) {
151 &pSReply("you are too eleet.");
155 if (scalar @array != 1) {
160 # TODO: use &getUser()?
162 foreach (keys %users) {
163 if ($users{$_}{FLAGS} =~ /n/) {
169 if (!exists $users{$who} and !$first) {
170 &pSReply("nick $who is not in user list.");
175 &pSReply("First time user... adding you as Master.");
176 $users{$who}{FLAGS} = "mrsteon";
179 my $crypt = $users{$who}{PASS};
180 if (defined $crypt) {
181 &pSReply("user $who already has pass set.");
185 if (!defined $host) {
186 &WARN("pass: host == NULL.");
190 if (!scalar keys %{ $users{$who}{HOSTS} }) {
191 my $mask = "*!$user@".&makeHostMask($host);
192 &pSReply("Added hostmask '\002$mask\002' to $who");
193 $users{$who}{HOSTS}{$mask} = 1;
196 $crypt = &mkcrypt($array[0]);
197 $users{$who}{PASS} = $crypt;
198 &pSReply("new pass for $who, crypt $crypt.");
204 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
207 foreach (keys %channels) {
208 # don't test for $channel{_default} elsewhere !!!
209 next if (/^\s*$/ || /^_?default$/);
210 next unless (&IsNickInChan($who,$_));
216 if (!$found and scalar(keys %channels)) {
217 &status("OUTSIDER <$who> $message");
223 if ($msgType =~ /public/ and $message =~ s/^\+//) {
224 &status("Process: '+' flag detected; changing reply to public");
226 $who = $chan; # major hack to fix &msg().
227 $force_public_reply++;
228 # notice is still NOTICE but to whole channel => good.
231 # User Processing, for all users.
234 return 'returned from pCH' if &parseCmdHook("main",$message);
236 $retval = &userCommands();
237 return unless (defined $retval);
238 return if ($retval eq $noreply);
242 # once useless messages have been parsed out, we match them.
245 # confused? is this for infobot communications?
246 foreach (keys %{ $lang{'confused'} }) {
249 next unless ($message =~ /^\Q$y\E\s*/);
253 # hello. [took me a while to fix this. -xk]
254 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
255 return '' unless ($talkok);
257 # 'mynick: hi' or 'hi mynick' or 'hi'.
258 &status("somebody said hello");
260 # 50% chance of replying to a random greeting when not addressed
261 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
262 &status("not returning unaddressed greeting");
266 # customized random message.
267 my $tmp = (rand() < 0.5) ? ", $who" : "";
268 &pSReply( &getRandom(keys %{ $lang{'hello'} }) . $tmp );
273 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
275 &performReply(&getRandom(keys %{ $lang{'howareyou'} }));
280 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
281 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
283 return 'praise: no addr' unless ($addressed);
285 &performReply(&getRandom(keys %{ $lang{'praise'} }));
290 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
291 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
293 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
302 if ($msgType =~ /public/i && $message =~ /^(\S+)(--|\+\+)\s*$/ &&
303 $addressed && &hasParam("karma")
305 # to request factoids such as "g++" or "libstdc++", append "?" to the query.
306 my ($term,$inc) = (lc $1,$2);
308 if (lc $term eq lc $who) {
309 &msg($who, "please don't karma yourself");
313 my $karma = &sqlSelect("stats", "counter",
314 { nick => $term, type => "karma" }) || 0;
321 &sqlReplace("stats", {
331 # here's where the external routines get called.
332 # if they return anything but null, that's the "answer".
334 if ( &parseCmdHook("extra",$message) ) {
335 return 'DID SOMETHING IN PCH.';
340 return 'SOMETHING 1';
343 # allow administration of bot via messages (default is DCC CHAT only)
345 &loadMyModule( $myModules{'ircdcc'} );
348 return 'SOMETHING 2';
352 if (0 and $addrchar) {
353 &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way.");
358 if (&IsParam("factoids") and $param{'DBType'} =~ /^(mysql|sqlite|pgsql)/i) {
360 } elsif ($param{'DBType'} =~ /^none$/i) {
361 return "NO FACTOIDS.";
363 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");