Nickometer.pm

filter: Statementstmt 15.6% 13 / 83 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 33.3% 4 / 12 Podpod 25.0% 2 / 8 totaltotal 12.5% 19 / 152 CC 23 SCAR 52.3
CC
23
Cov
10%
percentage
342.0
said
30.0
round_up
6.0
CRAP 186.2
« Botsnack.pm ↑ Summary Excuse.pm »
1 package Bot::BasicBot::Pluggable::Module::Nickometer;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 1 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub said {
Subroutine said: not called CC=5 SCAR=34.0
Pod documented
11 0 my ($self, $mess, $pri) = @_;
12  
13 0 my $body = $mess->{body};
14 0 my $who = $mess->{who};
15  
16 0 ▶ return unless ($pri == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 2 0 0 0
17 0 ▶ return unless $body =~ /^\s*(?:lame|nick)-?o-?meter(?: for)? (\S+)/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /^\s*(?:lame|nick)-?o-?meter(?: for)? (\S+)/i 0 0 0
18  
19 0 ▶ my $term = $1; $term = $who if (lc($term) eq 'me');
Branch: 1 branch
BranchTrueFalseTotal
if lc $term eq "me" 0 0 0
20  
21
22 0 my $percentage = percentage($term);
23
24  
25 0 ▶ if ($percentage =~ /NaN/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($percentage =~ /NaN/) { } 0 0 0
26 0 $percentage = "off the scale";
27 } else {
28 # $percentage = sprintf("%0.4f", $percentage);
29 0 $percentage =~ s/\.0+$//;
30 0 $percentage .= '%';
31 }
32
33 0 return "'$term' is $percentage lame, $who";
34 }
35  
36 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
37 0 return "Commands: 'nickometer <nick>'";
38 }
39  
40  
41 0 ▶sub percentage {
Subroutine percentage: not called CC=18 SCAR=58.3
Pod undocumented
42 0 local $_ = shift;
43  
44 0 my $score = 0;
45
46 # Deal with special cases (precede with \ to prevent de-k3wlt0k)
47 0 my %special_cost = (
48 '69' => 500,
49 'dea?th' => 500,
50 'dark' => 400,
51 'n[i1]ght' => 300,
52 'n[i1]te' => 500,
53 'fuck' => 500,
54 'sh[i1]t' => 500,
55 'coo[l1]' => 500,
56 'kew[l1]' => 500,
57 'lame' => 500,
58 'dood' => 500,
59 'dude' => 500,
60 '[l1](oo?|u)[sz]er' => 500,
61 '[l1]eet' => 500,
62 'e[l1]ite' => 500,
63 '[l1]ord' => 500,
64 'pron' => 1000,
65 'warez' => 1000,
66 'xx' => 100,
67 '\[rkx]0' => 1000,
68 '\0[rkx]' => 1000,
69 );
70  
71  
72  
73 0 foreach my $special (keys %special_cost) {
74 0 my $special_pattern = $special;
75 0 my $raw = ($special_pattern =~ s/^\\//);
76 0 my $nick = $_;
77 0 ▶ $nick =~ tr/023457+8/ozeasttb/ unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 0 0 0
78 0 ▶ $score += $special_cost{$special} if $nick =~ /$special_pattern/i;
Branch: 1 branch
BranchTrueFalseTotal
if $nick =~ /$special_pattern/i 0 0 0
79 }
80
81 # Allow Perl referencing
82 0 s/^\\([A-Za-z])/$1/;
83
84 # Keep me safe from Pudge ;-)
85 0 s/\^(pudge)/$1/i;
86  
87 # C-- ain't so bad either
88 0 s/^C--$/C/;
89
90 # Punish consecutive non-alphas
91 0 s/([^A-Za-z0-9]{2,})
92 0 /my $consecutive = length($1);
93 0 ▶ $score += slow_pow(10, $consecutive) if $consecutive;
Branch: 1 branch
BranchTrueFalseTotal
if $consecutive 0 0 0
94 0 $1
95 /egx;
96  
97 # Remove balanced brackets and punish for unmatched
98 0 ▶ while (s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x ||
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x or s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x or s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x) 0 0 0
Condition0%0/6
s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x or s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x or s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x
l!l&&r!l&&!r
000
s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x or s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x
l!l&&r!l&&!r
000
MC/DC0%0/3
s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x or s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x or s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x
s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/x s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x
Truth table0%0/4
A or B or C
A= s/^([^()]*) (\() (.*) (\)) ([^()]*) $/$1$3$5/xB= s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/xC= s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x
ABCresult
1XX1
01X1
0011
0000
99 s/^([^{}]*) (\{) (.*) (\}) ([^{}]*) $/$1$3$5/x ||
100 s/^([^\[\]]*) (\[) (.*) (\]) ([^\[\]]*) $/$1$3$5/x)
101 {}
102 0 my $parentheses = tr/(){}[]/(){}[]/;
103 0 ▶ $score += slow_pow(10, $parentheses) if $parentheses;
Branch: 1 branch
BranchTrueFalseTotal
if $parentheses 0 0 0
104  
105 # Punish k3wlt0k
106 0 my @k3wlt0k_weights = (5, 5, 2, 5, 2, 3, 1, 2, 2, 2);
107 0 for my $digit (0 .. 9) {
108 0 ▶ my $occurrences = s/$digit/$digit/g || 0;
Condition0%0/2
s/$digit/$digit/g || 0
l!l
00
MC/DC0%0/1
s/$digit/$digit/g || 0
s/$digit/$digit/g
Truth table0%0/2
A
A= s/$digit/$digit/g
Aresult
11
00
109 0 ▶ $score += ($k3wlt0k_weights[$digit] * $occurrences * 30) if $occurrences;
Branch: 1 branch
BranchTrueFalseTotal
if $occurrences 0 0 0
110 }
111  
112 # An alpha caps is not lame in middle or at end, provided the first
113 # alpha is caps.
114 0 my $orig_case = $_;
115 0 s/^([^A-Za-z]*[A-Z].*[a-z].*?)[_-]?([A-Z])/$1\l$2/;
116
117 # A caps first alpha is sometimes not lame
118 0 s/^([^A-Za-z]*)([A-Z])([a-z])/$1\l$2$3/;
119  
120  
121 # Punish uppercase to lowercase shifts and vice-versa, modulo
122 # exceptions above
123 0 my $case_shifts = case_shifts($orig_case);
124 0 ▶ $score += slow_pow(9, $case_shifts) if ($case_shifts > 1 && /[A-Z]/);
Branch: 1 branch
BranchTrueFalseTotal
if $case_shifts > 1 and /[A-Z]/ 0 0 0
Condition0%0/3
$case_shifts > 1 and /[A-Z]/
!ll&&!rl&&r
000
MC/DC0%0/2
$case_shifts > 1 and /[A-Z]/
$case_shifts > 1 /[A-Z]/
Truth table0%0/3
A and B
A= $case_shifts > 1B= /[A-Z]/
ABresult
0X0
100
111
125  
126 # Punish lame endings (TorgoX, WraithX et al. might kill me for this :-)
127 0 ▶ $score += 50 if $orig_case =~ /[XZ][^a-zA-Z]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $orig_case =~ /[XZ][^a-zA-Z]*$/ 0 0 0
128  
129 # Punish letter to numeric shifts and vice-versa
130 0 my $number_shifts = number_shifts($_);
131 0 ▶ $score += slow_pow(9, $number_shifts) if $number_shifts > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $number_shifts > 1 0 0 0
132  
133 # Punish extraneous caps
134 0 my $caps = tr/A-Z/A-Z/;
135 0 ▶ $score += slow_pow(7, $caps) if $caps;
Branch: 1 branch
BranchTrueFalseTotal
if $caps 0 0 0
136  
137 # Now punish anything that's left
138 0 my $remains = $_;
139 0 $remains =~ tr/a-zA-Z0-9//d;
140 0 my $remains_length = length($remains);
141  
142 0 ▶ $score += (50 * $remains_length + slow_pow(9, $remains_length)) if $remains;
Branch: 1 branch
BranchTrueFalseTotal
if $remains 0 0 0
143  
144 # Use an appropriate function to map [0, +inf) to [0, 100)
145 0 my $percentage = 100 *
146 (1 + tanh(($score-400)/400)) *
147 (1 - 1/(1+$score/5)) / 2;
148  
149 0 my $digits = 2 * (2 - &round_up(log(100 - $percentage) / log(10)));
150  
151 0 return sprintf "%.${digits}f", $percentage;
152  
153 }
154  
155 0 ▶sub case_shifts ($) {
Subroutine case_shifts: not called CC=1 SCAR=6.9
Pod undocumented
156 # This is a neat trick suggested by freeside. Thanks freeside!
157  
158 0 my $shifts = shift;
159  
160 0 $shifts =~ tr/A-Za-z//cd;
161 0 $shifts =~ tr/A-Z/U/s;
162 0 $shifts =~ tr/a-z/l/s;
163  
164 0 return length($shifts) - 1;
165 }
166  
167 0 ▶sub number_shifts ($) {
Subroutine number_shifts: not called CC=1 SCAR=6.9
Pod undocumented
168 0 my $shifts = shift;
169  
170 0 $shifts =~ tr/A-Za-z0-9//cd;
171 0 $shifts =~ tr/A-Za-z/l/s;
172 0 $shifts =~ tr/0-9/n/s;
173  
174 0 return length($shifts) - 1;
175 }
176  
177 0 ▶sub slow_pow ($$) {
Subroutine slow_pow: not called CC=1 SCAR=6.9
Pod undocumented
178 0 my ($x, $y) = @_;
179  
180 0 return $x ** slow_exponent($y);
181 }
182  
183  
184 0 ▶sub slow_exponent ($) {
Subroutine slow_exponent: not called CC=1 SCAR=6.9
Pod undocumented
185 0 my $x = shift;
186  
187 0 return 1.3 * $x * (1 - atan($x/6) *2/pi);
188 }
189  
190 0 ▶sub round_up ($) {
Subroutine round_up: not called CC=2 SCAR=17.9
Pod undocumented
191 0 my $float = shift;
192  
193 0 ▶ return int($float) + ((int($float) == $float) ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
int $float == $float ? : 0 0 0
194 }
195  
196  
197  
198  
199 1 1;
200  
201 =head1 NAME
202  
203 Bot::BasicBot::Pluggable::Module::Nickometer - check how lame a nick is
204  
205 =head1 IRC USAGE
206  
207 nickometer <nick>
208  
209 =head1 AUTHOR
210  
211 Simon Wistow, <simon@thegestalt.org>
212  
213 based on code by Adam Spiers <adam.spiers@new.ox.ac.uk>
214  
215  
216 =head1 COPYRIGHT
217  
218 Copyright 2005, Simon Wistow
219  
220 Distributed under the same terms as Perl itself.
221  
222 =head1 SEE ALSO
223  
224  
225 =cut
226  
« Botsnack.pm ↑ Summary Excuse.pm »