2 # IrcHooks.pl: IRC Hooks stuff.
6 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
9 #######################################################################
10 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
11 #######################################################################
14 # Usage: &hookMode($nick, $modes, @targets);
16 my ($nick, $modes, @targets) = @_;
19 if ($chan =~ tr/A-Z/a-z/) {
20 &VERB("hookMode: cased $chan.",2);
24 foreach $mode (split(//, $modes)) {
26 if ($mode =~ /[-+]/) {
27 $parity = 1 if ($mode eq "+");
28 $parity = 0 if ($mode eq "-");
33 if ($mode =~ /[bklov]/) {
34 my $target = shift @targets;
37 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
38 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
40 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
41 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
44 # modes w/ target affecting nick => cache it.
45 if ($mode =~ /[bov]/) {
46 $channels{$chan}{$mode}{$target}++ if $parity;
47 delete $channels{$chan}{$mode}{$target} if !$parity;
49 # lets do some custom stuff.
50 if ($mode eq "o" and $parity) {
51 if ($nick eq "ChanServ" and $target =~ /^\Q$ident\E$/i) {
52 &VERB("hookmode: chanserv deopped us! asking",2);
53 &chanServCheck($chan);
56 &chanLimitVerify($chan);
61 $channels{$chan}{$mode} = $target if $parity;
62 delete $channels{$chan}{$mode} if !$parity;
66 # important channel modes, targetless.
67 if ($mode =~ /[mt]/) {
68 $channels{$chan}{$mode}++ if $parity;
69 delete $channels{$chan}{$mode} if !$parity;
75 ($msgType, $chan, $who, $message) = @_;
79 $orig{message} = $message;
83 $message =~ s/[\cA-\c_]//ig; # strip control characters
84 $message =~ s/^\s+//; # initial whitespaces.
85 $who =~ tr/A-Z/a-z/; # lowercase.
90 if ($msgType =~ /private/) {
95 # addressing revamped by the xk.
96 ### below needs to be fixed...
97 if (&IsParam("addressCharacter")) {
98 if ($message =~ s/^\Q$param{'addressCharacter'}\E//) {
104 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
106 if ($1 =~ /^\Q$ident\E$/i) {
107 $message = $newmessage;
110 # ignore messages addressed to other people or unaddressed.
111 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
116 # Determine floodwho.
118 if ($msgType =~ /public/i) {
120 $floodwho = $c = lc $chan;
121 } elsif ($msgType =~ /private/i) {
126 &FIXME("floodwho = ???");
129 my $val = &getChanConfDefault("floodRepeat", "2:5", $c);
130 my ($count, $interval) = split /:/, $val;
132 # flood repeat protection.
134 my $time = $flood{$floodwho}{$message} || 0;
136 if ($msgType eq "public" and (time() - $time < $interval)) {
137 ### public != personal who so the below is kind of pointless.
139 foreach (keys %flood) {
140 next if (/^\Q$floodwho\E$/);
141 next if (defined $chan and /^\Q$chan\E$/);
143 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
146 return if ($lobotomized);
149 &msg($who, "you already said what ".
150 join(' ', @who)." have said.");
152 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
155 ### TODO: delete old floodwarn{} keys.
157 if (!exists $floodwarn{$floodwho}) {
160 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
164 &status("FLOOD repetition detected from $floodwho.");
165 $floodwarn{$floodwho} = time();
172 &status("$b_cyan$who$ob is short-addressing me");
173 } elsif ($msgType eq "private") { # private.
174 &status("$b_cyan$who$ob is /msg'ing me");
176 &status("$b_cyan$who$ob is addressing me");
179 $flood{$floodwho}{$message} = time();
180 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
181 # unaddressed, public only.
183 ### TODO: use a separate "short-time" hash.
185 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
188 $val = &getChanConfDefault("floodMessages", "5:30", $c);
189 ($count, $interval) = split /:/, $val;
191 # flood overflow protection.
193 foreach (keys %{ $flood{$floodwho} }) {
194 next unless (time() - $flood{$floodwho}{$_} > $interval);
195 delete $flood{$floodwho}{$_};
198 my $i = scalar keys %{ $flood{$floodwho} };
200 my $expire = $param{'ignoreAutoExpire'} || 5;
202 # &msg($who,"overflow of messages ($i > $count)");
203 &msg($who,"Too many queries from you, ignoring for $expire minutes.");
204 &status("FLOOD overflow detected from $floodwho; ignoring");
206 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
210 $flood{$floodwho}{$message} = time();
214 if ($msgType =~ /public/i) { # public.
215 $talkchannel = $chan;
216 &status("<$orig{who}/$chan> $orig{message}");
217 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
218 } elsif ($msgType =~ /private/i) { # private.
219 &status("[$orig{who}] $orig{message}");
220 $talkchannel = undef;
223 &DEBUG("unknown msgType => $msgType.");
225 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
227 if ((!$skipmessage or &IsChanConf("seenStoreAll") > 0) and
228 &IsChanConf("seen") > 0 and
231 $seencache{$who}{'time'} = time();
232 $seencache{$who}{'nick'} = $orig{who};
233 $seencache{$who}{'host'} = $uh;
234 $seencache{$who}{'chan'} = $talkchannel;
235 $seencache{$who}{'msg'} = $orig{message};
236 $seencache{$who}{'msgcount'}++;
239 return if ($skipmessage);
240 return unless (&IsParam("minVolunteerLength") or $addressed);
245 next unless (eval { $nuh =~ /^$_$/i } );
247 # better to ignore an extra message than to allow one to get
248 # through, although it would be better to go through ignore
250 if (time() - ($cache{ignoreCheckTime} || 0) > 60) {
254 &status("IGNORE <$who> $message");
259 if (!defined $userHandle) {
260 &DEBUG("line 1074: need verifyUser?");
261 &verifyUser($who, $nuh);
264 &DEBUG("hookMsg: 'nuh' not defined?");
267 ### For extra debugging purposes...
268 if ($_ = &process()) {
269 # &DEBUG("IrcHooks: process returned '$_'.");
272 # hack to remove +o from ppl with +O flag.
273 if (exists $users{$userHandle} && exists $users{$userHandle}{FLAGS} &&
274 $users{$userHandle}{FLAGS} =~ /O/
276 $users{$userHandle}{FLAGS} =~ s/o//g;
282 # this is basically run on on_join or on_quit
283 sub chanLimitVerify {
286 my $l = $channels{$chan}{'l'};
288 return unless (&IsChanConf("chanlimitcheck"));
290 if (scalar keys %netsplit) {
291 &WARN("clV: netsplit active (1, chan = $chan); skipping.");
296 &DEBUG("$chan: running chanlimitCheck from chanLimitVerify.");
301 # only change it if it's not set.
302 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
303 my $count = scalar(keys %{ $channels{$chan}{''} });
304 my $int = &getChanConfDefault("chanlimitcheckInterval", 10, $chan);
306 my $delta = $count + $plus - $l;
310 &WARN("clc: stupid to have plus at $plus, fix it!");
313 if (exists $cache{chanlimitChange}{$chan}) {
314 if (time() - $cache{chanlimitChange}{$chan} < $int*60) {
319 &chanServCheck($chan);
321 ### todo: unify code with chanlimitcheck()
322 return if ($delta > 5);
324 &status("clc: big change in limit for $chan ($delta);".
325 "going for it. (was: $l; now: ".($count+$plus).")");
327 $conn->mode($chan, "+l", $count+$plus);
328 $cache{chanlimitChange}{$chan} = time();
334 if (!defined $chan or $chan =~ /^\s*$/) {
335 &WARN("chanServCheck: chan == NULL.");
339 if ($chan =~ tr/A-Z/a-z/) {
340 &DEBUG("chanServCheck: lowercased chan ($chan)");
343 if (! &IsChanConf("chanServ_ops") ) {
347 &VERB("chanServCheck($chan) called.",2);
349 if ( &IsParam("nickServ_pass") and !$nickserv) {
350 $conn->who("NickServ");
354 # check for first hash then for next hash.
355 # todo: a function for &ischanop()? &isvoice()?
356 if (exists $channels{$chan} and exists $channels{$chan}{'o'}{$ident}) {
360 &status("ChanServ ==> Requesting ops for $chan. (chanServCheck)");
361 &rawout("PRIVMSG ChanServ :OP $chan $ident");