3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-01-25 19:44:26 +01:00

Add voice and devoice commands

This commit is contained in:
Pragmatic Software 2020-01-11 18:02:00 -08:00
parent 782be369b6
commit 04ed9d3554

View File

@ -49,6 +49,8 @@ sub initialize {
$pbot->{commands}->register(sub { return $self->checkmute(@_) }, "checkmute", 0); $pbot->{commands}->register(sub { return $self->checkmute(@_) }, "checkmute", 0);
$pbot->{commands}->register(sub { return $self->op_user(@_) }, "op", 10); $pbot->{commands}->register(sub { return $self->op_user(@_) }, "op", 10);
$pbot->{commands}->register(sub { return $self->deop_user(@_) }, "deop", 10); $pbot->{commands}->register(sub { return $self->deop_user(@_) }, "deop", 10);
$pbot->{commands}->register(sub { return $self->voice_user(@_) }, "voice", 10);
$pbot->{commands}->register(sub { return $self->devoice_user(@_) }, "devoice", 10);
$pbot->{commands}->register(sub { return $self->mode(@_) }, "mode", 40); $pbot->{commands}->register(sub { return $self->mode(@_) }, "mode", 40);
$pbot->{commands}->register(sub { return $self->invite(@_) }, "invite", 10); $pbot->{commands}->register(sub { return $self->invite(@_) }, "invite", 10);
} }
@ -75,19 +77,20 @@ sub invite {
return ""; return "";
} }
sub op_user { sub generic_mode_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $mode_flag, $mode_name, $channel, $nick, $stuff) = @_;
my $channel = $from;
my $result = ''; my $result = '';
my ($flag, $mode_char) = $mode_flag =~ m/(.)(.)/;
if ($channel !~ m/^#/) { if ($channel !~ m/^#/) {
# from message # from message
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}); $channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
$result = 'Done.'; $result = 'Done.';
if (not defined $channel) { if (not defined $channel) {
return "Usage from message: op <channel> [nick]"; return "Usage from message: $mode_name <channel> [nick]";
} elsif ($channel !~ m/^#/) { } elsif ($channel !~ m/^#/) {
return "$channel is not a channel. Usage from message: op <channel> [nick]"; return "$channel is not a channel. Usage from message: $mode_name <channel> [nick]";
} }
} }
@ -102,21 +105,21 @@ sub op_user {
} }
my $max_modes = $self->{pbot}->{ircd}->{MODES} // 1; my $max_modes = $self->{pbot}->{ircd}->{MODES} // 1;
my $mode = '+'; my $mode = $flag;
my $list = ''; my $list = '';
my $i = 0; my $i = 0;
foreach my $targets ($self->{pbot}->{interpreter}->unquoted_args($stuff->{arglist})) { foreach my $targets ($self->{pbot}->{interpreter}->unquoted_args($stuff->{arglist})) {
foreach my $target (split /,/, $targets) { foreach my $target (split /,/, $targets) {
$mode .= 'o'; $mode .= $mode_char;
$list .= "$target "; $list .= "$target ";
$i++; $i++;
if ($i >= $max_modes) { if ($i >= $max_modes) {
my $args = "$channel $mode $list"; my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args); $stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$self->mode($from, $nick, $user, $host, $args, $stuff); $self->mode($channel, $nick, $stuff->{user}, $stuff->{host}, $args, $stuff);
$mode = '+'; $mode = $flag;
$list = ''; $list = '';
$i = 0; $i = 0;
} }
@ -126,67 +129,31 @@ sub op_user {
if ($i) { if ($i) {
my $args = "$channel $mode $list"; my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args); $stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$self->mode($from, $nick, $user, $host, $args, $stuff); $self->mode($channel, $nick, $stuff->{user}, $stuff->{host}, $args, $stuff);
} }
return $result; return $result;
} }
sub op_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return $self->generic_mode_user('+o', 'op', $from, $nick, $stuff);
}
sub deop_user { sub deop_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $channel = $from; return $self->generic_mode_user('-o', 'deop', $from, $nick, $stuff);
my $result = ''; }
if ($channel !~ m/^#/) { sub voice_user {
# from message my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}); return $self->generic_mode_user('+v', 'voice', $from, $nick, $stuff);
$result = 'Done.'; }
if (not defined $channel) {
return "Usage from message: deop <channel> [nick]";
} elsif ($channel !~ m/^#/) {
return "$channel is not a channel. Usage from message: deop <channel> [nick]";
}
}
$channel = lc $channel; sub devoice_user {
if (not $self->{pbot}->{chanops}->can_gain_ops($channel)) { my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return "I am not configured as an OP for $channel. See `chanset` command for more information."; return $self->generic_mode_user('-v', 'devoice', $from, $nick, $stuff);
}
# add $nick to $args if no argument
if (not $self->{pbot}->{interpreter}->arglist_size($stuff->{arglist})) {
$self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $nick);
}
my $max_modes = $self->{pbot}->{ircd}->{MODES} // 1;
my $mode = '-';
my $list = '';
my $i = 0;
foreach my $targets ($self->{pbot}->{interpreter}->unquoted_args($stuff->{arglist})) {
foreach my $target (split /,/, $targets) {
$mode .= 'o';
$list .= "$target ";
$i++;
if ($i >= $max_modes) {
my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$self->mode($from, $nick, $user, $host, $args, $stuff);
$mode = '-';
$list = '';
$i = 0;
}
}
}
if ($i) {
my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$self->mode($from, $nick, $user, $host, $args, $stuff);
}
return $result;
} }
sub mode { sub mode {