| 1 | package POE::Component::IRC::Plugin::NickReclaim; | ||||||||||||||||||||||||||||
| 2 | 5 | $POE::Component::IRC::Plugin::NickReclaim::VERSION = '6.95'; | |||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use IRC::Utils qw(parse_user); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use POE::Component::IRC::Plugin qw(PCI_EAT_NONE); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 4 | my ($package) = shift; | |||||||||||||||||||||||||||
| 11 | 4 | ▶ | croak "$package requires an even number of arguments" if @_ & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 4 | my %args = @_; | |||||||||||||||||||||||||||
| 13 | 4 | $args{ lc $_ } = delete $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | if (!defined $args{poll} || $args{poll} !~ /^\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args{"poll"} and $args{"poll"} =~ /^\d+$/
MC/DC50%1/2
defined $args{"poll"} and $args{"poll"} =~ /^\d+$/
defined $args{"poll"}
$args{"poll"} =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $args{"poll"}B= $args{"poll"} =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 16 | 1 | $args{poll} = 30; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | return bless \%args, $package; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | sub PCI_register { | ||||||||||||||||||||||||||
|
Subroutine
PCI_register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 4 | my ($self, $irc) = @_; | |||||||||||||||||||||||||||
| 24 | 4 | $irc->plugin_register( $self, 'SERVER', qw(001 433 nick quit) ); | |||||||||||||||||||||||||||
| 25 | 4 | $irc->plugin_register( $self, 'USER', qw(nick) ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 4 | $self->{_desired_nick} = $irc->nick_name(); | |||||||||||||||||||||||||||
| 28 | 4 | return 1; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | ▶ | sub PCI_unregister { | ||||||||||||||||||||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 4 | return 1; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 9 | ▶ | sub U_nick { | ||||||||||||||||||||||||||
|
Subroutine
U_nick: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 9 | my ($nick) = ${ $_[1] } =~ /^NICK +(.+)/i; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | if (!defined $self->{_temp_nick} || $self->{_temp_nick} ne $nick) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $self->{"_temp_nick"} or $self->{"_temp_nick"} ne $nick
MC/DC100%2/2
not defined $self->{"_temp_nick"} or $self->{"_temp_nick"} ne $nick
not defined $self->{"_temp_nick"}
$self->{"_temp_nick"} ne $nick
Truth table100%3/3
not(A) or B
A= not defined $self->{"_temp_nick"}B= $self->{"_temp_nick"} ne $nick
| |||||||||||||||||||||||||||||
| 40 | 6 | delete $self->{_temp_nick}; | |||||||||||||||||||||||||||
| 41 | 6 | $self->{_desired_nick} = $nick; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 9 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | sub S_001 { | ||||||||||||||||||||||||||
|
Subroutine
S_001: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 3 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 48 | 3 | ▶ | $self->{_reclaimed} = $irc->nick_name eq $self->{_desired_nick} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 3 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # ERR_NICKNAMEINUSE | ||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub S_433 { | ||||||||||||||||||||||||||
|
Subroutine
S_433: called CC=4 SCAR=14.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 3 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 55 | 3 | my $offending = ${ $_[2] }->[0]; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if (!$irc->logged_in || $irc->nick_name() eq $offending) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $irc->logged_in or $irc->nick_name eq $offending
MC/DC0%0/2
not $irc->logged_in or $irc->nick_name eq $offending
not $irc->logged_in
$irc->nick_name eq $offending
Truth table33%1/3
not(A) or B
A= not $irc->logged_inB= $irc->nick_name eq $offending
| |||||||||||||||||||||||||||||
| 58 | 3 | my $temp_nick = "${offending}_"; | |||||||||||||||||||||||||||
| 59 | 3 | $self->{_temp_nick} = $temp_nick; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | $irc->yield('nick', $temp_nick); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | $irc->delay_remove($self->{_alarm_id}) if defined $self->{_alarm_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | $self->{_alarm_id} = $irc->delay( | ||||||||||||||||||||||||||||
| 66 | ['nick', $self->{_desired_nick} ], | ||||||||||||||||||||||||||||
| 67 | $self->{poll} | ||||||||||||||||||||||||||||
| 68 | 3 | ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub S_quit { | ||||||||||||||||||||||||||
|
Subroutine
S_quit: called CC=6 SCAR=21.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 1 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 75 | 1 | my $who = parse_user(${ $_[0] }); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | if ($who eq $irc->nick_name) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $irc->delay_remove($self->{_alarm_id}) if defined $self->{_alarm_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | ▶ | elsif (!$self->{_reclaimed} && $who eq $self->{_desired_nick}) { | |||||||||||||||||||||||||||
|
Condition33%1/3
not $self->{"_reclaimed"} and $who eq $self->{"_desired_nick"}
MC/DC0%0/2
not $self->{"_reclaimed"} and $who eq $self->{"_desired_nick"}
not $self->{"_reclaimed"}
$who eq $self->{"_desired_nick"}
Truth table33%1/3
not(A) and B
A= not $self->{"_reclaimed"}B= $who eq $self->{"_desired_nick"}
| |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | $irc->delay_remove($self->{_alarm_id}) if defined $self->{_alarm_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | $irc->yield('nick', $self->{_desired_nick}); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | sub S_nick { | ||||||||||||||||||||||||||
|
Subroutine
S_nick: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 89 | 4 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 90 | 4 | my $old_nick = parse_user(${ $_[0] }); | |||||||||||||||||||||||||||
| 91 | 4 | my $new_nick = ${ $_[1] }; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 4 | ▶ | if ($new_nick eq $irc->nick_name) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | if ($new_nick eq $self->{_desired_nick}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 3 | $self->{_reclaimed} = 1; | |||||||||||||||||||||||||||
| 96 | 3 | ▶ | $irc->delay_remove($self->{_alarm_id}) if defined $self->{_alarm_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | elsif ($old_nick eq $self->{_desired_nick}) { | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | $irc->delay_remove($self->{_alarm_id}) if defined $self->{_alarm_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | $irc->yield('nick', $self->{_desired_nick}); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 4 | return PCI_EAT_NONE; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 5 | 1; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =encoding utf8 | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 NAME | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | POE::Component::IRC::Plugin::NickReclaim - A PoCo-IRC plugin for reclaiming | ||||||||||||||||||||||||||||
| 114 | your nickname | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | use strict; | ||||||||||||||||||||||||||||
| 119 | use warnings; | ||||||||||||||||||||||||||||
| 120 | use POE qw(Component::IRC Component::IRC::Plugin::NickReclaim); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | my $nickname = 'Flibble' . $$; | ||||||||||||||||||||||||||||
| 123 | my $ircname = 'Flibble the Sailor Bot'; | ||||||||||||||||||||||||||||
| 124 | my $ircserver = 'irc.blahblahblah.irc'; | ||||||||||||||||||||||||||||
| 125 | my $port = 6667; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | my $irc = POE::Component::IRC->spawn( | ||||||||||||||||||||||||||||
| 128 | nick => $nickname, | ||||||||||||||||||||||||||||
| 129 | server => $ircserver, | ||||||||||||||||||||||||||||
| 130 | port => $port, | ||||||||||||||||||||||||||||
| 131 | ircname => $ircname, | ||||||||||||||||||||||||||||
| 132 | ) or die "Oh noooo! $!"; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | POE::Session->create( | ||||||||||||||||||||||||||||
| 135 | package_states => [ | ||||||||||||||||||||||||||||
| 136 | main => [ qw(_start) ], | ||||||||||||||||||||||||||||
| 137 | ], | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | $poe_kernel->run(); | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub _start { | ||||||||||||||||||||||||||||
| 143 | $irc->yield( register => 'all' ); | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # Create and load our NickReclaim plugin, before we connect | ||||||||||||||||||||||||||||
| 146 | $irc->plugin_add( 'NickReclaim' => | ||||||||||||||||||||||||||||
| 147 | POE::Component::IRC::Plugin::NickReclaim->new( poll => 30 ) ); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | $irc->yield( connect => { } ); | ||||||||||||||||||||||||||||
| 150 | return; | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | POE::Component::IRC::Plugin::NickReclaim - A | ||||||||||||||||||||||||||||
| 156 | L<POE::Component::IRC|POE::Component::IRC> plugin automagically deals with | ||||||||||||||||||||||||||||
| 157 | your bot's nickname being in use and reclaims it when it becomes available | ||||||||||||||||||||||||||||
| 158 | again. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | It registers and handles 'irc_433' events. On receiving a 433 event it will | ||||||||||||||||||||||||||||
| 161 | reset the nickname to the 'nick' specified with C<spawn> or C<connect>, | ||||||||||||||||||||||||||||
| 162 | appendedwith an underscore, and then poll to try and change it to the | ||||||||||||||||||||||||||||
| 163 | original nickname. If someone in your channel who has the nickname you're | ||||||||||||||||||||||||||||
| 164 | after quits or changes nickname, the plugin will try to reclaim it | ||||||||||||||||||||||||||||
| 165 | immediately. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head1 METHODS | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head2 C<new> | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Takes one optional argument: | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | B<'poll'>, the number of seconds between nick change attempts, default is 30; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Returns a plugin object suitable for feeding to | ||||||||||||||||||||||||||||
| 176 | L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Chris 'BinGOs' Williams | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | With amendments applied by Zoffix Znet | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | L<POE::Component::IRC|POE::Component::IRC> | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||