--- trunk/bin/irc-logger.pl 2008/03/08 00:14:41 100 +++ trunk/bin/irc-logger.pl 2008/03/09 00:47:38 104 @@ -2,6 +2,23 @@ use strict; $|++; +use POE qw(Component::IRC Component::Server::HTTP); +use HTTP::Status; +use DBI; +use Regexp::Common qw /URI/; +use CGI::Simple; +use HTML::TagCloud; +use POSIX qw/strftime/; +use HTML::CalendarMonthSimple; +use Getopt::Long; +use DateTime; +use URI::Escape; +use Data::Dump qw/dump/; +use DateTime::Format::ISO8601; +use Carp qw/confess/; +use XML::Feed; +use DateTime::Format::Flexible; + =head1 NAME irc-logger.pl @@ -35,15 +52,22 @@ my $NICK = 'irc-logger'; $NICK .= '-dev' if ($HOSTNAME =~ m/llin/); -my $CONNECT = - {Server => 'irc.freenode.net', - Nick => $NICK, - Ircname => "try /msg $NICK help", - }; +my $CONNECT = { + Server => 'irc.freenode.net', + Nick => $NICK, + Ircname => "try /msg $NICK help", +}; my $CHANNEL = '#razmjenavjestina'; $CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); my $IRC_ALIAS = "log"; +if ( $HOSTNAME =~ m/lugarin/ ) { + $CONNECT->{Server} = 'irc.carnet.hr'; + $CHANNEL = '#riss'; +} + +warn dump( $HOSTNAME, $CONNECT ); + my $DSN = 'DBI:Pg:dbname=' . $NICK; my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; @@ -62,23 +86,6 @@ ## END CONFIG -use POE qw(Component::IRC Component::Server::HTTP); -use HTTP::Status; -use DBI; -use Regexp::Common qw /URI/; -use CGI::Simple; -use HTML::TagCloud; -use POSIX qw/strftime/; -use HTML::CalendarMonthSimple; -use Getopt::Long; -use DateTime; -use URI::Escape; -use Data::Dump qw/dump/; -use DateTime::Format::ISO8601; -use Carp qw/confess/; -use XML::Feed; -use DateTime::Format::Flexible; - my $use_twitter = 1; eval { require Net::Twitter; }; $use_twitter = 0 if ($@); @@ -672,6 +679,8 @@ if ( $args->{kernel} && $send_rss_msgs ) { $send_rss_msgs--; + # FIXME bug! should be save_message +# save_message( channel => $args->{channel}, me => 1, nick => $NICK, message => $msg ); $sth_insert_log->execute( $args->{channel}, 1, $NICK, $msg, 'now()' ); my ( $type, $to ) = ( 'notice', $args->{channel} ); ( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private}; @@ -938,7 +947,7 @@ $channel = $nick if $sub eq 'private'; my $sql = { - add => qq{ insert into feeds (url,name,channel,nick,private) values (?,?,?,?,?) }, + add => qq{ insert into feeds (url,name,channel,nick,private) values (?,?,?,?,?) }, # remove => qq{ delete from feeds where url = ? and name = ? }, start => qq{ update feeds set active = true where url = ? }, stop => qq{ update feeds set active = false where url = ? }, @@ -972,33 +981,42 @@ rss_check_updates( $_[KERNEL] ); }, irc_477 => sub { - _log "# irc_477: ",$_[ARG1]; + _log "<< irc_477: ",$_[ARG1]; $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); }, irc_505 => sub { - _log "# irc_505: ",$_[ARG1]; + _log "<< irc_505: ",$_[ARG1]; $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); # $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" ); # $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" ); }, irc_registered => sub { - _log "## registrated $NICK"; + _log "## registrated $NICK, /msg nickserv IDENTIFY $NICK"; $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); }, irc_disconnected => sub { - _log "## disconnected, reconnecting again"; - $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); + _log "## disconnected.. sleeping for $sleep_on_error seconds and reconnecting again"; + sleep($sleep_on_error); + $_[KERNEL]->post( $IRC_ALIAS => connect => $CONNECT); }, irc_socketerr => sub { _log "## socket error... sleeping for $sleep_on_error seconds and retry"; sleep($sleep_on_error); - $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); + $_[KERNEL]->post( $IRC_ALIAS => connect => $CONNECT); }, # irc_433 => sub { # print "# irc_433: ",$_[ARG1], "\n"; # warn "## indetify $NICK\n"; # $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); # }, +# irc_451 # please register + irc_snotice => sub { + _log "<< snotice",$_[ARG0]; + if ( $_[ARG0] =~ m!/(QUOTE)\s+(PASS\s+\d+)!i ) { + warn ">> $1 | $2\n"; + $_[KERNEL]->post( $IRC_ALIAS => lc($1) => $2); + } + }, _child => sub {}, _default => sub { _log sprintf "sID:%s %s %s",