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