/usr/share/perl5/POE/Component/IRC/Plugin/NickReclaim.pm is in libpoe-component-irc-perl 6.83+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | package POE::Component::IRC::Plugin::NickReclaim;
BEGIN {
$POE::Component::IRC::Plugin::NickReclaim::AUTHORITY = 'cpan:HINRIK';
}
{
$POE::Component::IRC::Plugin::NickReclaim::VERSION = '6.83';
}
use strict;
use warnings FATAL => 'all';
use Carp;
use IRC::Utils qw(parse_user);
use POE::Component::IRC::Plugin qw(PCI_EAT_NONE);
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;
}
# ERR_NICKNAMEINUSE
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;
=encoding utf8
=head1 NAME
POE::Component::IRC::Plugin::NickReclaim - A PoCo-IRC plugin for reclaiming
your nickname
=head1 SYNOPSIS
use strict;
use warnings;
use POE qw(Component::IRC Component::IRC::Plugin::NickReclaim);
my $nickname = 'Flibble' . $$;
my $ircname = 'Flibble the Sailor Bot';
my $ircserver = 'irc.blahblahblah.irc';
my $port = 6667;
my $irc = POE::Component::IRC->spawn(
nick => $nickname,
server => $ircserver,
port => $port,
ircname => $ircname,
) or die "Oh noooo! $!";
POE::Session->create(
package_states => [
main => [ qw(_start) ],
],
);
$poe_kernel->run();
sub _start {
$irc->yield( register => 'all' );
# Create and load our NickReclaim plugin, before we connect
$irc->plugin_add( 'NickReclaim' =>
POE::Component::IRC::Plugin::NickReclaim->new( poll => 30 ) );
$irc->yield( connect => { } );
return;
}
=head1 DESCRIPTION
POE::Component::IRC::Plugin::NickReclaim - A
L<POE::Component::IRC|POE::Component::IRC> plugin automagically deals with
your bot's nickname being in use and reclaims it when it becomes available
again.
It registers and handles 'irc_433' events. On receiving a 433 event it will
reset the nickname to the 'nick' specified with C<spawn> or C<connect>,
appendedwith an underscore, and then poll to try and change it to the
original nickname. If someone in your channel who has the nickname you're
after quits or changes nickname, the plugin will try to reclaim it
immediately.
=head1 METHODS
=head2 C<new>
Takes one optional argument:
B<'poll'>, the number of seconds between nick change attempts, default is 30;
Returns a plugin object suitable for feeding to
L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method.
=head1 AUTHOR
Chris 'BinGOs' Williams
With amendments applied by Zoffix Znet
=head1 SEE ALSO
L<POE::Component::IRC|POE::Component::IRC>
=cut
|