line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LiBot::Handler::Karma; |
2
|
2
|
|
|
2
|
|
24766
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
8
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
5
|
2
|
|
|
2
|
|
3787
|
use DB_File; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Mouse; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has path => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
isa => 'Str', |
12
|
|
|
|
|
|
|
required => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has dict => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
lazy => 1, |
19
|
|
|
|
|
|
|
default => sub { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
tie my %karma_dict, 'DB_File', $self->path; |
22
|
|
|
|
|
|
|
\%karma_dict; |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
no Mouse; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
|
|
|
|
|
|
my ($self, $bot) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
print "Registering karma bot\n"; |
32
|
|
|
|
|
|
|
$bot->register( |
33
|
|
|
|
|
|
|
qr/(\w+)(\+\+|--)/ => sub { |
34
|
|
|
|
|
|
|
my ($cb, $event, $name, $op) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
print "Processing karma\n"; |
37
|
|
|
|
|
|
|
$self->dict->{$name} += 1 if $op eq '++'; |
38
|
|
|
|
|
|
|
$self->dict->{$name} -= 1 if $op eq '--'; |
39
|
|
|
|
|
|
|
$cb->(sprintf("$name: %s", $self->dict->{$name})); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |