3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

Allow optionally using name instead of hostmask in adminset/adminunset/adminrem commands

This commit is contained in:
Pragmatic Software 2015-07-09 23:25:31 -07:00
parent e3eb698f27
commit 9376c65b24

View File

@ -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 <name> <channel> <hostmask> <level> <password>";
}
$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> <hostmask/name>";
}
$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 <channel> <hostmask> <key> <value>";
return "Usage: adminset <channel> <hostmask/name> <key> <value>";
}
$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 <channel> <hostmask> <key>";
return "Usage: adminunset <channel> <hostmask/name> <key>";
}
$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);