| 1 | package Hubot::Scripts::roles; | ||||||||||||||
| 2 | 2 | $Hubot::Scripts::roles::VERSION = '0.2.8'; | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | sub load { | ||||||||||||
|
Subroutine
load: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||
| 7 | 2 | my ( $class, $robot ) = @_; | |||||||||||||
| 8 | $robot->respond( | ||||||||||||||
| 9 | qr/who is \@?([\w \.-_]+)\?*$/i, | ||||||||||||||
| 10 | 5 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.1
| |||||||||||||||
| 11 | 5 | my $msg = shift; | |||||||||||||
| 12 | 5 | my $joiner = ', '; | |||||||||||||
| 13 | 5 | my $name = $msg->match->[0]; | |||||||||||||
| 14 | 5 | $name =~ s/(^\s+|\s+$)//g; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 5 | ▶ | if ( $name eq 'you' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | 0 | $msg->send("Who ain't I?"); | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | elsif ( $name eq $robot->name ) { | ||||||||||||||
| 20 | 1 | $msg->send("The best."); | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | else { | ||||||||||||||
| 23 | 4 | my @users = $robot->usersForFuzzyName($name); | |||||||||||||
| 24 | 4 | ▶ | if ( scalar @users == 1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 25 | 3 | my $user = $users[0]; | |||||||||||||
| 26 | 3 | ▶ | $user->{roles} ||= []; | ||||||||||||
|
Condition100%2/2
$user->{"roles"} ||= []
MC/DC100%1/1
$user->{"roles"} ||= []
$user->{"roles"}
Truth table100%2/2
A
A= $user->{"roles"}
| |||||||||||||||
| 27 | 3 | my @roles = @{ $user->{roles} }; | |||||||||||||
| 28 | 3 | ▶ | if ( scalar @roles > 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 1 | ▶ | $joiner = '; ' if join( '', @roles ) =~ m/,/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 1 | $msg->send( "$name is " . join( $joiner, @roles ) ); | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | else { | ||||||||||||||
| 33 | 2 | $msg->send("$name is nothing to me."); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | } | ||||||||||||||
| 36 | elsif ( scalar @users > 1 ) { | ||||||||||||||
| 37 | 0 | $msg->send( getAmbiguousUserText(@users) ); | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | 1 | $msg->send("$name? Never heard of 'em"); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | } | ||||||||||||||
| 44 | 2 | ); | |||||||||||||
| 45 | |||||||||||||||
| 46 | $robot->respond( | ||||||||||||||
| 47 | qr/\@?([\w \.-_]+) is ([\"\'\w: -_]+)[\.!]*$/i, | ||||||||||||||
| 48 | 8 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.6
| |||||||||||||||
| 49 | 8 | my $msg = shift; | |||||||||||||
| 50 | 8 | my ( $name, $newRole ) = @{ $msg->match }; | |||||||||||||
| 51 | 8 | $name =~ s/(^\s+|\s+$)//g; | |||||||||||||
| 52 | 8 | $newRole =~ s/(^\s+|\s+$)//g; | |||||||||||||
| 53 | 8 | ▶ | if ( $name !~ m/^(|who|what|where|when|why)$/i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 3 | ▶ | unless ( $newRole =~ m/^not\s+/i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 2 | my @users = $robot->usersForFuzzyName($name); | |||||||||||||
| 56 | 2 | ▶ | if ( scalar @users == 1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 57 | 1 | my $user = $users[0]; | |||||||||||||
| 58 | 1 | ▶ | $user->{roles} ||= []; | ||||||||||||
|
Condition50%1/2
$user->{"roles"} ||= []
MC/DC0%0/1
$user->{"roles"} ||= []
$user->{"roles"}
Truth table50%1/2
A
A= $user->{"roles"}
| |||||||||||||||
| 59 | 0 | ▶ | if ( grep { $newRole eq $_ } @{ $user->{roles} } ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 60 | 0 | $msg->send("I know."); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | else { | ||||||||||||||
| 63 | 1 | push @{ $user->{roles} }, $newRole; | |||||||||||||
| 64 | 1 | ▶ | if ( lc $name eq $robot->name ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 0 | $msg->send("OK, I am $newRole."); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | else { | ||||||||||||||
| 68 | 1 | $msg->send("OK, $name is $newRole."); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | elsif ( scalar @users > 1 ) { | ||||||||||||||
| 73 | 0 | $msg->send( getAmbiguousUserText(@users) ); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | else { | ||||||||||||||
| 76 | 1 | $msg->send("I don't know anything about $name."); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | } | ||||||||||||||
| 81 | 2 | ); | |||||||||||||
| 82 | |||||||||||||||
| 83 | $robot->respond( | ||||||||||||||
| 84 | qr/\@?([\w \.-_]+) is not ([\"\'\w: -_]+)[\.!]*$/i, | ||||||||||||||
| 85 | 1 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.3
| |||||||||||||||
| 86 | 1 | my $msg = shift; | |||||||||||||
| 87 | 1 | my ( $name, $newRole ) = @{ $msg->match }; | |||||||||||||
| 88 | 1 | $name =~ s/(^\s+|\s+$)//g; | |||||||||||||
| 89 | 1 | $newRole =~ s/(^\s+|\s+$)//g; | |||||||||||||
| 90 | 1 | ▶ | if ( $name !~ m/^(|who|what|where|when|why)$/i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 1 | my @users = $robot->usersForFuzzyName($name); | |||||||||||||
| 92 | 1 | ▶ | if ( scalar @users == 1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 93 | 1 | my $user = $users[0]; | |||||||||||||
| 94 | 1 | ▶ | $user->{roles} ||= []; | ||||||||||||
|
Condition50%1/2
$user->{"roles"} ||= []
MC/DC0%0/1
$user->{"roles"} ||= []
$user->{"roles"}
Truth table50%1/2
A
A= $user->{"roles"}
| |||||||||||||||
| 95 | 1 | ▶ | if ( !grep { $newRole eq $_ } @{ $user->{roles} } ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 96 | 0 | $msg->send("I know."); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | else { | ||||||||||||||
| 99 | my @roles | ||||||||||||||
| 100 | 1 | = grep { $newRole ne $_ } @{ $user->{roles} }; | |||||||||||||
| 101 | 1 | $user->{roles} = \@roles; | |||||||||||||
| 102 | 1 | $msg->send("OK, $name is no longer $newRole."); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | } | ||||||||||||||
| 105 | elsif ( scalar @users > 1 ) { | ||||||||||||||
| 106 | 0 | $msg->send( getAmbiguousUserText(@users) ); | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | else { | ||||||||||||||
| 109 | 0 | $msg->send("I don't know anything about $name."); | |||||||||||||
| 110 | } | ||||||||||||||
| 111 | } | ||||||||||||||
| 112 | } | ||||||||||||||
| 113 | 2 | ); | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | |||||||||||||||
| 116 | 0 | ▶ | sub getAmbiguousUserText { | ||||||||||||
|
Subroutine
getAmbiguousUserText: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 117 | 0 | my @users = @_; | |||||||||||||
| 118 | return sprintf( | ||||||||||||||
| 119 | "Be more specific, I know %d people named like that: %s", | ||||||||||||||
| 120 | scalar @users, | ||||||||||||||
| 121 | 0 | join( ', ', map { $_->{name} } @users ) | |||||||||||||
| 122 | ); | ||||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 2 | 1; | |||||||||||||
| 126 | |||||||||||||||
| 127 | =pod | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =encoding utf-8 | ||||||||||||||
| 130 | |||||||||||||||
| 131 | =head1 NAME | ||||||||||||||
| 132 | |||||||||||||||
| 133 | Hubot::Scripts::roles | ||||||||||||||
| 134 | |||||||||||||||
| 135 | =head1 VERSION | ||||||||||||||
| 136 | |||||||||||||||
| 137 | version 0.2.8 | ||||||||||||||
| 138 | |||||||||||||||
| 139 | =head1 SYNOPSIS | ||||||||||||||
| 140 | |||||||||||||||
| 141 | hubot <user> is a badass guitarist - assign a role to a user | ||||||||||||||
| 142 | hubot <user> is not a badass guitarist - remove a role from a user | ||||||||||||||
| 143 | hubot who is <user> - see what roles a user has | ||||||||||||||
| 144 | |||||||||||||||
| 145 | =head1 AUTHOR | ||||||||||||||
| 146 | |||||||||||||||
| 147 | Hyungsuk Hong <hshong@perl.kr> | ||||||||||||||
| 148 | |||||||||||||||
| 149 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 150 | |||||||||||||||
| 151 | This software is copyright (c) 2012 by Hyungsuk Hong. | ||||||||||||||
| 152 | |||||||||||||||
| 153 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 154 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 155 | |||||||||||||||
| 156 | =cut | ||||||||||||||