33 |
ERROR => "/var/log/apache/error.log", |
ERROR => "/var/log/apache/error.log", |
34 |
); |
); |
35 |
|
|
36 |
my $DSN = 'DBI:Pg:dbname=irc-logger'; |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
37 |
|
|
38 |
my $ENCODING = 'ISO-8859-2'; |
my $ENCODING = 'ISO-8859-2'; |
39 |
|
|
51 |
|
|
52 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
53 |
|
|
54 |
=for SQL schema |
eval { |
55 |
|
$dbh->do(qq{ select count(*) from log }); |
56 |
|
}; |
57 |
|
|
58 |
|
if ($@) { |
59 |
|
warn "creating database table in $DSN\n"; |
60 |
|
$dbh->do(<<'_SQL_SCHEMA_'); |
61 |
|
|
|
$dbh->do(qq{ |
|
62 |
create table log ( |
create table log ( |
63 |
id serial, |
id serial, |
64 |
time timestamp default now(), |
time timestamp default now(), |
65 |
channel text not null, |
channel text not null, |
66 |
|
me boolean default false, |
67 |
nick text not null, |
nick text not null, |
68 |
message text not null, |
message text not null, |
69 |
primary key(id) |
primary key(id) |
73 |
create index log_channel on log(channel); |
create index log_channel on log(channel); |
74 |
create index log_nick on log(nick); |
create index log_nick on log(nick); |
75 |
|
|
76 |
}); |
_SQL_SCHEMA_ |
77 |
|
} |
|
=cut |
|
78 |
|
|
79 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
80 |
insert into log |
insert into log |
81 |
(channel, nick, message) |
(channel, me, nick, message) |
82 |
values (?,?,?) |
values (?,?,?,?) |
83 |
}); |
}); |
84 |
|
|
85 |
=head2 get_from_log |
=head2 get_from_log |
223 |
from_to($msg, 'UTF-8', $ENCODING); |
from_to($msg, 'UTF-8', $ENCODING); |
224 |
|
|
225 |
print "$channel: <$nick> $msg\n"; |
print "$channel: <$nick> $msg\n"; |
226 |
$sth->execute($channel, $nick, $msg); |
$sth->execute($channel, 0, $nick, $msg); |
227 |
|
}, |
228 |
|
irc_ctcp_action => sub { |
229 |
|
my $kernel = $_[KERNEL]; |
230 |
|
my $nick = (split /!/, $_[ARG0])[0]; |
231 |
|
my $channel = $_[ARG1]->[0]; |
232 |
|
my $msg = $_[ARG2]; |
233 |
|
|
234 |
|
from_to($msg, 'UTF-8', $ENCODING); |
235 |
|
|
236 |
|
print "$channel ***$nick $msg\n"; |
237 |
|
$sth->execute($channel, 1, $nick, $msg); |
238 |
}, |
}, |
239 |
irc_msg => sub { |
irc_msg => sub { |
240 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |