/[irc-logger]/trunk/bin/irc-logger.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/irc-logger.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 108 by dpavlin, Sun Mar 9 20:13:46 2008 UTC revision 109 by dpavlin, Sun Mar 9 21:13:15 2008 UTC
# Line 47  log all conversation on irc channel Line 47  log all conversation on irc channel
47    
48  ## CONFIG  ## CONFIG
49    
50    my $irc_config = {
51            nick => 'irc-logger',
52            server => 'irc.freenode.net',
53            port => 6667,
54            ircname => 'Anna the bot: try /msg irc-logger help',
55    };
56    
57  my $HOSTNAME = `hostname -f`;  my $HOSTNAME = `hostname -f`;
58  chomp($HOSTNAME);  chomp($HOSTNAME);
59    
60  my $NICK = 'irc-logger';  
 $NICK .= '-dev' if ($HOSTNAME =~ m/llin/);  
 my $CONNECT = {  
         Server => 'irc.freenode.net',  
         Nick => $NICK,  
         Ircname => "try /msg $NICK help",  
 };  
61  my $CHANNEL = '#razmjenavjestina';  my $CHANNEL = '#razmjenavjestina';
 $CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);  
 my $IRC_ALIAS = "log";  
62    
63  if ( $HOSTNAME =~ m/lugarin/ ) {  if ( $HOSTNAME =~ m/llin/ ) {
64          $CONNECT->{Server} = 'irc.carnet.hr';          $irc_config->{nick} = 'irc-logger-dev';
65    #       $irc_config = {
66    #               nick => 'irc-logger-dev',
67    #               server => 'localhost',
68    #               port => 6668,
69    #       };
70            $CHANNEL = '#irc-logger';
71    } elsif ( $HOSTNAME =~ m/lugarin/ ) {
72            $irc_config->{server} = 'irc.carnet.hr';
73          $CHANNEL = '#riss';          $CHANNEL = '#riss';
74  }  }
75    
76  warn dump( $HOSTNAME, $CONNECT );  my @channels = ( $CHANNEL );
77    
78    warn "# config = ", dump( $irc_config ), $/;
79    
80    my $NICK = $irc_config->{nick} or die "no nick?";
81    
82  my $DSN = 'DBI:Pg:dbname=' . $NICK;  my $DSN = 'DBI:Pg:dbname=' . $NICK;
83    
# Line 689  sub rss_fetch { Line 700  sub rss_fetch {
700                          my ( $type, $to ) = ( 'notice', $args->{channel} );                          my ( $type, $to ) = ( 'notice', $args->{channel} );
701                          ( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private};                          ( $type, $to ) = ( 'privmsg', $args->{nick} ) if $args->{private};
702                          _log(">> $type $to |", $msg);                          _log(">> $type $to |", $msg);
703                          $args->{kernel}->post( $IRC_ALIAS => $type => $to, $msg );                          $args->{kernel}->post( irc => $type => $to, $msg );
704                          $updates++;                          $updates++;
705                  }                  }
706          }          }
# Line 743  _log rss_fetch_all; Line 754  _log rss_fetch_all;
754  # POE handing part  # POE handing part
755  #  #
756    
757  my $ping;                                               # ping stats  my $poe_irc = POE::Component::IRC->spawn( %$irc_config ) or
758            die "can't start ", dump( $irc_config ), ": $!";
759    
760  POE::Component::IRC->new($IRC_ALIAS);  my $irc = $poe_irc->session_id();
761    _log "session_id $irc";
762    
763  POE::Session->create( inline_states => {  POE::Session->create( inline_states => {
764          _start => sub {                _start => sub {      
765                  $_[KERNEL]->post($IRC_ALIAS => register => 'all');                  $_[KERNEL]->post( $irc => register => 'all' );
766                  $_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT);                  $_[KERNEL]->post( $irc => connect => {} );
767      },      },
768            irc_001 => sub {
769                    my ($kernel,$sender) = @_[KERNEL,SENDER];
770                    my $poco_object = $sender->get_heap();
771                    _log "connected to",$poco_object->server_name();
772                    $kernel->post( $sender => join => $_ ) for @channels;
773                    undef;
774            },
775      irc_255 => sub {    # server is done blabbing      irc_255 => sub {    # server is done blabbing
776                  $_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);                  $_[KERNEL]->post( $irc => join => $CHANNEL);
777                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );                  $_[KERNEL]->post( $irc => privmsg => 'nickserv', "IDENTIFY $NICK" );
778      },      },
779      irc_public => sub {      irc_public => sub {
780                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
# Line 786  POE::Session->create( inline_states => { Line 806  POE::Session->create( inline_states => {
806      },      },
807          irc_ping => sub {          irc_ping => sub {
808                  _log( "pong ", $_[ARG0] );                  _log( "pong ", $_[ARG0] );
809                  $ping->{ $_[ARG0] }++;                  $_stat->{ping}->{ $_[ARG0] }++;
810                  rss_check_updates( $_[KERNEL] );                  rss_check_updates( $_[KERNEL] );
811          },          },
812          irc_invite => sub {          irc_invite => sub {
# Line 796  POE::Session->create( inline_states => { Line 816  POE::Session->create( inline_states => {
816    
817                  _log "invited to $channel by $nick";                  _log "invited to $channel by $nick";
818    
819                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." );                  $_[KERNEL]->post( $irc => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." );
820                  $_[KERNEL]->post($IRC_ALIAS => join => $channel);                  $_[KERNEL]->post( $irc => 'join' => $channel );
821    
822          },          },
823          irc_msg => sub {          irc_msg => sub {
# Line 818  POE::Session->create( inline_states => { Line 838  POE::Session->create( inline_states => {
838                  } elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) {                  } elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) {
839    
840                          _log ">> /msg $1 $2";                          _log ">> /msg $1 $2";
841                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $1, $2 );                          $_[KERNEL]->post( $irc => privmsg => $1, $2 );
842                          $res = '';                          $res = '';
843    
844                  } elsif ($msg =~ m/^stat.*?\s*(\d*)/i) {                  } elsif ($msg =~ m/^stat.*?\s*(\d*)/i) {
# Line 848  POE::Session->create( inline_states => { Line 868  POE::Session->create( inline_states => {
868    
869                          foreach my $res (get_from_log( limit => $limit )) {                          foreach my $res (get_from_log( limit => $limit )) {
870                                  _log "last: $res";                                  _log "last: $res";
871                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $irc => privmsg => $nick, $res );
872                          }                          }
873    
874                          $res = '';                          $res = '';
# Line 862  POE::Session->create( inline_states => { Line 882  POE::Session->create( inline_states => {
882                                          search => $what,                                          search => $what,
883                                  )) {                                  )) {
884                                  _log "search [$what]: $res";                                  _log "search [$what]: $res";
885                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $irc => privmsg => $nick, $res );
886                          }                          }
887    
888                          $res = '';                          $res = '';
# Line 897  POE::Session->create( inline_states => { Line 917  POE::Session->create( inline_states => {
917                                  " : " . ( $stat->{vote}->{'-'} || 0 ) . " --" .                                  " : " . ( $stat->{vote}->{'-'} || 0 ) . " --" .
918                                  " from " . ( join(", ", @nicks) || 'nobody' );                                  " from " . ( join(", ", @nicks) || 'nobody' );
919    
920                          $_[KERNEL]->post( $IRC_ALIAS => notice => $nick, $res );                          $_[KERNEL]->post( $irc => notice => $nick, $res );
921    
922                  } elsif ($msg =~ m/^ping/) {                  } elsif ($msg =~ m/^ping/) {
923                          $res = "ping = " . dump( $ping );                          $res = "ping = " . dump( $_stat->{ping} );
924                  } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) {                  } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) {
925                          if ( ! defined( $1 ) ) {                          if ( ! defined( $1 ) ) {
926                                  my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? });                                  my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? });
# Line 941  POE::Session->create( inline_states => { Line 961  POE::Session->create( inline_states => {
961                          my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds });                          my $sth = $dbh->prepare(qq{ select url,name,last_update,active,channel,nick,private from feeds });
962                          $sth->execute;                          $sth->execute;
963                          while (my @row = $sth->fetchrow_array) {                          while (my @row = $sth->fetchrow_array) {
964                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) );                                  $_[KERNEL]->post( $irc => privmsg => $nick, join(' | ',@row) );
965                          }                          }
966                          $res = '';                          $res = '';
967                  } elsif ($msg =~ m!^rss-(add|remove|stop|start)(?:-(private))?\s+(http://\S+)\s*(.*)!) {                  } elsif ($msg =~ m!^rss-(add|remove|stop|start)(?:-(private))?\s+(http://\S+)\s*(.*)!) {
# Line 979  POE::Session->create( inline_states => { Line 999  POE::Session->create( inline_states => {
999    
1000                  if ($res) {                  if ($res) {
1001                          _log ">> [$nick] $res";                          _log ">> [$nick] $res";
1002                          $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                          $_[KERNEL]->post( $irc => privmsg => $nick, $res );
1003                  }                  }
1004    
1005                  rss_check_updates( $_[KERNEL] );                  rss_check_updates( $_[KERNEL] );
# Line 995  POE::Session->create( inline_states => { Line 1015  POE::Session->create( inline_states => {
1015          },          },
1016          irc_477 => sub {          irc_477 => sub {
1017                  _log "<< irc_477: ",$_[ARG1];                  _log "<< irc_477: ",$_[ARG1];
1018                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );                  $_[KERNEL]->post( $irc => privmsg => 'nickserv', "register $NICK" );
1019          },          },
1020          irc_505 => sub {          irc_505 => sub {
1021                  _log "<< irc_505: ",$_[ARG1];                  _log "<< irc_505: ",$_[ARG1];
1022                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" );                  $_[KERNEL]->post( $irc => privmsg => 'nickserv', "register $NICK" );
1023  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" );  #               $_[KERNEL]->post( $irc => privmsg => 'nickserv', "set hide email on" );
1024  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" );  #               $_[KERNEL]->post( $irc => privmsg => 'nickserv', "set email dpavlin\@rot13.org" );
1025          },          },
1026          irc_registered => sub {          irc_registered => sub {
1027                  _log "## registrated $NICK, /msg nickserv IDENTIFY $NICK";                  _log "<< registered $NICK";
                 $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );  
1028          },          },
1029          irc_disconnected => sub {          irc_disconnected => sub {
1030                  _log "## disconnected.. sleeping for $sleep_on_error seconds and reconnecting again";                  _log "## disconnected.. sleeping for $sleep_on_error seconds and reconnecting again";
1031                  sleep($sleep_on_error);                  sleep($sleep_on_error);
1032                  $_[KERNEL]->post( $IRC_ALIAS => connect => $CONNECT);                  $_[KERNEL]->post( $irc => connect => {} );
1033          },          },
1034          irc_socketerr => sub {          irc_socketerr => sub {
1035                  _log "## socket error... sleeping for $sleep_on_error seconds and retry";                  _log "## socket error... sleeping for $sleep_on_error seconds and retry";
1036                  sleep($sleep_on_error);                  sleep($sleep_on_error);
1037                  $_[KERNEL]->post( $IRC_ALIAS => connect => $CONNECT);                  $_[KERNEL]->post( $irc => connect => {} );
1038          },          },
1039  #       irc_433 => sub {  #       irc_433 => sub {
1040  #               print "# irc_433: ",$_[ARG1], "\n";  #               print "# irc_433: ",$_[ARG1], "\n";
1041  #               warn "## indetify $NICK\n";  #               warn "## indetify $NICK\n";
1042  #               $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );  #               $_[KERNEL]->post( $irc => privmsg => 'nickserv', "IDENTIFY $NICK" );
1043  #       },  #       },
1044  #       irc_451 # please register  #       irc_451 # please register
1045            irc_notice => sub {
1046                    _log "<< notice",$_[ARG0];
1047                    if ( $_[ARG0] =~ m!/msg\s+NickServ\s+IDENTIFY!i ) {
1048                            $_[KERNEL]->post( $irc => privmsg => 'nickserv', "IDENTIFY $NICK" );
1049                    }
1050            },
1051          irc_snotice => sub {          irc_snotice => sub {
1052                  _log "<< snotice",$_[ARG0];                  _log "<< snotice",$_[ARG0];
1053                  if ( $_[ARG0] =~ m!/(QUOTE)\s+(PASS\s+\d+)!i ) {                  if ( $_[ARG0] =~ m!/(QUOTE)\s+(PASS\s+\d+)!i ) {
1054                          warn ">> $1 | $2\n";                          warn ">> $1 | $2\n";
1055                          $_[KERNEL]->post( $IRC_ALIAS => lc($1) => $2);                          $_[KERNEL]->post( $irc => lc($1) => $2);
1056                  }                  }
1057          },          },
1058      _child => sub {},      _child => sub {},

Legend:
Removed from v.108  
changed lines
  Added in v.109

  ViewVC Help
Powered by ViewVC 1.1.26