/usr/share/perl5/App/Alice/History.pm is in alice 0.19-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | package App::Alice::History;
use Any::Moose;
use AnyEvent::DBI;
use AnyEvent::IRC::Util qw/filter_colors/;
use SQL::Abstract;
has dbi => (
is => 'ro',
isa => 'AnyEvent::DBI',
lazy => 1,
default => sub {
my $self = shift;
AnyEvent::DBI->new("DBI:SQLite:dbname=".$self->dbfile,"","");
}
);
has sql => (
is => 'ro',
isa => 'SQL::Abstract',
default => sub {SQL::Abstract->new(cmp => "like")},
);
has dbfile => (
is => 'ro',
isa => 'Str',
#required => 1,
);
sub store {
my ($self, %fields) = @_;
my ($stmt, @bind) = $self->sql->insert("messages", \%fields);
$self->dbi->exec($stmt, @bind, sub {});
}
sub range {
my $cb = pop;
my ($self, $user, $channel, $id, $limit) = @_;
$limit ||=5;
$self->dbi->exec(
"SELECT * FROM messages WHERE id < ? AND channel=? AND user=? ORDER BY id DESC LIMIT ?",
$id, $channel, $user, $limit, sub {
my $before = [ reverse @{$_[1]} ];
$self->dbi->exec(
"SELECT * FROM messages WHERE id > ? AND channel=? AND user=? ORDER BY id ASC LIMIT ?",
$id, $channel, $user, $limit, sub {
my $after = $_[1];
$cb->($before, $after);
}
);
}
);
}
sub search {
my $cb = pop;
my ($self, %query) = @_;
%query = map {$_ => "%$query{$_}%"} grep {$query{$_}} qw/body channel nick user/;
my ($stmt, @bind) = $self->sql->select("messages", '*', \%query, {-desc => 'id'});
$self->dbi->exec($stmt, @bind, sub {
my ($db, $rows, $rv) = @_;
$cb->($rows);
});
}
__PACKAGE__->meta->make_immutable;
1;
|