/[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 41 by dpavlin, Tue Oct 24 12:51:49 2006 UTC revision 43 by dpavlin, Fri Feb 2 22:27:36 2007 UTC
# Line 67  use POSIX qw/strftime/; Line 67  use POSIX qw/strftime/;
67  use HTML::CalendarMonthSimple;  use HTML::CalendarMonthSimple;
68  use Getopt::Long;  use Getopt::Long;
69  use DateTime;  use DateTime;
70    use Data::Dump qw/dump/;
71    
72  my $import_dircproxy;  my $import_dircproxy;
73  GetOptions(  GetOptions(
# Line 128  my $tag_regex = '\b([\w-_]+)//'; Line 129  my $tag_regex = '\b([\w-_]+)//';
129                  }                  }
130          },          },
131          context => 5,          context => 5,
132            full_rows => 1,
133   );   );
134    
135  Order is important. Fields are first passed through C<filter> (if available) and  Order is important. Fields are first passed through C<filter> (if available) and
# Line 135  then throgh C<< sprintf($fmt->{message}, Line 137  then throgh C<< sprintf($fmt->{message},
137    
138  C<context> defines number of messages around each search hit for display.  C<context> defines number of messages around each search hit for display.
139    
140    C<full_rows> will return database rows for each result with C<date>, C<time>, C<channel>,
141    C<me>, C<nick> and C<message> keys.
142    
143  =cut  =cut
144    
145  sub get_from_log {  sub get_from_log {
# Line 204  sub get_from_log { Line 209  sub get_from_log {
209                  unshift @rows, $row;                  unshift @rows, $row;
210          }          }
211    
212            # normalize nick names
213            map {
214                    $_->{nick} =~ s/^_*(.*?)_*$/$1/
215            } @rows;
216    
217            return @rows if ($args->{full_rows});
218    
219          my @msgs = (          my @msgs = (
220                  "Showing " . ($#rows + 1) . " messages..."                  "Showing " . ($#rows + 1) . " messages..."
221          );          );
# Line 260  sub get_from_log { Line 272  sub get_from_log {
272                  my $append = 1;                  my $append = 1;
273    
274                  my $nick = $row->{nick};                  my $nick = $row->{nick};
275                  if ($nick =~ s/^_*(.*?)_*$/$1/) {  #               if ($nick =~ s/^_*(.*?)_*$/$1/) {
276                          $row->{nick} = $nick;  #                       $row->{nick} = $nick;
277                  }  #               }
278    
279                  if ($last_row->{nick} ne $nick) {                  if ($last_row->{nick} ne $nick) {
280                          # obfu way to find format for me_nick if needed or fallback to default                          # obfu way to find format for me_nick if needed or fallback to default
# Line 421  if ($import_dircproxy) { Line 433  if ($import_dircproxy) {
433    
434  my $SKIPPING = 0;               # if skipping, how many we've done  my $SKIPPING = 0;               # if skipping, how many we've done
435  my $SEND_QUEUE;                 # cache  my $SEND_QUEUE;                 # cache
436    my $ping;                                               # ping stats
437    
438  POE::Component::IRC->new($IRC_ALIAS);  POE::Component::IRC->new($IRC_ALIAS);
439    
# Line 452  POE::Session->create( inline_states => Line 465  POE::Session->create( inline_states =>
465    
466                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);                  save_message( channel => $channel, me => 1, nick => $nick, msg => $msg);
467      },      },
468            irc_ping => sub {
469                    warn "pong ", $_[ARG0], $/;
470                    $ping->{$_[ARG0]++};
471            },
472            irc_invite => sub {
473                    my $kernel = $_[KERNEL];
474                    my $nick = (split /!/, $_[ARG0])[0];
475                    my $channel = $_[ARG1];
476                    
477    
478                    warn "invited to $channel by $nick";
479    
480                    $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." );
481                    $_[KERNEL]->post($IRC_ALIAS => join => $channel);
482    
483            },
484          irc_msg => sub {          irc_msg => sub {
485                  my $kernel = $_[KERNEL];                  my $kernel = $_[KERNEL];
486                  my $nick = (split /!/, $_[ARG0])[0];                  my $nick = (split /!/, $_[ARG0])[0];
# Line 519  POE::Session->create( inline_states => Line 548  POE::Session->create( inline_states =>
548    
549                          $res = '';                          $res = '';
550    
551                    } elsif ($msg =~ m/^(?:count|poll)\s+(.*)(?:\s+(\d+))?\s*$/i) {
552    
553                            my ($what,$limit) = ($1,$2);
554                            $limit ||= 100;
555    
556                            my $stat;
557    
558                            foreach my $res (get_from_log(
559                                            limit => $limit,
560                                            search => $what,
561                                            full_rows => 1,
562                                    )) {
563                                    while ($res->{message} =~ s/\Q$what\E(\+|\-)//) {
564                                            $stat->{vote}->{$1}++;
565                                            $stat->{from}->{ $res->{nick} }++;
566                                    }
567                            }
568    
569                            my @nicks;
570                            foreach my $nick (sort { $stat->{from}->{$a} <=> $stat->{from}->{$b} } keys %{ $stat->{from} }) {
571                                    push @nicks, $nick . ( $stat->{from}->{$nick} == 1 ? '' :
572                                            "(" . $stat->{from}->{$nick} . ")"
573                                    );
574                            }
575    
576                            $res =
577                                    "$what ++ " . ( $stat->{vote}->{'+'} || 0 ) .
578                                    " : " . ( $stat->{vote}->{'-'} || 0 ) . " --" .
579                                    " from " . ( join(", ", @nicks) || 'nobody' );
580    
581                            $_[KERNEL]->post( $IRC_ALIAS => notice => $nick, $res );
582    
583                    } elsif ($msg =~ m/^ping/) {
584                            $res = "ping = " . dump( $ping );
585                  }                  }
586    
587                  if ($res) {                  if ($res) {

Legend:
Removed from v.41  
changed lines
  Added in v.43

  ViewVC Help
Powered by ViewVC 1.1.26