Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only give +op when one has op privileges

Added a channel state so that it doesn't tick off the server attempting to give
op privileges, when it doesn't yet have them.   However, once it has been give
op privileges, then it will start doing so.

Similarly, if the bot has been deop'd (-o), it will stop attempting to give out
privileges.
  • Loading branch information...
commit bcd3f858bf3698939e0e4c3bd10b802899c0b7cf 1 parent 0f28177
@an0maly an0maly authored
Showing with 44 additions and 6 deletions.
  1. +44 −6 radicalweed.pl
View
50 radicalweed.pl
@@ -8,7 +8,8 @@
use Hash::Util qw/ lock_hash /;
#use DB_File::Lock;
-my %config = read_config();
+my %opstate;
+my %config = read_config();
while( my ($server_addr,$server) = each %{$config{server}} ) {
my @username;
@@ -41,6 +42,12 @@
print "$server_addr: connected to ", $irc->server_name, "\n";
+ for my $channel ( keys %{ $server->{channel} } ) {
+ # flag that we don't have op yet for this channel
+ $opstate{$server_addr}{$channel}{state} = 0;
+
+ }
+
# we join our channels
$irc->yield( join => "#$_" ) for keys %{ $server->{channel} };
},
@@ -52,14 +59,45 @@
my $channel = ref $where ? $where->[0] : $where;
$channel =~ s/^#//;
- # give them op if they are in the (reread) config
- %config = read_config();
- if( exists $config{server}{$server_addr}{channel}{$channel}{ops}{$nick} ) {
- print "$server_addr: Gave op to $nick in #$channel.\n";
- $irc->yield( mode => "#$channel" => '+o' => $nick );
+ # See if we have op privileges before we go gallivanting about
+ # attempting to give +op and ticking off the server
+
+ if( $opstate{$server_addr}{$channel}{state} ) {
+
+ # give them op if they are in the (reread) config
+ %config = read_config();
+ if( exists $config{server}{$server_addr}{channel}{$channel}{ops}{$nick} ) {
+ print "$server_addr: Gave op to $nick in #$channel.\n";
+ $irc->yield( mode => "#$channel" => '+o' => $nick );
+ }
+
}
+
},
+
+ irc_mode => sub {
+ my ( $who, $where, $what, $towhom ) = @_[ ARG0 .. ARG3 ];
+ my $nick = ( split /!/, $who )[0];
+ my $channel = ref $where ? $where->[0] : $where;
+ $channel =~ s/^#//;
+
+ if( defined $towhom && $towhom eq $server->{nick} ) {
+ if( $what eq '+o' ) {
+ # I just received op privileges
+ $opstate{$server_addr}{$channel}{state} = 1;
+
+ }
+ elsif( $what eq '-o' ) {
+ $opstate{$server_addr}{$channel}{state} = 0;
+
+ }
+
+ }
+
+ },
+
+
irc_notice => sub {
my ( $sender, $what, $message ) = @_[ ARG0 .. ARG2 ];
my $i = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.