line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::IRC::Karma; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::IRC track karma for things |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2310
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
20
|
use exact; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.38'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub init { |
10
|
1
|
|
|
1
|
0
|
6384
|
my ($bot) = @_; |
11
|
1
|
|
|
|
|
6
|
$bot->load('Store'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$bot->hook( |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
command => 'PRIVMSG', |
16
|
|
|
|
|
|
|
text => qr/^(?<thing>\([^\)]+\)|\S+)\s*(?<type>[+-]{2,})(?:\s*#\s*(?<comment>.+))?/, |
17
|
|
|
|
|
|
|
}, |
18
|
|
|
|
|
|
|
sub { |
19
|
0
|
|
|
0
|
|
0
|
my ( $bot, $in, $m ) = @_; |
20
|
0
|
|
|
|
|
0
|
my $type = substr( $m->{type}, 0, 2 ); |
21
|
0
|
|
0
|
|
|
0
|
my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
0
|
if ( $type eq '++' ) { |
|
|
0
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
$thing->{karma} += 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ( $type eq '--' ) { |
27
|
0
|
|
|
|
|
0
|
$thing->{karma} -= 1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
0
|
push( @{ $thing->{comments}{$type} }, $m->{comment} ) if ( $m->{comment} ); |
|
0
|
|
|
|
|
0
|
|
31
|
0
|
|
|
|
|
0
|
$bot->store->set( lc( $m->{thing} ) => $thing ); |
32
|
|
|
|
|
|
|
}, |
33
|
1
|
|
|
|
|
14
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$bot->hook( |
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
to_me => 1, |
38
|
|
|
|
|
|
|
text => qr/^karma\s+(?<thing>\([^\)]+\)|\S+)/i, |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
sub { |
41
|
0
|
|
|
0
|
|
0
|
my ( $bot, $in, $m ) = @_; |
42
|
0
|
|
0
|
|
|
0
|
my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; |
43
|
0
|
|
0
|
|
|
0
|
my $karma = $thing->{karma} || 0; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$bot->reply_to("$m->{thing} has a karma of $karma."); |
46
|
|
|
|
|
|
|
}, |
47
|
1
|
|
|
|
|
24
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$bot->hook( |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
to_me => 1, |
52
|
|
|
|
|
|
|
text => qr/^explain\s+(?<thing>\([^\)]+\)|\S+)/i, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
sub { |
55
|
0
|
|
|
0
|
|
0
|
my ( $bot, $in, $m ) = @_; |
56
|
0
|
|
0
|
|
|
0
|
my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; |
57
|
0
|
|
0
|
|
|
0
|
my $karma = $thing->{karma} || 0; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my @text; |
60
|
0
|
|
|
|
|
0
|
for my $type ( '++', '--' ) { |
61
|
0
|
0
|
0
|
|
|
0
|
if ( $thing->{comments}{$type} and @{ $thing->{comments}{$type} } ) { |
|
0
|
|
|
|
|
0
|
|
62
|
|
|
|
|
|
|
push( @text, |
63
|
|
|
|
|
|
|
"Some say $m->{thing} is " . ( ( $type eq '++' ) ? 'good' : 'bad' ) . " because: " . |
64
|
|
|
|
|
|
|
( |
65
|
0
|
|
|
|
|
0
|
map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, rand() ] } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
66
|
0
|
0
|
|
|
|
0
|
@{ $thing->{comments}{$type} } |
|
0
|
|
|
|
|
0
|
|
67
|
|
|
|
|
|
|
)[0] . '.' |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$bot->reply_to( join( ' ', @text ) ); |
73
|
|
|
|
|
|
|
}, |
74
|
1
|
|
|
|
|
23
|
); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
17
|
$bot->helps( |
77
|
|
|
|
|
|
|
karma => join( |
78
|
|
|
|
|
|
|
'Adjust the karma of a word.', |
79
|
|
|
|
|
|
|
'Usage: "word++" or "word--" to increment or decrement the karma of "word".', |
80
|
|
|
|
|
|
|
'"karma word" to see what the karma of "word" is.', |
81
|
|
|
|
|
|
|
'"explain word" to receive one positive and one negative comment (at random)', |
82
|
|
|
|
|
|
|
'about the word if there are comments to share.', |
83
|
|
|
|
|
|
|
), |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding UTF-8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Bot::IRC::Karma - Bot::IRC track karma for things |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 1.38 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Bot::IRC; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Bot::IRC->new( |
108
|
|
|
|
|
|
|
connect => { server => 'irc.perl.org' }, |
109
|
|
|
|
|
|
|
plugins => ['Karma'], |
110
|
|
|
|
|
|
|
)->run; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This L<Bot::IRC> plugin gives the bot the ability to track and report on |
115
|
|
|
|
|
|
|
something as meaningless as the concept of karma for things. Commands include: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 <thing>++ # comment |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Increases karma of "thing" by one and optionally remembers a positive comment |
120
|
|
|
|
|
|
|
about "thing". |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 <thing>-- # comment |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Decreases karma of "thing" by one and optionally remembers a negative comment |
125
|
|
|
|
|
|
|
about "thing". |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 karma <thing> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Reports the karma of a "thing". |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 explain <thing> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Tells you one positive and one negative comment (at random) about "thing" if |
134
|
|
|
|
|
|
|
there are comments to share. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 SEE ALSO |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<Bot::IRC> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=for Pod::Coverage init |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Gryphon Shafer <gryphon@cpan.org> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is Copyright (c) 2016-2021 by Gryphon Shafer. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This is free software, licensed under: |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |