diff --git a/PBot/BotAdminCommands.pm b/PBot/BotAdminCommands.pm index 71dd89ed..3da203eb 100644 --- a/PBot/BotAdminCommands.pm +++ b/PBot/BotAdminCommands.pm @@ -136,8 +136,7 @@ sub join_channel { foreach my $channel (split /\s+/, $arguments) { $self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n"); - $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $channel }); - $self->{pbot}->{conn}->join($channel); + $self->{pbot}->{chanops}->join_channel($channel); } return "/msg $nick Joining $arguments"; @@ -151,8 +150,7 @@ sub part_channel { foreach my $channel (split /\s+/, $arguments) { $self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n"); - $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.part', { channel => $channel }); - $self->{pbot}->{conn}->part($channel); + $self->{pbot}->{chanops}->part_channel($channel); } return "/msg $nick Parting $arguments"; diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index 8092df49..48f08421 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -121,6 +121,32 @@ sub ban_user_timed { $self->{unban_timeout}->save; } +sub join_channel { + my ($self, $channel) = @_; + + $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $channel }); + $self->{pbot}->{conn}->join($channel); + + delete $self->{is_opped}->{$channel}; + delete $self->{op_requested}->{$channel}; + + if (exists $self->{pbot}->{channels}->{channels}->hash->{$channel} + and exists $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop} + and $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop}) { + $self->gain_ops($channel); + } +} + +sub part_channel { + my ($self, $channel) = @_; + + $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.part', { channel => $channel }); + $self->{pbot}->{conn}->part($channel); + + delete $self->{is_opped}->{$channel}; + delete $self->{op_requested}->{$channel}; +} + sub check_unban_timeouts { my $self = shift; @@ -143,8 +169,12 @@ sub check_opped_timeouts { foreach my $channel (keys %{ $self->{is_opped} }) { if($self->{is_opped}->{$channel}{timeout} < $now) { - $self->lose_ops($channel); - delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed + unless (exists $self->{pbot}->{channels}->{channels}->hash->{$channel} + and exists $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop} + and $self->{pbot}->{channels}->{channels}->hash->{$channel}{permop}) { + $self->lose_ops($channel); + delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed + } } else { # my $timediff = $self->{is_opped}->{$channel}{timeout} - $now; # $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n"); diff --git a/PBot/Channels.pm b/PBot/Channels.pm index ce73ee43..053e578b 100644 --- a/PBot/Channels.pm +++ b/PBot/Channels.pm @@ -70,6 +70,7 @@ sub add { my $hash = {}; $hash->{enabled} = 1; $hash->{chanop} = 0; + $hash->{permop} = 0; return $self->{channels}->add($arguments, $hash); } diff --git a/PBot/IRCHandlers.pm b/PBot/IRCHandlers.pm index 5cd6d0db..90bac6a5 100644 --- a/PBot/IRCHandlers.pm +++ b/PBot/IRCHandlers.pm @@ -132,8 +132,7 @@ sub on_notice { foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) { if($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) { $self->{pbot}->{logger}->log("Joining channel: $chan\n"); - $self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $chan }); - $event->{conn}->join($chan); + $self->{pbot}->{chanops}->join_channel($chan); } } $self->{pbot}->{joined_channels} = 1; diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 182dad5f..a4f0afc1 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 800, - BUILD_DATE => "2014-11-14", + BUILD_REVISION => 801, + BUILD_DATE => "2014-12-18", }; 1;