3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 23:39:24 +01:00

Add permop channel flag; when non-zero bot automatically ops itself when joining channel, otherwise bot ops itself only when needing to perform an op command and then deops itself after its deop timeout has elapsed

This commit is contained in:
Pragmatic Software 2014-12-18 08:46:13 +00:00
parent 598e2e4988
commit a09d3c1d63
5 changed files with 38 additions and 10 deletions

View File

@ -136,8 +136,7 @@ sub join_channel {
foreach my $channel (split /\s+/, $arguments) { foreach my $channel (split /\s+/, $arguments) {
$self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n");
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $channel }); $self->{pbot}->{chanops}->join_channel($channel);
$self->{pbot}->{conn}->join($channel);
} }
return "/msg $nick Joining $arguments"; return "/msg $nick Joining $arguments";
@ -151,8 +150,7 @@ sub part_channel {
foreach my $channel (split /\s+/, $arguments) { foreach my $channel (split /\s+/, $arguments) {
$self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n");
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.part', { channel => $channel }); $self->{pbot}->{chanops}->part_channel($channel);
$self->{pbot}->{conn}->part($channel);
} }
return "/msg $nick Parting $arguments"; return "/msg $nick Parting $arguments";

View File

@ -121,6 +121,32 @@ sub ban_user_timed {
$self->{unban_timeout}->save; $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 { sub check_unban_timeouts {
my $self = shift; my $self = shift;
@ -143,8 +169,12 @@ sub check_opped_timeouts {
foreach my $channel (keys %{ $self->{is_opped} }) { foreach my $channel (keys %{ $self->{is_opped} }) {
if($self->{is_opped}->{$channel}{timeout} < $now) { if($self->{is_opped}->{$channel}{timeout} < $now) {
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); $self->lose_ops($channel);
delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed delete $self->{is_opped}->{$channel}; # assume chanserv is alive and deop will succeed
}
} else { } else {
# my $timediff = $self->{is_opped}->{$channel}{timeout} - $now; # my $timediff = $self->{is_opped}->{$channel}{timeout} - $now;
# $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n"); # $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n");

View File

@ -70,6 +70,7 @@ sub add {
my $hash = {}; my $hash = {};
$hash->{enabled} = 1; $hash->{enabled} = 1;
$hash->{chanop} = 0; $hash->{chanop} = 0;
$hash->{permop} = 0;
return $self->{channels}->add($arguments, $hash); return $self->{channels}->add($arguments, $hash);
} }

View File

@ -132,8 +132,7 @@ sub on_notice {
foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) { foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
if($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) { if($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) {
$self->{pbot}->{logger}->log("Joining channel: $chan\n"); $self->{pbot}->{logger}->log("Joining channel: $chan\n");
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', { channel => $chan }); $self->{pbot}->{chanops}->join_channel($chan);
$event->{conn}->join($chan);
} }
} }
$self->{pbot}->{joined_channels} = 1; $self->{pbot}->{joined_channels} = 1;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 800, BUILD_REVISION => 801,
BUILD_DATE => "2014-11-14", BUILD_DATE => "2014-12-18",
}; };
1; 1;