| 1 | package Bot::BasicBot::Pluggable::Module::Retort; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use Bot::BasicBot::Pluggable::Module; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use base 'Bot::BasicBot::Pluggable::Module'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use Bot::BasicBot::Pluggable::Store; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use Text::English; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 1 | our $VERSION = '1.000000'; | |||||||||||
| 13 | |||||||||||||
| 14 | 1 | my $store = Bot::BasicBot::Pluggable::Store->new( 'option' => 'value' ); | |||||||||||
| 15 | 1 | my $sns = 'Retort', | |||||||||||
| 16 | |||||||||||||
| 17 | my %awesomes = ( | ||||||||||||
| 18 | 'cache' => [ | ||||||||||||
| 19 | 'Caching? Implement it!', | ||||||||||||
| 20 | 'Yeah, we totally need some caching that.', | ||||||||||||
| 21 | 'I read if you cache your caching layer, it\'s awesome.', | ||||||||||||
| 22 | 'What if we cached our already cached mason objects? Would we be 1337 then?', | ||||||||||||
| 23 | ], | ||||||||||||
| 24 | 'touch' => [ | ||||||||||||
| 25 | 'heh, that\'s what she said.', | ||||||||||||
| 26 | 'Please don\'t touch me there.', | ||||||||||||
| 27 | 'Hey! That\'s my naughty place!', | ||||||||||||
| 28 | '. o O! That\'s where my 1st grade teacher used to touch me, too. Memories.', | ||||||||||||
| 29 | ], | ||||||||||||
| 30 | 'finger' => [ | ||||||||||||
| 31 | 'http://is.gd/xRW1', | ||||||||||||
| 32 | 'http://is.gd/rwMl', | ||||||||||||
| 33 | 'heh, that\'s what she said.', | ||||||||||||
| 34 | ' ... in the bedroom.', | ||||||||||||
| 35 | ], | ||||||||||||
| 36 | 'beer' => [ | ||||||||||||
| 37 | 'Beer? Where?', | ||||||||||||
| 38 | 'Mmmmm.... Beeeeer.', | ||||||||||||
| 39 | ], | ||||||||||||
| 40 | ); | ||||||||||||
| 41 | |||||||||||||
| 42 | 1 | foreach my $wurd ( keys %awesomes ) { | |||||||||||
| 43 | 4 | ▶ | $store->set( $sns, $wurd, $awesomes{$wurd} ) if ( ! $store->get( $sns, $wurd ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | sub help { | ||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 47 | 0 | return 'retort [WORD] as [STATEMENT]' | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | sub said { | ||||||||||
|
Subroutine
said: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 51 | 0 | my ( $self, $args, $pri ) = @_; | |||||||||||
| 52 | 0 | my ( $who, $nick, $channel, $body, $address ) = @$args{ qw( who nick channel body address ) }; | |||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | return unless ( $pri == 2 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 0 | ▶ | if ( $body =~ /^.*retort (\w+) as (.*)$/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 0 | my ( $word, $content ) = ( $1, $2 ); | |||||||||||
| 58 | 0 | my ( $stem ) = Text::English::stem( $word ); | |||||||||||
| 59 | 0 | my $has = $store->get( $sns, $stem ); | |||||||||||
| 60 | 0 | ▶ | push( @{ $has ||= [] }, $content ); | ||||||||||
|
Condition0%0/2
$has ||= []
MC/DC0%0/1
$has ||= []
$has
Truth table0%0/2
A
A= $has
| |||||||||||||
| 61 | 0 | $store->set( $sns, $stem, $has ); | |||||||||||
| 62 | 0 | $store->save(); | |||||||||||
| 63 | |||||||||||||
| 64 | 0 | $self->reply( $args, "$who, got it." ); | |||||||||||
| 65 | 0 | return; | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | foreach my $stem ( Text::English::stem( map{ lc } split( /\s+/, $body ) ) ) { | |||||||||||
| 69 | 0 | ▶ | if ( my $has = $store->get( $sns, $stem ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 0 | $self->reply( $args, $has->[ int( rand( @$has ) ) ] ); | |||||||||||
| 71 | 0 | return; | |||||||||||
| 72 | } | ||||||||||||
| 73 | } | ||||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 1 | 1; | |||||||||||
| 77 | |||||||||||||
| 78 | __END__ | ||||||||||||