From 9376c65b24c2c2258e8654710f224917aea96e7b Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 9 Jul 2015 23:25:31 -0700 Subject: [PATCH] Allow optionally using name instead of hostmask in adminset/adminunset/adminrem commands --- PBot/BotAdminCommands.pm | 58 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/PBot/BotAdminCommands.pm b/PBot/BotAdminCommands.pm index 3da203eb..d5540fd1 100644 --- a/PBot/BotAdminCommands.pm +++ b/PBot/BotAdminCommands.pm @@ -81,9 +81,11 @@ sub adminadd { if(not defined $name or not defined $channel or not defined $hostmask or not defined $level or not defined $password) { - return "/msg $nick Usage: adminadd name channel hostmask level password"; + return "/msg $nick Usage: adminadd "; } + $channel = '.*' if lc $channel eq 'global'; + $self->{pbot}->{admins}->add_admin($name, $channel, $hostmask, $level, $password); return "Admin added."; } @@ -95,7 +97,23 @@ sub adminrem { my ($channel, $hostmask) = split / /, $arguments, 2; if(not defined $channel or not defined $hostmask) { - return "/msg $nick Usage: adminrem channel hostmask"; + return "/msg $nick Usage: adminrem "; + } + + $channel = lc $channel; + $hostmask = lc $hostmask; + + $channel = '.*' if $channel eq 'global'; + + if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) { + foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) { + $hostmask = $mask; + last; + } + } + } } if($self->{pbot}->{admins}->remove_admin($channel, $hostmask)) { @@ -111,7 +129,23 @@ sub adminset { my ($channel, $hostmask, $key, $value) = split / /, $arguments, 4 if defined $arguments; if(not defined $channel or not defined $hostmask) { - return "Usage: adminset "; + return "Usage: adminset "; + } + + $channel = lc $channel; + $hostmask = lc $hostmask; + + $channel = '.*' if $channel eq 'global'; + + if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) { + foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) { + $hostmask = $mask; + last; + } + } + } } return $self->{pbot}->{admins}->{admins}->set($channel, $hostmask, $key, $value); @@ -123,7 +157,23 @@ sub adminunset { my ($channel, $hostmask, $key) = split / /, $arguments, 3 if defined $arguments; if(not defined $channel or not defined $hostmask) { - return "Usage: adminunset "; + return "Usage: adminunset "; + } + + $channel = lc $channel; + $hostmask = lc $hostmask; + + $channel = '.*' if $channel eq 'global'; + + if (exists $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if (not exists $self->{pbot}->{admins}->{admins}->hash->{$channel}->{$hostmask}) { + foreach my $mask (keys $self->{pbot}->{admins}->{admins}->hash->{$channel}) { + if ($self->{pbot}->{admins}->{admins}->hash->{$channel}->{$mask}->{name} eq $hostmask) { + $hostmask = $mask; + last; + } + } + } } return $self->{pbot}->{admins}->{admins}->unset($channel, $hostmask, $key);