our
$AUTHORITY
=
'cpan:HINRIK'
;
$POE::Component::IRC::Plugin::NickReclaim::VERSION
=
'6.93'
;
sub
new {
my
(
$package
) =
shift
;
croak
"$package requires an even number of arguments"
if
@_
& 1;
my
%args
=
@_
;
$args
{
lc
$_
} =
delete
$args
{
$_
}
for
keys
%args
;
if
(!
defined
$args
{poll} ||
$args
{poll} !~ /^\d+$/) {
$args
{poll} = 30;
}
return
bless
\
%args
,
$package
;
}
sub
PCI_register {
my
(
$self
,
$irc
) =
@_
;
$irc
->plugin_register(
$self
,
'SERVER'
,
qw(001 433 nick quit)
);
$irc
->plugin_register(
$self
,
'USER'
,
qw(nick)
);
$self
->{_desired_nick} =
$irc
->nick_name();
return
1;
}
sub
PCI_unregister {
return
1;
}
sub
U_nick {
my
$self
=
shift
;
my
(
$nick
) = ${
$_
[1] } =~ /^NICK +(.+)/i;
if
(!
defined
$self
->{_temp_nick} ||
$self
->{_temp_nick} ne
$nick
) {
delete
$self
->{_temp_nick};
$self
->{_desired_nick} =
$nick
;
}
return
PCI_EAT_NONE;
}
sub
S_001 {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
$self
->{_reclaimed} =
$irc
->nick_name eq
$self
->{_desired_nick} ? 1 : 0;
return
PCI_EAT_NONE;
}
sub
S_433 {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$offending
= ${
$_
[2] }->[0];
if
(!
$irc
->logged_in ||
$irc
->nick_name() eq
$offending
) {
my
$temp_nick
=
"${offending}_"
;
$self
->{_temp_nick} =
$temp_nick
;
$irc
->yield(
'nick'
,
$temp_nick
);
}
$irc
->delay_remove(
$self
->{_alarm_id})
if
defined
$self
->{_alarm_id};
$self
->{_alarm_id} =
$irc
->delay(
[
'nick'
,
$self
->{_desired_nick} ],
$self
->{poll}
);
return
PCI_EAT_NONE;
}
sub
S_quit {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$who
= parse_user(${
$_
[0] });
if
(
$who
eq
$irc
->nick_name) {
$irc
->delay_remove(
$self
->{_alarm_id})
if
defined
$self
->{_alarm_id};
}
elsif
(!
$self
->{_reclaimed} &&
$who
eq
$self
->{_desired_nick}) {
$irc
->delay_remove(
$self
->{_alarm_id})
if
defined
$self
->{_alarm_id};
$irc
->yield(
'nick'
,
$self
->{_desired_nick});
}
return
PCI_EAT_NONE;
}
sub
S_nick {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$old_nick
= parse_user(${
$_
[0] });
my
$new_nick
= ${
$_
[1] };
if
(
$new_nick
eq
$irc
->nick_name) {
if
(
$new_nick
eq
$self
->{_desired_nick}) {
$self
->{_reclaimed} = 1;
$irc
->delay_remove(
$self
->{_alarm_id})
if
defined
$self
->{_alarm_id};
}
}
elsif
(
$old_nick
eq
$self
->{_desired_nick}) {
$irc
->delay_remove(
$self
->{_alarm_id})
if
defined
$self
->{_alarm_id};
$irc
->yield(
'nick'
,
$self
->{_desired_nick});
}
return
PCI_EAT_NONE;
}
1;