our
$AUTHORITY
=
'cpan:HINRIK'
;
$POE::Component::IRC::Plugin::NickServID::VERSION
=
'6.93'
;
sub
new {
my
(
$package
) =
shift
;
croak
"$package requires an even number of arguments"
if
@_
& 1;
my
%self
=
@_
;
die
"$package requires a Password"
if
!
defined
$self
{Password};
return
bless
\
%self
,
$package
;
}
sub
PCI_register {
my
(
$self
,
$irc
) =
@_
;
$self
->{nick} =
$irc
->{nick};
$self
->{irc} =
$irc
;
$irc
->plugin_register(
$self
,
'SERVER'
,
qw(isupport nick notice)
);
return
1;
}
sub
PCI_unregister {
return
1;
}
sub
S_isupport {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
$irc
->yield(
nickserv
=>
"IDENTIFY $self->{Password}"
);
return
PCI_EAT_NONE;
}
sub
S_nick {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$mapping
=
$irc
->isupport(
'CASEMAPPING'
);
my
$new_nick
= uc_irc( ${
$_
[1] },
$mapping
);
if
(
$new_nick
eq uc_irc(
$self
->{nick},
$mapping
) ) {
$irc
->yield(
nickserv
=>
"IDENTIFY $self->{Password}"
);
}
return
PCI_EAT_NONE;
}
sub
S_notice {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$sender
= parse_user(${
$_
[0] });
my
$recipient
= parse_user(${
$_
[1] }->[0]);
my
$msg
= ${
$_
[2] };
return
PCI_EAT_NONE
if
$recipient
ne
$irc
->nick_name();
return
PCI_EAT_NONE
if
$sender
!~ /^nickserv$/i;
return
PCI_EAT_NONE
if
$msg
!~ /now (?:identified|recognized)/;
$irc
->send_event_next(
'irc_identified'
);
return
PCI_EAT_NONE;
}
sub
S_433 {
my
(
$self
,
$irc
) =
splice
@_
, 0, 2;
my
$offending
= ${
$_
[2] }->[0];
my
$reason
= ${
$_
[2] }->[1];
if
(
$irc
->nick_name() eq
$offending
&&
$reason
eq
"Nickname is registered to someone else"
) {
$irc
->yield(
nickserv
=>
"IDENTIFY $self->{Password}"
);
}
return
PCI_EAT_NONE;
}
1;