line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::IRC::Functions; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::IRC add maybe helpful functions to the bot |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2271
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
17
|
use exact; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.38'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub init { |
10
|
1
|
|
|
1
|
0
|
6683
|
my ($bot) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
3
|
my $alphabet = 'abcdefghijklmnopqrstuvwxyz'; |
13
|
1
|
|
|
|
|
6
|
my $start = uc($alphabet) . $alphabet; |
14
|
1
|
|
|
|
|
8
|
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
|
|
|
|
|
|
|
sub { |
22
|
4
|
|
|
4
|
|
1770
|
my ( $bot, $in, $m ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
12
|
my $function = lc( $m->{function} ); |
25
|
4
|
|
|
|
|
8
|
my $text = ''; |
26
|
|
|
|
|
|
|
|
27
|
4
|
100
|
33
|
|
|
37
|
if ( $function eq 'ord' ) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$text = |
29
|
|
|
|
|
|
|
"\"$m->{input}\" has a numerical value of " . |
30
|
1
|
|
|
|
|
7
|
join( ' ', map { ord($_) } split( '', $m->{input} ) ) . '.'; |
|
1
|
|
|
|
|
8
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( $function eq 'chr' or $function eq 'ascii' and $m->{input} =~ /^\d+$/ ) { |
33
|
|
|
|
|
|
|
$text = |
34
|
|
|
|
|
|
|
"$m->{input} has a character value of \"" . |
35
|
1
|
|
|
|
|
9
|
chr( $m->{input} ) . '".'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ( $function =~ /rot(\d+)/ ) { |
38
|
1
|
|
|
|
|
3
|
my $rot = $1; |
39
|
1
|
|
|
|
|
17
|
my @this_alphabet = @alphabet; |
40
|
1
|
|
|
|
|
6
|
push( @this_alphabet, splice( @this_alphabet, 0, $rot ) ); |
41
|
1
|
|
|
|
|
10
|
my $end = uc( join( '', @this_alphabet ) ) . join( '', @this_alphabet ); |
42
|
1
|
|
|
|
|
5
|
( $text = $m->{input} ) =~ tr/$start/$end/; |
43
|
1
|
|
|
|
|
6
|
$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
|
50
|
|
|
|
7
|
: join( '', map { $alphabet[ int( rand() * @alphabet ) ] } 0 .. 1 ); |
|
2
|
|
|
|
|
12
|
|
49
|
1
|
|
|
|
|
595
|
$text = 'The crypt value of your input is "' . crypt( $m->{input}, $salt ) . '".'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
4
|
50
|
|
|
|
22
|
$bot->reply($text) if ($text); |
53
|
|
|
|
|
|
|
}, |
54
|
1
|
|
|
|
|
16
|
); |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
18
|
$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
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Bot::IRC::Functions - Bot::IRC add maybe helpful functions to the bot |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 VERSION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
version 1.38 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use Bot::IRC; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Bot::IRC->new( |
83
|
|
|
|
|
|
|
connect => { server => 'irc.perl.org' }, |
84
|
|
|
|
|
|
|
plugins => ['Functions'], |
85
|
|
|
|
|
|
|
)->run; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This L<Bot::IRC> plugin adds what might be helpful functions to the bot. |
90
|
|
|
|
|
|
|
Commands include: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 ord <character> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Convert a character into its ASCII number equivalent. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 (chr|ascii) <number> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Convert a number into its ASCII character equivalent. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 rot<number> <string> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Inspired by ROT13, this function will transpose letters based on the sequence |
103
|
|
|
|
|
|
|
of the alphabet and by the number provided. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
rot13 hello |
106
|
|
|
|
|
|
|
rot42 hello again |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
ROT13 is a simple letter substitution cipher that replaces a letter with the |
109
|
|
|
|
|
|
|
letter 13 letters after it in the alphabet. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 crypt <string> [<salt>] |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This method will encrypt using C<crypt> a string. If the salt is not provided, |
114
|
|
|
|
|
|
|
it will be randomly generated. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<Bot::IRC> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=for Pod::Coverage init |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Gryphon Shafer <gryphon@cpan.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is Copyright (c) 2016-2021 by Gryphon Shafer. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software, licensed under: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |