File Coverage

blib/lib/Bot/IRC/X/Retort.pm
Criterion Covered Total %
statement 11 36 30.5
branch 0 10 0.0
condition n/a
subroutine 3 6 50.0
pod 0 1 0.0
total 14 53 26.4


line stmt bran cond sub pod time code
1             # ABSTRACT: Bot::IRC plugin for bot-retorting to key words
2              
3             use 5.014;
4 1     1   287453 use exact;
  1         9  
5 1     1   4  
  1         1  
  1         4  
6             our $VERSION = '1.05'; # VERSION
7              
8             my ($bot) = @_;
9             $bot->load('Store');
10 1     1 0 4946  
11 1         5 $bot->hook(
12             {
13             to_me => 1,
14             text => qr/^retort\s+(?<term>\([^\)]+\)|\S+)\s+with\s+(?<retort>.+)/i,
15             },
16             sub {
17             my ( $bot, $in, $m ) = @_;
18              
19 0     0   0 my %retorts = %{ $bot->store->get('retorts') || {} };
20             push( @{ $retorts{ lc( $m->{term} ) } }, $m->{retort} );
21 0 0       0 $bot->store->set( 'retorts' => \%retorts );
  0         0  
22 0         0  
  0         0  
23 0         0 $bot->reply_to('OK.');
24             },
25 0         0 );
26              
27 1         812 $bot->hook(
28             {
29             to_me => 1,
30             text => qr/^retort\s+(?<term>\([^\)]+\)|\S+)\s+clear\b/i,
31             },
32             sub {
33             my ( $bot, $in, $m ) = @_;
34              
35 0     0   0 my %retorts = %{ $bot->store->get('retorts') || {} };
36             delete $retorts{ lc( $m->{term} ) };
37 0 0       0 $bot->store->set( 'retorts' => \%retorts );
  0         0  
38 0         0  
39 0         0 $bot->reply_to('OK.');
40             },
41 0         0 );
42              
43 1         9 $bot->hook(
44             {
45             command => 'PRIVMSG',
46             },
47             sub {
48             my ( $bot, $in ) = @_;
49              
50 0     0   0 my %retorts = %{ $bot->store->get('retorts') || {} };
51             my @terms =
52 0 0       0 map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, rand ] }
  0         0  
53             grep { $in->{text} =~ /\b$_\b/i } keys %retorts;
54 0         0  
  0         0  
  0         0  
55 0         0 if (@terms) {
  0         0  
56             my @retorts = @{ $retorts{ $terms[ rand() * @terms ] } };
57 0 0       0 $bot->reply( $retorts[ rand() * @retorts ] ) if (@retorts);
58 0         0 }
  0         0  
59 0 0       0 },
60             );
61              
62 1         11 $bot->helps( retort =>
63             'Retort with statements. ' .
64 1         9 'Usage: retort <term> with <retort string>; retort <term> clear.',
65             );
66             }
67              
68             1;
69              
70              
71             =pod
72              
73             =encoding UTF-8
74              
75             =head1 NAME
76              
77             Bot::IRC::X::Retort - Bot::IRC plugin for bot-retorting to key words
78              
79             =head1 VERSION
80              
81             version 1.05
82              
83             =for markdown [![test](https://github.com/gryphonshafer/Bot-IRC-X-Retort/workflows/test/badge.svg)](https://github.com/gryphonshafer/Bot-IRC-X-Retort/actions?query=workflow%3Atest)
84             [![codecov](https://codecov.io/gh/gryphonshafer/Bot-IRC-X-Retort/graph/badge.svg)](https://codecov.io/gh/gryphonshafer/Bot-IRC-X-Retort)
85              
86             =head1 SYNOPSIS
87              
88             use Bot::IRC;
89              
90             Bot::IRC->new(
91             connect => { server => 'irc.perl.org' },
92             plugins => ['Retort'],
93             )->run;
94              
95             =head1 DESCRIPTION
96              
97             This L<Bot::IRC> plugin is for bot-retorting to key words.
98              
99             retort <term> with <retort string>
100             retort <term> clear
101              
102             =head1 SEE ALSO
103              
104             You can look for additional information at:
105              
106             =over 4
107              
108             =item *
109              
110             L<Bot::IRC>
111              
112             =item *
113              
114             L<GitHub|https://github.com/gryphonshafer/Bot-IRC-X-Retort>
115              
116             =item *
117              
118             L<MetaCPAN|https://metacpan.org/pod/Bot::IRC::X::Retort>
119              
120             =item *
121              
122             L<GitHub Actions|https://github.com/gryphonshafer/Bot-IRC-X-Retort/actions>
123              
124             =item *
125              
126             L<Codecov|https://codecov.io/gh/gryphonshafer/Bot-IRC-X-Retort>
127              
128             =item *
129              
130             L<CPANTS|http://cpants.cpanauthors.org/dist/Bot-IRC-X-Retort>
131              
132             =item *
133              
134             L<CPAN Testers|http://www.cpantesters.org/distro/T/Bot-IRC-X-Retort.html>
135              
136             =back
137              
138             =for Pod::Coverage init
139              
140             =head1 AUTHOR
141              
142             Gryphon Shafer <gryphon@cpan.org>
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             This software is Copyright (c) 2016-2050 by Gryphon Shafer.
147              
148             This is free software, licensed under:
149              
150             The Artistic License 2.0 (GPL Compatible)
151              
152             =cut