From ebf5206ff61379370374adb5629c456ad5923b76 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 14 Jan 2020 18:55:20 -0800 Subject: [PATCH] ChanOpCommands: `invite` now behaves more like ChanServ when used from /msg --- PBot/ChanOpCommands.pm | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index e640d6fb..e4a1ded7 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -58,20 +58,37 @@ sub initialize { sub invite { my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_; - if (not length $arguments) { - return "Usage: invite [channel] "; - } + my ($channel, $target); - # add current channel as default channel - if ($stuff->{arglist}[0] !~ m/^#/) { - if ($from =~ m/^#/) { - $self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $from); - } else { - return "Usage from private message: invite "; + if ($from !~ m/^#/) { + # from /msg + if (not length $arguments) { + return "Usage from /msg: invite [nick]; if you omit [nick] then you will be invited"; } + + ($channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); + + if ($channel !~ m/^#/) { + return "$channel is not a channel; usage from /msg: invite [nick]; if you omit [nick] then you will be invited"; + } + + if (not defined $target) { + $target = $nick; + } + } else { + # in channel + if (not length $arguments) { + return "Usage: invite [channel] "; + } + + # add current channel as default channel + if ($stuff->{arglist}[0] !~ m/^#/) { + $self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $from); + } + + ($channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); } - my ($channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2); $self->{pbot}->{chanops}->add_op_command($channel, "sl invite $target $channel"); $self->{pbot}->{chanops}->gain_ops($channel); return "";