/[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 4 by dpavlin, Mon Feb 27 11:54:38 2006 UTC revision 6 by dpavlin, Mon Feb 27 12:41:10 2006 UTC
# Line 2  Line 2 
2  use strict;  use strict;
3  $|++;  $|++;
4    
5    =head1 NAME
6    
7    irc-logger.pl
8    
9    =head1 SYNOPSIS
10    
11    ./irc-logger.pl
12    
13    =head1 DESCRIPTION
14    
15    log all conversation on irc channel
16    
17    =cut
18    
19  ## CONFIG  ## CONFIG
20    
21  my $NICK = 'irc-logger';  my $NICK = 'irc-logger';
# Line 19  my %FOLLOWS = Line 33  my %FOLLOWS =
33     ERROR => "/var/log/apache/error.log",     ERROR => "/var/log/apache/error.log",
34    );    );
35    
36    my $DSN = 'DBI:Pg:dbname=irc-logger';
37    
38  ## END CONFIG  ## END CONFIG
39    
40  my $SKIPPING = 0;               # if skipping, how many we've done  
 my $SEND_QUEUE;                 # cache  
41    
42  use POE qw(Component::IRC Wheel::FollowTail);  use POE qw(Component::IRC Wheel::FollowTail);
43    use DBI;
44    use Encode qw/from_to/;
45    
46    
47    my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
48    
49    =for SQL schema
50    
51    $dbh->do(qq{
52    create table log (
53            id serial,
54            time timestamp default now(),
55            channel text not null,
56            nick text not null,
57            message text not null,
58            primary key(id)
59    );
60    
61    create index log_time on log(time);
62    create index log_channel on log(channel);
63    create index log_nick on log(nick);
64    
65    });
66    
67    =cut
68    
69    my $sth = $dbh->prepare(qq{
70    insert into log
71            (channel, nick, message)
72    values (?,?,?)
73    });
74    
75    
76    my $SKIPPING = 0;               # if skipping, how many we've done
77    my $SEND_QUEUE;                 # cache
78    
79  POE::Component::IRC->new($IRC_ALIAS);  POE::Component::IRC->new($IRC_ALIAS);
80    
# Line 46  POE::Session->create Line 96  POE::Session->create
96            my $channel = $_[ARG1]->[0];            my $channel = $_[ARG1]->[0];
97            my $msg = $_[ARG2];            my $msg = $_[ARG2];
98    
99              from_to($msg, 'UTF-8', 'ISO-8859-2');
100    
101            print "$channel: <$nick> $msg\n";            print "$channel: <$nick> $msg\n";
102              $sth->execute($channel, $nick, $msg);
103      },      },
104      (map      (map
105       {       {
# Line 56  POE::Session->create Line 109  POE::Session->create
109          connected snotice ctcp_action ping notice mode part quit          connected snotice ctcp_action ping notice mode part quit
110          001 002 003 004 005          001 002 003 004 005
111          250 251 252 253 254 265 266          250 251 252 253 254 265 266
112          332 333 353 366 372 375 376)),          332 333 353 366 372 375 376
113                    477
114                    )),
115      _child => sub {},      _child => sub {},
116      _default => sub {      _default => sub {
117        printf "%s: session %s caught an unhandled %s event.\n",        printf "%s: session %s caught an unhandled %s event.\n",

Legend:
Removed from v.4  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26