| 1 | package Bot::IRC::Functions; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Bot::IRC add maybe helpful functions to the bot | ||||||||||||||||||||||||||||||||||
| 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=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | my ($bot) = @_; | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | my $alphabet = 'abcdefghijklmnopqrstuvwxyz'; | |||||||||||||||||||||||||||||||||
| 13 | 1 | my $start = uc($alphabet) . $alphabet; | |||||||||||||||||||||||||||||||||
| 14 | 1 | my @alphabet = split( '', $alphabet ); | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | $bot->hook( | ||||||||||||||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||||||||||||
| 18 | command => 'PRIVMSG', | ||||||||||||||||||||||||||||||||||
| 19 | text => qr/^(?<function>ord|chr|ascii|rot\d+|crypt)\s+(?<input>.+)/i, | ||||||||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.4
| |||||||||||||||||||||||||||||||||||
| 22 | 4 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 4 | my $function = lc( $m->{function} ); | |||||||||||||||||||||||||||||||||
| 25 | 4 | my $text = ''; | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | if ( $function eq 'ord' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 28 | $text = | ||||||||||||||||||||||||||||||||||
| 29 | "\"$m->{input}\" has a numerical value of " . | ||||||||||||||||||||||||||||||||||
| 30 | 1 | join( ' ', map { ord($_) } split( '', $m->{input} ) ) . '.'; | |||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | ▶ | elsif ( $function eq 'chr' or $function eq 'ascii' and $m->{input} =~ /^\d+$/ ) { | |||||||||||||||||||||||||||||||||
|
Condition50%3/6
$function eq "chr" or $function eq "ascii" and $m->{"input"} =~ /^\d+$/u
$function eq "ascii" and $m->{"input"} =~ /^\d+$/u
MC/DC33%1/3
$function eq "chr" or $function eq "ascii" and $m->{"input"} =~ /^\d+$/u
$function eq "chr"
$function eq "ascii"
$m->{"input"} =~ /^\d+$/u
Truth table50%2/4
A or B and C
A= $function eq "chr"B= $function eq "ascii"C= $m->{"input"} =~ /^\d+$/u
| |||||||||||||||||||||||||||||||||||
| 33 | $text = | ||||||||||||||||||||||||||||||||||
| 34 | "$m->{input} has a character value of \"" . | ||||||||||||||||||||||||||||||||||
| 35 | 1 | chr( $m->{input} ) . '".'; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | elsif ( $function =~ /rot(\d+)/ ) { | ||||||||||||||||||||||||||||||||||
| 38 | 1 | my $rot = $1; | |||||||||||||||||||||||||||||||||
| 39 | 1 | my @this_alphabet = @alphabet; | |||||||||||||||||||||||||||||||||
| 40 | 1 | push( @this_alphabet, splice( @this_alphabet, 0, $rot ) ); | |||||||||||||||||||||||||||||||||
| 41 | 1 | my $end = uc( join( '', @this_alphabet ) ) . join( '', @this_alphabet ); | |||||||||||||||||||||||||||||||||
| 42 | 1 | ( $text = $m->{input} ) =~ tr/$start/$end/; | |||||||||||||||||||||||||||||||||
| 43 | 1 | $text = "The ROT$rot of your input is \"$text\"."; | |||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | elsif ( $function eq 'crypt' ) { | ||||||||||||||||||||||||||||||||||
| 46 | my $salt = ( $m->{input} =~ s/(\w+)\s+(\w{2})\s*$/$1/ ) | ||||||||||||||||||||||||||||||||||
| 47 | ? $2 | ||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | : join( '', map { $alphabet[ int( rand() * @alphabet ) ] } 0 .. 1 ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 49 | 1 | $text = 'The crypt value of your input is "' . crypt( $m->{input}, $salt ) . '".'; | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | $bot->reply($text) if ($text); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||
| 54 | 1 | ); | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 1 | $bot->helps( functions => | |||||||||||||||||||||||||||||||||
| 57 | 'A set of maybe useful functions. ' . | ||||||||||||||||||||||||||||||||||
| 58 | 'Usage: ord <character>; (chr|ascii) <number>; rot<number> <string>; crypt <string> [<salt>].' | ||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||||||||