1package POE::Component::IRC::Plugin::NickServID; 2our $AUTHORITY = 'cpan:HINRIK'; 3$POE::Component::IRC::Plugin::NickServID::VERSION = '6.93'; 4use strict; 5use warnings FATAL => 'all'; 6use Carp; 7use IRC::Utils qw( uc_irc parse_user ); 8use POE::Component::IRC::Plugin qw( :ALL ); 9 10sub new { 11 my ($package) = shift; 12 croak "$package requires an even number of arguments" if @_ & 1; 13 my %self = @_; 14 15 die "$package requires a Password" if !defined $self{Password}; 16 return bless \%self, $package; 17} 18 19sub PCI_register { 20 my ($self, $irc) = @_; 21 $self->{nick} = $irc->{nick}; 22 $self->{irc} = $irc; 23 $irc->plugin_register($self, 'SERVER', qw(isupport nick notice)); 24 return 1; 25} 26 27sub PCI_unregister { 28 return 1; 29} 30 31# we identify after S_isupport so that pocoirc has a chance to turn on 32# CAPAB IDENTIFY-MSG (if the server supports it) before the AutoJoin 33# plugin joins channels 34sub S_isupport { 35 my ($self, $irc) = splice @_, 0, 2; 36 $irc->yield(nickserv => "IDENTIFY $self->{Password}"); 37 return PCI_EAT_NONE; 38} 39 40sub S_nick { 41 my ($self, $irc) = splice @_, 0, 2; 42 my $mapping = $irc->isupport('CASEMAPPING'); 43 my $new_nick = uc_irc( ${ $_[1] }, $mapping ); 44 45 if ( $new_nick eq uc_irc($self->{nick}, $mapping) ) { 46 $irc->yield(nickserv => "IDENTIFY $self->{Password}"); 47 } 48 return PCI_EAT_NONE; 49} 50 51sub S_notice { 52 my ($self, $irc) = splice @_, 0, 2; 53 my $sender = parse_user(${ $_[0] }); 54 my $recipient = parse_user(${ $_[1] }->[0]); 55 my $msg = ${ $_[2] }; 56 57 return PCI_EAT_NONE if $recipient ne $irc->nick_name(); 58 return PCI_EAT_NONE if $sender !~ /^nickserv$/i; 59 return PCI_EAT_NONE if $msg !~ /now (?:identified|recognized)/; 60 $irc->send_event_next('irc_identified'); 61 return PCI_EAT_NONE; 62} 63 64# ERR_NICKNAMEINUSE 65sub S_433 { 66 my ($self, $irc) = splice @_, 0, 2; 67 my $offending = ${ $_[2] }->[0]; 68 my $reason = ${ $_[2] }->[1]; 69 70 if ($irc->nick_name() eq $offending && $reason eq "Nickname is registered to someone else") { 71 $irc->yield(nickserv => "IDENTIFY $self->{Password}"); 72 } 73 74 return PCI_EAT_NONE; 75} 761; 77 78=encoding utf8 79 80=head1 NAME 81 82POE::Component::IRC::Plugin::NickServID - A PoCo-IRC plugin which identifies with NickServ when needed 83 84=head1 SYNOPSIS 85 86 use POE::Component::IRC::Plugin::NickServID; 87 88 $irc->plugin_add( 'NickServID', POE::Component::IRC::Plugin::NickServID->new( 89 Password => 'opensesame' 90 )); 91 92=head1 DESCRIPTION 93 94POE::Component::IRC::Plugin::NickServID is a L<POE::Component::IRC|POE::Component::IRC> 95plugin. It identifies with NickServ on connect and when you change your nick, 96if your nickname matches the supplied password. 97 98B<Note>: If you have a cloak and you don't want to be seen without it, make sure 99you don't join channels until after you've identified yourself. If you use the 100L<AutoJoin plugin|POE::Component::IRC::Plugin::AutoJoin>, it will be taken 101care of for you. 102 103=head1 METHODS 104 105=head2 C<new> 106 107Arguments: 108 109'Password', the NickServ password. 110 111Returns a plugin object suitable for feeding to 112L<POE::Component::IRC|POE::Component::IRC>'s plugin_add() method. 113 114=head1 OUTPUT EVENTS 115 116=head2 C<irc_identified> 117 118This event will be sent when you have identified with NickServ. No arguments 119are passed with it. 120 121=head1 AUTHOR 122 123Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com 124 125=cut 126