| 1 | package Bot::IRC::Karma; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Bot::IRC track karma for things | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use exact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '1.49'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=5.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 1 | my ($bot) = @_; | |||||||||||||||||||||||||||
| 11 | 1 | $bot->load('Store'); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | $bot->hook( | ||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||
| 15 | command => 'PRIVMSG', | ||||||||||||||||||||||||||||
| 16 | text => qr/^(?<thing>\([^\)]+\)|\S+)\s*(?<type>[+-]{2,})(?:\s*#\s*(?<comment>.+))?/, | ||||||||||||||||||||||||||||
| 17 | }, | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 19 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 20 | 0 | my $type = substr( $m->{type}, 0, 2 ); | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get(lc $m->{'thing'}) || {}
MC/DC0%0/1
$bot->store->get(lc $m->{'thing'}) || {}
$bot->store->get(lc $m->{'thing'})
Truth table0%0/2
A
A= $bot->store->get(lc $m->{'thing'})
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if ( $type eq '++' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 24 | 0 | $thing->{karma} += 1; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | elsif ( $type eq '--' ) { | ||||||||||||||||||||||||||||
| 27 | 0 | $thing->{karma} -= 1; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | push( @{ $thing->{comments}{$type} }, $m->{comment} ) if ( $m->{comment} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | $bot->store->set( lc( $m->{thing} ) => $thing ); | |||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | 1 | ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | $bot->hook( | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | to_me => 1, | ||||||||||||||||||||||||||||
| 38 | text => qr/^karma\s+(?<thing>\([^\)]+\)|\S+)/i, | ||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 41 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get(lc $m->{'thing'}) || {}
MC/DC0%0/1
$bot->store->get(lc $m->{'thing'}) || {}
$bot->store->get(lc $m->{'thing'})
Truth table0%0/2
A
A= $bot->store->get(lc $m->{'thing'})
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $karma = $thing->{karma} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$thing->{'karma'} || 0
MC/DC0%0/1
$thing->{'karma'} || 0
$thing->{'karma'}
Truth table0%0/2
A
A= $thing->{'karma'}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $bot->reply_to("$m->{thing} has a karma of $karma."); | |||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | 1 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | $bot->hook( | ||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | to_me => 1, | ||||||||||||||||||||||||||||
| 52 | text => qr/^explain\s+(?<thing>\([^\)]+\)|\S+)/i, | ||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 55 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $thing = $bot->store->get( lc( $m->{thing} ) ) || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get(lc $m->{'thing'}) || {}
MC/DC0%0/1
$bot->store->get(lc $m->{'thing'}) || {}
$bot->store->get(lc $m->{'thing'})
Truth table0%0/2
A
A= $bot->store->get(lc $m->{'thing'})
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $karma = $thing->{karma} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$thing->{'karma'} || 0
MC/DC0%0/1
$thing->{'karma'} || 0
$thing->{'karma'}
Truth table0%0/2
A
A= $thing->{'karma'}
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my @text; | |||||||||||||||||||||||||||
| 60 | 0 | for my $type ( '++', '--' ) { | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $thing->{comments}{$type} and @{ $thing->{comments}{$type} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$thing->{"comments"}{$type} and @{$thing->{"comments"}{$type};}
MC/DC0%0/2
$thing->{"comments"}{$type} and @{$thing->{"comments"}{$type};}
$thing->{"comments"}{$type}
@{$thing->{"comments"}{$type};}
Truth table0%0/3
A and B
A= $thing->{"comments"}{$type}B= @{$thing->{"comments"}{$type};}
| |||||||||||||||||||||||||||||
| 62 | push( @text, | ||||||||||||||||||||||||||||
| 63 | "Some say $m->{thing} is " . ( ( $type eq '++' ) ? 'good' : 'bad' ) . " because: " . | ||||||||||||||||||||||||||||
| 64 | ( | ||||||||||||||||||||||||||||
| 65 | 0 | map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, rand() ] } | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | @{ $thing->{comments}{$type} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | )[0] . '.' | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $bot->reply_to( join( ' ', @text ) ); | |||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||
| 74 | 1 | ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | $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 | 2 | 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||