mirror of
https://github.com/pragma-/pbot.git
synced 2025-10-11 13:37:25 +02:00
Add as
command to execute admin commands as a specific admin
This commit is contained in:
parent
08edb697c1
commit
0163d36360
@ -41,6 +41,7 @@ sub initialize {
|
|||||||
|
|
||||||
$pbot->{commands}->register(sub { return $self->login(@_) }, "login", 0);
|
$pbot->{commands}->register(sub { return $self->login(@_) }, "login", 0);
|
||||||
$pbot->{commands}->register(sub { return $self->logout(@_) }, "logout", 0);
|
$pbot->{commands}->register(sub { return $self->logout(@_) }, "logout", 0);
|
||||||
|
$pbot->{commands}->register(sub { return $self->as_admin(@_) }, "as", 0);
|
||||||
$pbot->{commands}->register(sub { return $self->join_channel(@_) }, "join", 40);
|
$pbot->{commands}->register(sub { return $self->join_channel(@_) }, "join", 40);
|
||||||
$pbot->{commands}->register(sub { return $self->part_channel(@_) }, "part", 40);
|
$pbot->{commands}->register(sub { return $self->part_channel(@_) }, "part", 40);
|
||||||
$pbot->{commands}->register(sub { return $self->ack_die(@_) }, "die", 90);
|
$pbot->{commands}->register(sub { return $self->ack_die(@_) }, "die", 90);
|
||||||
@ -62,6 +63,23 @@ sub sl {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub as_admin {
|
||||||
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
|
my $usage = "Usage: as <channel> <command>";
|
||||||
|
|
||||||
|
if (not $arguments) {
|
||||||
|
return $usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($channel, $command) = split / /, $arguments, 2;
|
||||||
|
return $usage if not defined $channel or not defined $command;
|
||||||
|
|
||||||
|
$stuff->{as_admin} = $channel;
|
||||||
|
$stuff->{command} = $command;
|
||||||
|
return $self->{pbot}->{interpreter}->interpret($stuff);
|
||||||
|
}
|
||||||
|
|
||||||
sub login {
|
sub login {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
|
@ -154,11 +154,7 @@ sub find_admin {
|
|||||||
|
|
||||||
my $result = eval {
|
my $result = eval {
|
||||||
foreach my $channel_regex (keys %{ $self->{admins}->hash }) {
|
foreach my $channel_regex (keys %{ $self->{admins}->hash }) {
|
||||||
if($from !~ m/^#/) {
|
if ($from =~ m/^$channel_regex$/i) {
|
||||||
foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) {
|
|
||||||
return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/$hostmask_regex/i or $hostmask eq lc $hostmask_regex;
|
|
||||||
}
|
|
||||||
} elsif($from =~ m/^$channel_regex$/i) {
|
|
||||||
foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) {
|
foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) {
|
||||||
return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/$hostmask_regex/i or $hostmask eq lc $hostmask_regex;
|
return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/$hostmask_regex/i or $hostmask eq lc $hostmask_regex;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ sub initialize {
|
|||||||
|
|
||||||
sub ban_user {
|
sub ban_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
||||||
|
|
||||||
$channel = '' if not defined $channel;
|
$channel = '' if not defined $channel;
|
||||||
@ -62,10 +62,10 @@ sub ban_user {
|
|||||||
if ($channel !~ m/^#/) {
|
if ($channel !~ m/^#/) {
|
||||||
$length = "$channel $length";
|
$length = "$channel $length";
|
||||||
$length = undef if $length eq ' ';
|
$length = undef if $length eq ' ';
|
||||||
$channel = $from;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from;
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel = $from if not defined $channel or not length $channel;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from if not defined $channel or not length $channel;
|
||||||
|
|
||||||
if (not defined $target) {
|
if (not defined $target) {
|
||||||
return "/msg $nick Usage: ban <mask> [channel [timeout (default: 24 hours)]]";
|
return "/msg $nick Usage: ban <mask> [channel [timeout (default: 24 hours)]]";
|
||||||
@ -99,7 +99,7 @@ sub ban_user {
|
|||||||
|
|
||||||
sub unban_user {
|
sub unban_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
if (not defined $from) {
|
if (not defined $from) {
|
||||||
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
||||||
@ -112,7 +112,7 @@ sub unban_user {
|
|||||||
return "/msg $nick Usage: unban <mask> [[channel] [true value to use unban queue]]";
|
return "/msg $nick Usage: unban <mask> [[channel] [true value to use unban queue]]";
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel = $from if not defined $channel;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from if not defined $channel;
|
||||||
$immediately = 1 if not defined $immediately;
|
$immediately = 1 if not defined $immediately;
|
||||||
|
|
||||||
return "/msg $nick Usage for /msg: unban <nick/mask> <channel> [true value to use unban queue]" if $channel !~ /^#/;
|
return "/msg $nick Usage for /msg: unban <nick/mask> <channel> [true value to use unban queue]" if $channel !~ /^#/;
|
||||||
@ -133,7 +133,7 @@ sub unban_user {
|
|||||||
|
|
||||||
sub mute_user {
|
sub mute_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
||||||
|
|
||||||
if (not defined $from) {
|
if (not defined $from) {
|
||||||
@ -148,10 +148,10 @@ sub mute_user {
|
|||||||
if ($channel !~ m/^#/) {
|
if ($channel !~ m/^#/) {
|
||||||
$length = "$channel $length";
|
$length = "$channel $length";
|
||||||
$length = undef if $length eq ' ';
|
$length = undef if $length eq ' ';
|
||||||
$channel = $from;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from;
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel = $from if not defined $channel;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from if not defined $channel;
|
||||||
|
|
||||||
if ($channel !~ m/^#/) {
|
if ($channel !~ m/^#/) {
|
||||||
return "/msg $nick Please specify a channel.";
|
return "/msg $nick Please specify a channel.";
|
||||||
@ -189,7 +189,7 @@ sub mute_user {
|
|||||||
|
|
||||||
sub unmute_user {
|
sub unmute_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
if (not defined $from) {
|
if (not defined $from) {
|
||||||
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
||||||
@ -202,7 +202,7 @@ sub unmute_user {
|
|||||||
return "/msg $nick Usage: unmute <mask> [channel]";
|
return "/msg $nick Usage: unmute <mask> [channel]";
|
||||||
}
|
}
|
||||||
|
|
||||||
$channel = $from if not defined $channel;
|
$channel = exists $stuff->{as_admin} ? $stuff->{as_admin} : $from if not defined $channel;
|
||||||
|
|
||||||
return "/msg $nick Usage for /msg: unmute <mask> <channel>" if $channel !~ /^#/;
|
return "/msg $nick Usage for /msg: unmute <mask> <channel>" if $channel !~ /^#/;
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ sub unmute_user {
|
|||||||
|
|
||||||
sub kick_user {
|
sub kick_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
if (not defined $from) {
|
if (not defined $from) {
|
||||||
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
|
||||||
@ -236,7 +236,7 @@ sub kick_user {
|
|||||||
if ($arguments =~ s/^(#\S+)\s+(\S+)\s*//) {
|
if ($arguments =~ s/^(#\S+)\s+(\S+)\s*//) {
|
||||||
($channel, $victim) = ($1, $2);
|
($channel, $victim) = ($1, $2);
|
||||||
} elsif ($arguments =~ s/^(\S+)\s*//) {
|
} elsif ($arguments =~ s/^(\S+)\s*//) {
|
||||||
($victim, $channel) = ($1, $from);
|
($victim, $channel) = ($1, exists $stuff->{as_admin} ? $stuff->{as_admin} : $from);
|
||||||
} else {
|
} else {
|
||||||
return "/msg $nick Usage: kick [channel] <nick> [reason]";
|
return "/msg $nick Usage: kick [channel] <nick> [reason]";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user