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+(\S+))?/;
69 my($joinchan, $key) = (lc $1, $3);
71 if ($joinchan eq "") {
76 if ($joinchan !~ /^$mask{chan}$/) {
77 &msg($who, "$joinchan is not a valid channel name.");
81 if (&IsFlag("o") ne "o") {
82 if (!exists $chanconf{$joinchan}) {
83 &msg($who, "I am not allowed to join $joinchan.");
87 if (&validChan($joinchan)) {
88 &msg($who,"warn: I'm already on $joinchan, joining anyway...");
91 $cache{join}{$joinchan} = $who; # used for on_join self.
93 &status("JOIN $joinchan $key <$who>");
94 &msg($who, "joining $joinchan $key");
95 &joinchan($joinchan, $key);
96 &joinNextChan(); # hack.
102 if ($msgType =~ /private/ and $message =~ s/^identify//i) {
103 $message =~ s/^\s+|\s+$//g;
104 my @array = split / /, $message;
106 if ($who =~ /^_default$/i) {
107 &performStrictReply("you are too eleet.");
111 if (!scalar @array or scalar @array > 2) {
116 my $do_nick = $array[1] || $who;
118 if (!exists $users{$do_nick}) {
119 &performStrictReply("nick $do_nick is not in user list.");
123 my $crypt = $users{$do_nick}{PASS};
124 if (!defined $crypt) {
125 &performStrictReply("user $do_nick has no passwd set.");
129 if (!&ckpasswd($array[0], $crypt)) {
130 &performStrictReply("invalid passwd for $do_nick.");
134 my $mask = "$who!$user@".&makeHostMask($host);
135 ### TODO: prevent adding multiple dupe masks?
136 ### TODO: make &addHostMask() CMD?
137 &performStrictReply("Added $mask for $do_nick...");
138 $users{$do_nick}{HOSTS}{$mask} = 1;
144 if ($msgType =~ /private/ and $message =~ s/^pass//i) {
145 $message =~ s/^\s+|\s+$//g;
146 my @array = split ' ', $message;
148 if ($who =~ /^_default$/i) {
149 &performStrictReply("you are too eleet.");
153 if (scalar @array != 1) {
158 # TODO: use &getUser()?
160 foreach (keys %users) {
161 if ($users{$_}{FLAGS} =~ /n/) {
167 if (!exists $users{$who} and !$first) {
168 &performStrictReply("nick $who is not in user list.");
173 &performStrictReply("First time user... adding you as Master.");
174 $users{$who}{FLAGS} = "aemnorst";
177 my $crypt = $users{$who}{PASS};
178 if (defined $crypt) {
179 &performStrictReply("user $who already has pass set.");
183 if (!defined $host) {
184 &WARN("pass: host == NULL.");
188 if (!scalar keys %{ $users{$who}{HOSTS} }) {
189 my $mask = "*!$user@".&makeHostMask($host);
190 &performStrictReply("Added hostmask '\002$mask\002' to $who");
191 $users{$who}{HOSTS}{$mask} = 1;
194 $crypt = &mkcrypt($array[0]);
195 $users{$who}{PASS} = $crypt;
196 &performStrictReply("new pass for $who, crypt $crypt.");
202 if (&IsParam("disallowOutsiders") and $msgType =~ /private/i) {
205 foreach (keys %channels) {
206 # don't test for $channel{_default} elsewhere !!!
207 next if (/^\s*$/ || /^_?default$/);
208 next unless (&IsNickInChan($who,$_));
214 if (!$found and scalar(keys %channels)) {
215 &status("OUTSIDER <$who> $message");
221 if ($msgType =~ /public/ and $message =~ s/^\+//) {
222 &status("Process: '+' flag detected; changing reply to public");
224 $who = $chan; # major hack to fix &msg().
225 $force_public_reply++;
226 # notice is still NOTICE but to whole channel => good.
229 # User Processing, for all users.
232 return 'SOMETHING parseCmdHook' if &parseCmdHook($message);
234 $retval = &userCommands();
235 return unless (defined $retval);
236 return if ($retval eq $noreply);
240 # once useless messages have been parsed out, we match them.
243 # confused? is this for infobot communications?
244 foreach (keys %{ $lang{'confused'} }) {
247 next unless ($message =~ /^\Q$y\E\s*/);
251 # hello. [took me a while to fix this. -xk]
252 if ($orig{message} =~ /^(\Q$ident\E\S?[:, ]\S?)?\s*(h(ello|i( there)?|owdy|ey|ola))( \Q$ident\E)?\s*$/i) {
253 return '' unless ($talkok);
255 # 'mynick: hi' or 'hi mynick' or 'hi'.
256 &status("somebody said hello");
258 # 50% chance of replying to a random greeting when not addressed
259 if (!defined $5 and $addressed == 0 and rand() < 0.5) {
260 &status("not returning unaddressed greeting");
264 # customized random message.
265 my $tmp = (rand() < 0.5) ? ", $who" : "";
266 &performStrictReply( &getRandom(keys %{ $lang{'hello'} }) . $tmp );
271 if ($message =~ /how (the hell )?are (ya|you)( doin\'?g?)?\?*$/) {
273 &performReply(&getRandom(keys %{ $lang{'howareyou'} }));
278 if ($message =~ /you (rock|rewl|rule|are so+ coo+l)/ ||
279 $message =~ /(good (bo(t|y)|g([ui]|r+)rl))|(bot( |\-)?snack)/i)
281 return 'praise: no addr' unless ($addressed);
283 &performReply(&getRandom(keys %{ $lang{'praise'} }));
288 if ($message =~ /^than(ks?|x)( you)?( \S+)?/i) {
289 return 'thank: no addr' unless ($message =~ /$ident/ or $talkok);
291 &performReply( &getRandom(keys %{ $lang{'welcome'} }) );
300 if ($msgType =~ /public/i && $message =~ /^(\S+)(--|\+\+)\s*$/ &&
301 $addressed && &IsChanConfOrWarn("karma")
303 # to request factoids such as "g++" or "libstdc++", append "?" to the query.
304 my ($term,$inc) = (lc $1,$2);
306 if (lc $term eq lc $who) {
307 &msg($who, "please don't karma yourself");
311 my $karma = &sqlSelect("stats", "counter",
312 { nick => $term, type => "karma" }) || 0;
319 &sqlReplace("stats", {
329 # here's where the external routines get called.
330 # if they return anything but null, that's the "answer".
334 return 'SOMETHING 1';
337 # allow administration of bot via messages (default is DCC CHAT only)
339 &loadMyModule('UserDCC');
342 return 'SOMETHING 2';
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(2)?|pgsql)$/i) {
354 } elsif ($param{'DBType'} =~ /^none$/i) {
355 return "NO FACTOIDS.";
357 &ERROR("INVALID FACTOID SUPPORT? ($param{'DBType'})");