X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FIRC%2FIrc.pl;h=0afd7d7690aafed8f93e3684173a3fe3049c63ff;hb=22dd6f030aa19695c39839d01c9511fccd7dab7f;hp=3f567542747486a8d33dfcea246c2b2fc84eb4df;hpb=bf3becdd11d0fc64898051a6e8a36f2ceddd609b;p=infobot.git diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 3f56754..0afd7d7 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -6,17 +6,22 @@ # use strict; + no strict 'refs'; +no strict 'subs'; # IN/STDIN use vars qw(%floodjoin %nuh %dcc %cache %conns %channels %param %mask %chanconf %orig %ircPort %ircstats %last %netsplit); -use vars qw($irc $nickserv $ident $conn $msgType $who $talkchannel - $addressed); +use vars qw($irc $nickserv $conn $msgType $who $talkchannel + $addressed $postprocess); use vars qw($notcount $nottime $notsize $msgcount $msgtime $msgsize $pubcount $pubtime $pubsize); use vars qw($b_blue $ob); use vars qw(@ircServers); +#use open ':utf8'; +#use open ':std'; + $nickserv = 0; my $maxlinelen = 400; @@ -102,7 +107,6 @@ sub irc { $args{'Password'} = $param{'ircPasswd'} if ($param{'ircPasswd'}); foreach my $mynick (split ',', $param{'ircNick'}) { - &DEBUG("got $mynick"); &status("Connecting to port $port of server $server ($resolve) as $mynick ..."); $args{'Nick'} = $mynick; $conns{$mynick} = $irc->newconn(%args); @@ -171,6 +175,12 @@ sub irc { $ircstats{'Server'} = "$server:$port"; + # works? needs to actually do something + # should likely listen on a tcp port instead + #$irc->addfh(STDIN, \&on_stdin, "r"); + + &status("starting main loop"); + $irc->start; } @@ -202,34 +212,44 @@ sub say { return; } + if ( $postprocess ) { + undef $postprocess; + } elsif ($postprocess = &getChanConf('postprocess', $talkchannel)) { + &DEBUG("say: $postprocess $msg"); + &parseCmdHook($postprocess . ' ' . $msg); + undef $postprocess; + return; + } &status("<$mynick/$talkchannel> $msg"); - if (&whatInterface() =~ /IRC/) { - $msg = "zero" if ($msg =~ /^0+$/); - my $t = time(); - - if ($t == $pubtime) { - $pubcount++; - $pubsize += length $msg; - - my $i = &getChanConfDefault("sendPublicLimitLines", 3); - my $j = &getChanConfDefault("sendPublicLimitBytes", 1000); - - if ( ($pubcount % $i) == 0 and $pubcount) { - sleep 1; - } elsif ($pubsize > $j) { - sleep 1; - $pubsize -= $j; - } - } else { - $pubcount = 0; - $pubtime = $t; - $pubsize = length $msg; + return unless (&whatInterface() =~ /IRC/); + + $msg = "zero" if ($msg =~ /^0+$/); + + my $t = time(); + + if ($t == $pubtime) { + $pubcount++; + $pubsize += length $msg; + + my $i = &getChanConfDefault("sendPublicLimitLines", 3, $chan); + my $j = &getChanConfDefault("sendPublicLimitBytes", 1000, $chan); + + if ( ($pubcount % $i) == 0 and $pubcount) { + sleep 1; + } elsif ($pubsize > $j) { + sleep 1; + $pubsize -= $j; } - $conn->privmsg($talkchannel, $msg); + } else { + $pubcount = 0; + $pubtime = $t; + $pubsize = length $msg; } + + $conn->privmsg($talkchannel, $msg); } sub msg { @@ -254,8 +274,8 @@ sub msg { $msgcount++; $msgsize += length $msg; - my $i = &getChanConfDefault("sendPrivateLimitLines", 3); - my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000); + my $i = &getChanConfDefault("sendPrivateLimitLines", 3, $chan); + my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000, $chan); if ( ($msgcount % $i) == 0 and $msgcount) { sleep 1; } elsif ($msgsize > $j) { @@ -274,6 +294,7 @@ sub msg { # Usage: &action(nick || chan, txt); sub action { + my $mynick = $conn->nick(); my ($target, $txt) = @_; if (!defined $txt) { &WARN("action: txt == NULL."); @@ -285,7 +306,7 @@ sub action { chop($txt) while (length $txt > 480); } - &status("* $ident/$target $txt"); + &status("* $mynick/$target $txt"); $conn->me($target, $txt); } @@ -305,8 +326,8 @@ sub notice { $notcount++; $notsize += length $txt; - my $i = &getChanConfDefault("sendNoticeLimitLines", 3); - my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000); + my $i = &getChanConfDefault("sendNoticeLimitLines", 3, $chan); + my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000, $chan); if ( ($notcount % $i) == 0 and $notcount) { sleep 1; @@ -349,6 +370,11 @@ sub performReply { $reply =~ /([\.\?\s]+)$/; + # FIXME need real throttling.... + if (length($reply) > $maxlinelen - 30) { + $reply = substr($reply, 0, $maxlinelen - 33); + $reply =~ s/ [^ ]*?$/ .../; + } &checkMsgType($reply); if ($msgType eq 'public') { @@ -383,14 +409,15 @@ sub performAddressedReply { &performReply(@_); } -sub pSReply { - &performStrictReply(@_); -} - # Usage: &performStrictReply($reply); sub performStrictReply { my ($reply) = @_; + # FIXME need real throttling.... + if (length($reply) > $maxlinelen - 30) { + $reply = substr($reply, 0, $maxlinelen - 33); + $reply =~ s/ [^ ]*?$/ .../; + } &checkMsgType($reply); if ($msgType eq 'private') { @@ -435,8 +462,9 @@ sub dcc_close { } sub joinchan { - my ($chan) = @_; - my $key = &getChanConf("chankey", $chan) || ""; + my ($chan, $key) = @_; + $key ||= &getChanConf("chankey", $chan); + $key ||= ""; # forgot for about 2 years to implement channel keys when moving # over to Net::IRC... @@ -446,10 +474,10 @@ sub joinchan { &status("join: already on $chan?"); } #} else { - &status("joining $b_blue$chan$ob"); + &status("joining $b_blue$chan $key$ob"); return if ($conn->join($chan, $key)); - return if (&validChan($chan)); + return if (&validChan($chan)); &DEBUG("joinchan: join failed. trying connect!"); &clearIRCVars(); @@ -512,6 +540,7 @@ sub deop { sub kick { my ($nick,$chan,$msg) = @_; my (@chans) = ($chan eq "") ? (keys %channels) : lc($chan); + my $mynick = $conn->nick(); if ($chan ne "" and &validChan($chan) == 0) { &ERROR("kick: invalid channel $chan."); @@ -526,7 +555,7 @@ sub kick { next; } - if (!exists $channels{$chan}{o}{$ident}) { + if (!exists $channels{$chan}{o}{$mynick}) { &status("kick: do not have ops on $chan :("); next; } @@ -539,6 +568,7 @@ sub kick { sub ban { my ($mask,$chan) = @_; my (@chans) = ($chan =~ /^\*?$/) ? (keys %channels) : lc($chan); + my $mynick = $conn->nick(); my $ban = 0; if ($chan !~ /^\*?$/ and &validChan($chan) == 0) { @@ -547,7 +577,7 @@ sub ban { } foreach $chan (@chans) { - if (!exists $channels{$chan}{o}{$ident}) { + if (!exists $channels{$chan}{o}{$mynick}) { &status("ban: do not have ops on $chan :("); next; } @@ -563,12 +593,13 @@ sub ban { sub unban { my ($mask,$chan) = @_; my (@chans) = ($chan =~ /^\*?$/) ? (keys %channels) : lc($chan); + my $mynick = $conn->nick(); my $ban = 0; &DEBUG("unban: mask = $mask, chan = @chans"); foreach $chan (@chans) { - if (!exists $channels{$chan}{o}{$ident}) { + if (!exists $channels{$chan}{o}{$mynick}) { &status("unBan: do not have ops on $chan :("); next; } @@ -592,46 +623,36 @@ sub quit { } sub nick { - my ($nick) = @_; + my ($newnick) = @_; + my $mynick = $conn->nick(); - if (!defined $nick) { + if (!defined $newnick) { &ERROR("nick: nick == NULL."); return; } - if (defined $ident and $nick eq $ident) { - &WARN("nick: nick == ident == '$ident'."); + if (!defined $mynick) { + &WARN("nick: mynick == NULL."); return; } - my $bad = 0; - $bad++ if (exists $nuh{$conn->nick()}); - $bad++ if (&IsNickInAnyChan($conn->nick())); + my $bad = 0; + $bad++ if (exists $nuh{$newnick}); + $bad++ if (&IsNickInAnyChan($newnick)); if ($bad) { - &WARN("Nick: not going to try and get my nick back. [". - scalar(gmtime). "]"); -# hrm... over time we lose track of our own nick. -# return; + &WARN("Nick: not going to try to change from $mynick to $newnick. [". scalar(gmtime). "]"); + # hrm... over time we lose track of our own nick. + #return; } -# FIXME broken for multiple nicks -# if ($nick =~ /^$mask{nick}$/) { -# &rawout("NICK ".$nick); -# -# if (defined $ident) { -# &status("nick: Changing nick to $nick (from $ident)"); -# # following shouldn't be here :( -# $ident = $nick; -# } else { -# &DEBUG("first time nick change."); -# $ident = $nick; -# } -# -# return 1; -# } - &DEBUG("nick: failed... why oh why (nick => $nick)"); - + if ($newnick =~ /^$mask{nick}$/) { + &status("nick: Changing nick from $mynick to $newnick"); + # ->nick() will NOT change cause we are using rawout? + &rawout("NICK $newnick"); + return 1; + } + &DEBUG("nick: failed... why oh why (mynick=$mynick, newnick=$newnick)"); return 0; } @@ -839,8 +860,8 @@ sub getJoinChans { } my $str; - $str .= ' in:' . join(',', sort @in) if scalar @in; - $str .= ' skip:' . join(',', sort @skip) if scalar @skip; + #$str .= ' in:' . join(',', sort @in) if scalar @in; + #$str .= ' skip:' . join(',', sort @skip) if scalar @skip; $str .= ' join:' . join(',', sort @join) if scalar @join; &status("Chans: ($nick)$str") if ($show);