| 1 | package POE::Component::IRC::Plugin::CycleEmpty; | ||||||||||
| 2 | 3 | $POE::Component::IRC::Plugin::CycleEmpty::VERSION = '6.95'; | |||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use IRC::Utils qw( parse_user uc_irc ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 10 | 2 | my ($package) = shift; | |||||||||
| 11 | 2 | ▶ | croak "$package requires an even number of arguments" if @_ & 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 2 | my %self = @_; | |||||||||
| 13 | 2 | return bless \%self, $package; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub PCI_register { | ||||||||
|
Subroutine
PCI_register: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 17 | 2 | my ($self, $irc) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | if (!$irc->isa('POE::Component::IRC::State')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | die __PACKAGE__ . " requires PoCo::IRC::State or a subclass thereof"; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 2 | $self->{cycling} = { }; | |||||||||
| 24 | 2 | $self->{irc} = $irc; | |||||||||
| 25 | 2 | $irc->plugin_register($self, 'SERVER', qw(join kick part quit)); | |||||||||
| 26 | 2 | return 1; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 2 | ▶ | sub PCI_unregister { | ||||||||
|
Subroutine
PCI_unregister: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 2 | return 1; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 2 | ▶ | sub S_join { | ||||||||
|
Subroutine
S_join: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 2 | my ($self, $irc) = splice @_, 0, 2; | |||||||||
| 35 | 2 | my $chan = ${ $_[1] }; | |||||||||
| 36 | 2 | delete $self->{cycling}->{$chan}; | |||||||||
| 37 | 2 | return PCI_EAT_NONE; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub S_kick { | ||||||||
|
Subroutine
S_kick: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 41 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||
| 42 | 0 | my $chan = ${ $_[1] }; | |||||||||
| 43 | 0 | my $victim = ${ $_[2] }; | |||||||||
| 44 | 0 | ▶ | $self->_cycle($chan) if $victim ne $irc->nick_name(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | return PCI_EAT_NONE; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | sub S_part { | ||||||||
|
Subroutine
S_part: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 49 | 2 | my ($self, $irc) = splice @_, 0, 2; | |||||||||
| 50 | 2 | my $parter = parse_user(${ $_[0] }); | |||||||||
| 51 | 2 | my $chan = ${ $_[1] }; | |||||||||
| 52 | 2 | ▶ | $self->_cycle($chan) if $parter ne $irc->nick_name(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 2 | return PCI_EAT_NONE; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub S_quit { | ||||||||
|
Subroutine
S_quit: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 57 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||
| 58 | 0 | my $quitter = parse_user(${ $_[0] }); | |||||||||
| 59 | 0 | my $channels = @{ $_[2] }[0]; | |||||||||
| 60 | 0 | ▶ | if ($quitter ne $irc->nick_name()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | for my $chan (@{ $channels }) { | |||||||||
| 62 | 0 | $self->_cycle($chan); | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | 0 | return PCI_EAT_NONE; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | ▶ | sub _cycle { | ||||||||
|
Subroutine
_cycle: called CC=5 SCAR=16.6
| |||||||||||
| 69 | 1 | my ($self, $chan) = @_; | |||||||||
| 70 | 1 | my $irc = $self->{irc}; | |||||||||
| 71 | 1 | ▶ | if ($irc->channel_list($chan) == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 1 | ▶ | if (!$irc->is_channel_operator($chan, $irc->nick_name)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 1 | $self->{cycling}->{ uc_irc($chan) } = 1; | |||||||||
| 74 | 1 | my $topic = $irc->channel_topic($chan); | |||||||||
| 75 | 1 | $irc->yield(part => $chan); | |||||||||
| 76 | 1 | $irc->yield(join => $chan => $irc->channel_key($chan)); | |||||||||
| 77 | 1 | ▶ | $irc->yield(topic => $chan => $topic->{Value}) if defined $topic->{Value}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 1 | ▶ | $irc->yield(mode => $chan => '+k ' . $irc->channel_key($chan)) if defined $irc->channel_key($chan); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | } | ||||||||||
| 81 | 1 | return; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 1 | ▶ | sub is_cycling { | ||||||||
|
Subroutine
is_cycling: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||
| 85 | 1 | my ($self, $value) = @_; | |||||||||
| 86 | 1 | ▶ | return 1 if $self->{cycling}->{ uc_irc($value) }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 3 | 1; | |||||||||
| 91 | |||||||||||
| 92 | =encoding utf8 | ||||||||||
| 93 | |||||||||||
| 94 | =head1 NAME | ||||||||||
| 95 | |||||||||||
| 96 | POE::Component::IRC::Plugin::CycleEmpty - A PoCo-IRC plugin which cycles | ||||||||||
| 97 | channels if they become empty and opless. | ||||||||||
| 98 | |||||||||||
| 99 | =head1 SYNOPSIS | ||||||||||
| 100 | |||||||||||
| 101 | use POE::Component::IRC::Plugin::CycleEmpty; | ||||||||||
| 102 | |||||||||||
| 103 | $irc->plugin_add('CycleEmpty', POE::Component::IRC::Plugin::CycleEmpty->new()); | ||||||||||
| 104 | |||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||
| 106 | |||||||||||
| 107 | POE::Component::IRC::Plugin::CycleEmpty is a L<POE::Component::IRC|POE::Component::IRC> | ||||||||||
| 108 | plugin. When a channel member quits, gets kicked, or parts, the plugin will | ||||||||||
| 109 | cycle the channel if the IRC component is alone on that channel and is not | ||||||||||
| 110 | a channel operator. If there was a topic or a key set on the channel, they | ||||||||||
| 111 | will be restored upon rejoining. | ||||||||||
| 112 | |||||||||||
| 113 | This is useful for regaining ops in small channels if the IRC network does | ||||||||||
| 114 | not have ChanServ or IRCNet's +R channel mode. | ||||||||||
| 115 | |||||||||||
| 116 | This plugin requires the IRC component to be | ||||||||||
| 117 | L<POE::Component::IRC::State|POE::Component::IRC::State> or a subclass thereof. | ||||||||||
| 118 | |||||||||||
| 119 | =head1 METHODS | ||||||||||
| 120 | |||||||||||
| 121 | =head2 C<new> | ||||||||||
| 122 | |||||||||||
| 123 | Returns a plugin object suitable for feeding to | ||||||||||
| 124 | L<POE::Component::IRC|POE::Component::IRC>'s C<plugin_add> method. | ||||||||||
| 125 | |||||||||||
| 126 | =head2 C<is_cycling> | ||||||||||
| 127 | |||||||||||
| 128 | One argument: | ||||||||||
| 129 | |||||||||||
| 130 | A channel name | ||||||||||
| 131 | |||||||||||
| 132 | Returns 1 if the plugin is currently cycling that channel, 0 otherwise. | ||||||||||
| 133 | Useful if need to ignore the fact that the Component just parted the channel | ||||||||||
| 134 | in question. | ||||||||||
| 135 | |||||||||||
| 136 | =head1 AUTHOR | ||||||||||
| 137 | |||||||||||
| 138 | Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com | ||||||||||
| 139 | |||||||||||
| 140 | =cut | ||||||||||