/[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 50 by dpavlin, Sun Mar 18 15:37:05 2007 UTC revision 57 by dpavlin, Sat Apr 7 17:03:57 2007 UTC
# Line 75  use Getopt::Long; Line 75  use Getopt::Long;
75  use DateTime;  use DateTime;
76  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
77    
78    my $use_twitter = 1;
79    eval { require Net::Twitter; };
80    $use_twitter = 0 if ($@);
81    
82  my $import_dircproxy;  my $import_dircproxy;
83  my $log_path;  my $log_path;
84  GetOptions(  GetOptions(
# Line 545  POE::Session->create( inline_states => Line 549  POE::Session->create( inline_states =>
549    
550                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
551    
552                  if ( my $twitter = ( $nick, $channel, 'twitter' ) ) {                  if ( $use_twitter ) {
553                          _log("FIXME: send twitter for $nick on $channel [$twitter]");                          if ( my $twitter = meta( $nick, $channel, 'twitter' ) ) {
554                                    my ($login,$passwd) = split(/\s+/,$twitter,2);
555                                    _log("sending twitter for $nick/$login on $channel ");
556                                    my $bot = Net::Twitter->new( username=>$login, password=>$passwd );
557                                    $bot->update("<${channel}> $msg");
558                            }
559                  }                  }
560    
561      },      },
# Line 593  POE::Session->create( inline_states => Line 602  POE::Session->create( inline_states =>
602    
603                          my $sth = $dbh->prepare(qq{                          my $sth = $dbh->prepare(qq{
604                                  select                                  select
605                                          nick,                                          trim(both '_' from nick) as nick,
606                                          count(*) as count,                                          count(*) as count,
607                                          sum(length(message)) as len                                          sum(length(message)) as len
608                                  from log                                  from log
609                                  group by nick                                  group by trim(both '_' from nick)
610                                  order by len desc,count desc                                  order by len desc,count desc
611                                  limit $nr                                  limit $nr
612                          });                          });
# Line 669  POE::Session->create( inline_states => Line 678  POE::Session->create( inline_states =>
678    
679                  } elsif ($msg =~ m/^ping/) {                  } elsif ($msg =~ m/^ping/) {
680                          $res = "ping = " . dump( $ping );                          $res = "ping = " . dump( $ping );
681                  } elsif ($msg =~ m/^(?:twitter)\s+(\S+)\s+(.*?)/) {                  } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) {
                         if ( defined( $2 ) ) {  
                                 meta($nick, $channel, 'twitter', "$1\t$2");  
                                 $res = "saved twitter auth for $1 -- /me on $channel will auto-update twitter status";  
                         } else {  
                                 meta($nick, $channel, 'twitter', '' );  
                                 $res = "removed twitter status update for /me on $channel";  
                         }  
                 } elsif ($msg =~ m/^conf(?:ig)*\s*(last-size)*\s*(\d*)/) {  
682                          if ( ! defined( $1 ) ) {                          if ( ! defined( $1 ) ) {
683                                  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 = ? });
684                                  $sth->execute( $nick, $channel );                                  $sth->execute( $nick, $channel );
685                                  $res = "config for $nick ";                                  $res = "config for $nick on $channel";
686                                  while ( my ($n,$v) = $sth->fetchrow_array ) {                                  while ( my ($n,$v) = $sth->fetchrow_array ) {
687                                          $res .= "| $n = $v";                                          $res .= " | $n = $v";
688                                  }                                  }
689                          } elsif ( defined( $2 ) ) {                          } elsif ( ! $2 ) {
                                 meta( $nick, $channel, $1, $2 );  
                                 $res = "saved $1 = $2";  
                         } else {  
690                                  my $val = meta( $nick, $channel, $1 );                                  my $val = meta( $nick, $channel, $1 );
691                                  $res = "current $1 = " . ( $val ? $val : 'undefined' );                                  $res = "current $1 = " . ( $val ? $val : 'undefined' );
692                            } else {
693                                    my $validate = {
694                                            'last-size' => qr/^\d+/,
695                                            'twitter' => qr/^\w+\s+\w+/,
696                                    };
697    
698                                    my ( $op, $val ) = ( $1, $2 );
699    
700                                    if ( my $regex = $validate->{$op} ) {
701                                            if ( $val =~ $regex ) {
702                                                    meta( $nick, $channel, $op, $val );
703                                                    $res = "saved $op = $val";
704                                            } else {
705                                                    $res = "config option $op = $val doesn't validate against $regex";
706                                            }
707                                    } else {
708                                            $res = "config option $op doesn't exist";
709                                    }
710                          }                          }
711                  }                  }
712    

Legend:
Removed from v.50  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26