mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 20:42:38 +01:00
Update all commands to understand quoted arguments; factoid names, etc, can now contain spaces
This commit is contained in:
parent
bbe817cd28
commit
174de2be8e
@ -126,10 +126,12 @@ sub whitelisted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub whitelist {
|
sub whitelist {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
$arguments = lc $arguments;
|
|
||||||
|
|
||||||
my ($command, $args) = split /\s+/, $arguments, 2;
|
my $arglist = $stuff->{arglist};
|
||||||
|
$self->{pbot}->{interpreter}->lc_args($arglist);
|
||||||
|
|
||||||
|
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);
|
||||||
|
|
||||||
return "Usage: whitelist <command>, where commands are: list/show, add, remove, set, unset" if not defined $command;
|
return "Usage: whitelist <command>, where commands are: list/show, add, remove, set, unset" if not defined $command;
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ sub whitelist {
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
when ("set") {
|
when ("set") {
|
||||||
my ($channel, $mask, $flag, $value) = split /\s+/, $args, 4;
|
my ($channel, $mask, $flag, $value) = $self->{pbot}->{interpreter}->split_args($arglist, 4);
|
||||||
return "Usage: whitelist set <channel> <mask> [flag] [value]" if not defined $channel or not defined $mask;
|
return "Usage: whitelist set <channel> <mask> [flag] [value]" if not defined $channel or not defined $mask;
|
||||||
|
|
||||||
if (not exists $self->{whitelist}->hash->{$channel}) {
|
if (not exists $self->{whitelist}->hash->{$channel}) {
|
||||||
@ -194,7 +196,7 @@ sub whitelist {
|
|||||||
return "Flag set.";
|
return "Flag set.";
|
||||||
}
|
}
|
||||||
when ("unset") {
|
when ("unset") {
|
||||||
my ($channel, $mask, $flag) = split /\s+/, $args, 3;
|
my ($channel, $mask, $flag) = $self->{pbot}->{interpreter}->split_args($arglist, 3);
|
||||||
return "Usage: whitelist unset <channel> <mask> <flag>" if not defined $channel or not defined $mask or not defined $flag;
|
return "Usage: whitelist unset <channel> <mask> <flag>" if not defined $channel or not defined $mask or not defined $flag;
|
||||||
|
|
||||||
if (not exists $self->{whitelist}->hash->{$channel}) {
|
if (not exists $self->{whitelist}->hash->{$channel}) {
|
||||||
@ -214,7 +216,7 @@ sub whitelist {
|
|||||||
return "Flag unset.";
|
return "Flag unset.";
|
||||||
}
|
}
|
||||||
when ("add") {
|
when ("add") {
|
||||||
my ($channel, $mask, $mode) = split /\s+/, $args, 3;
|
my ($channel, $mask, $mode) = $self->{pbot}->{interpreter}->split_args($arglist, 3);
|
||||||
return "Usage: whitelist add <channel> <mask> [mode (user or ban, default: user)]" if not defined $channel or not defined $mask;
|
return "Usage: whitelist add <channel> <mask> [mode (user or ban, default: user)]" if not defined $channel or not defined $mask;
|
||||||
|
|
||||||
$mode = 'user' if not defined $mode;
|
$mode = 'user' if not defined $mode;
|
||||||
@ -231,7 +233,7 @@ sub whitelist {
|
|||||||
return "/say $mask whitelisted in channel $channel";
|
return "/say $mask whitelisted in channel $channel";
|
||||||
}
|
}
|
||||||
when ("remove") {
|
when ("remove") {
|
||||||
my ($channel, $mask) = split /\s+/, $args, 2;
|
my ($channel, $mask) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
return "Usage: whitelist remove <channel> <mask>" if not defined $channel or not defined $mask;
|
return "Usage: whitelist remove <channel> <mask>" if not defined $channel or not defined $mask;
|
||||||
|
|
||||||
if(not defined $self->{whitelist}->hash->{$channel}) {
|
if(not defined $self->{whitelist}->hash->{$channel}) {
|
||||||
|
@ -70,9 +70,9 @@ sub is_spam {
|
|||||||
sub antispam_cmd {
|
sub antispam_cmd {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
my @pargs = @{$stuff->{argumentspos}};
|
my $arglist = $stuff->{arglist};
|
||||||
|
|
||||||
my $command = shift @pargs;
|
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);
|
||||||
|
|
||||||
return "Usage: antispam <command>, where commands are: list/show, add, remove, set, unset" if not defined $command;
|
return "Usage: antispam <command>, where commands are: list/show, add, remove, set, unset" if not defined $command;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ sub antispam_cmd {
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
when ("set") {
|
when ("set") {
|
||||||
my ($namespace, $keyword, $flag, $value) = $self->{pbot}->{interpreter}->split_args(\@pargs, 4);
|
my ($namespace, $keyword, $flag, $value) = $self->{pbot}->{interpreter}->split_args($arglist, 4);
|
||||||
return "Usage: antispam set <namespace> <regex> [flag] [value]" if not defined $namespace or not defined $keyword;
|
return "Usage: antispam set <namespace> <regex> [flag] [value]" if not defined $namespace or not defined $keyword;
|
||||||
|
|
||||||
if (not exists $self->{keywords}->hash->{$namespace}) {
|
if (not exists $self->{keywords}->hash->{$namespace}) {
|
||||||
@ -132,7 +132,7 @@ sub antispam_cmd {
|
|||||||
return "Flag set.";
|
return "Flag set.";
|
||||||
}
|
}
|
||||||
when ("unset") {
|
when ("unset") {
|
||||||
my ($namespace, $keyword, $flag) = $self->{pbot}->{interpreter}->split_args(\@pargs, 3);
|
my ($namespace, $keyword, $flag) = $self->{pbot}->{interpreter}->split_args($arglist, 3);
|
||||||
return "Usage: antispam unset <namespace> <regex> <flag>" if not defined $namespace or not defined $keyword or not defined $flag;
|
return "Usage: antispam unset <namespace> <regex> <flag>" if not defined $namespace or not defined $keyword or not defined $flag;
|
||||||
|
|
||||||
if (not exists $self->{keywords}->hash->{$namespace}) {
|
if (not exists $self->{keywords}->hash->{$namespace}) {
|
||||||
@ -152,7 +152,7 @@ sub antispam_cmd {
|
|||||||
return "Flag unset.";
|
return "Flag unset.";
|
||||||
}
|
}
|
||||||
when ("add") {
|
when ("add") {
|
||||||
my ($namespace, $keyword) = $self->{pbot}->{interpreter}->split_args(\@pargs, 2);
|
my ($namespace, $keyword) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
return "Usage: antispam add <namespace> <regex>" if not defined $namespace or not defined $keyword;
|
return "Usage: antispam add <namespace> <regex>" if not defined $namespace or not defined $keyword;
|
||||||
$self->{keywords}->hash->{$namespace}->{$keyword}->{owner} = "$nick!$user\@$host";
|
$self->{keywords}->hash->{$namespace}->{$keyword}->{owner} = "$nick!$user\@$host";
|
||||||
$self->{keywords}->hash->{$namespace}->{$keyword}->{created_on} = gettimeofday;
|
$self->{keywords}->hash->{$namespace}->{$keyword}->{created_on} = gettimeofday;
|
||||||
@ -160,7 +160,7 @@ sub antispam_cmd {
|
|||||||
return "/say Added `$keyword`.";
|
return "/say Added `$keyword`.";
|
||||||
}
|
}
|
||||||
when ("remove") {
|
when ("remove") {
|
||||||
my ($namespace, $keyword) = $self->{pbot}->{interpreter}->split_args(\@pargs, 2);
|
my ($namespace, $keyword) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
return "Usage: antispam remove <namespace> <regex>" if not defined $namespace or not defined $keyword;
|
return "Usage: antispam remove <namespace> <regex>" if not defined $namespace or not defined $keyword;
|
||||||
|
|
||||||
if(not defined $self->{keywords}->hash->{$namespace}) {
|
if(not defined $self->{keywords}->hash->{$namespace}) {
|
||||||
|
@ -170,15 +170,17 @@ sub check_blacklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub blacklist {
|
sub blacklist {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
$arguments = lc $arguments;
|
|
||||||
|
|
||||||
my ($command, $args) = split /\s+/, $arguments, 2;
|
my $arglist = $stuff->{arglist};
|
||||||
|
$self->{pbot}->{interpreter}->lc_args($arglist);
|
||||||
|
|
||||||
|
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);
|
||||||
|
|
||||||
return "Usage: blacklist <command>, where commands are: list/show, add, remove" if not defined $command;
|
return "Usage: blacklist <command>, where commands are: list/show, add, remove" if not defined $command;
|
||||||
|
|
||||||
given($command) {
|
given ($command) {
|
||||||
when($_ eq "list" or $_ eq "show") {
|
when ($_ eq "list" or $_ eq "show") {
|
||||||
my $text = "Blacklist:\n";
|
my $text = "Blacklist:\n";
|
||||||
my $entries = 0;
|
my $entries = 0;
|
||||||
foreach my $channel (sort keys %{ $self->{blacklist} }) {
|
foreach my $channel (sort keys %{ $self->{blacklist} }) {
|
||||||
@ -195,8 +197,8 @@ sub blacklist {
|
|||||||
$text .= "none" if $entries == 0;
|
$text .= "none" if $entries == 0;
|
||||||
return "/msg $nick $text";
|
return "/msg $nick $text";
|
||||||
}
|
}
|
||||||
when("add") {
|
when ("add") {
|
||||||
my ($mask, $channel) = split /\s+/, $args, 2;
|
my ($mask, $channel) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
return "Usage: blacklist add <hostmask regex> [channel]" if not defined $mask;
|
return "Usage: blacklist add <hostmask regex> [channel]" if not defined $mask;
|
||||||
|
|
||||||
$channel = '.*' if not defined $channel;
|
$channel = '.*' if not defined $channel;
|
||||||
@ -205,8 +207,8 @@ sub blacklist {
|
|||||||
$self->add($channel, $mask);
|
$self->add($channel, $mask);
|
||||||
return "/say $mask blacklisted in channel $channel";
|
return "/say $mask blacklisted in channel $channel";
|
||||||
}
|
}
|
||||||
when("remove") {
|
when ("remove") {
|
||||||
my ($mask, $channel) = split /\s+/, $args, 2;
|
my ($mask, $channel) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
return "Usage: blacklist remove <hostmask regex> [channel]" if not defined $mask;
|
return "Usage: blacklist remove <hostmask regex> [channel]" if not defined $mask;
|
||||||
|
|
||||||
$channel = '.*' if not defined $channel;
|
$channel = '.*' if not defined $channel;
|
||||||
|
@ -72,7 +72,7 @@ sub in_channel {
|
|||||||
return $usage;
|
return $usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($channel, $command) = split / /, $arguments, 2;
|
my ($channel, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
return $usage if not defined $channel or not defined $command;
|
return $usage if not defined $channel or not defined $command;
|
||||||
|
|
||||||
$stuff->{admin_channel_override} = $channel;
|
$stuff->{admin_channel_override} = $channel;
|
||||||
@ -112,9 +112,9 @@ sub logout {
|
|||||||
|
|
||||||
sub adminadd {
|
sub adminadd {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
my ($name, $channel, $hostmask, $level, $password) = split /\s+/, $arguments, 5;
|
my ($name, $channel, $hostmask, $level, $password) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
|
||||||
|
|
||||||
if(not defined $name or not defined $channel or not defined $hostmask or not defined $level
|
if(not defined $name or not defined $channel or not defined $hostmask or not defined $level
|
||||||
or not defined $password) {
|
or not defined $password) {
|
||||||
@ -139,9 +139,9 @@ sub adminadd {
|
|||||||
|
|
||||||
sub adminrem {
|
sub adminrem {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
my ($channel, $hostmask) = split /\s+/, $arguments, 2;
|
my ($channel, $hostmask) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $channel or not defined $hostmask) {
|
if(not defined $channel or not defined $hostmask) {
|
||||||
return "/msg $nick Usage: adminrem <channel> <hostmask/name>";
|
return "/msg $nick Usage: adminrem <channel> <hostmask/name>";
|
||||||
@ -172,8 +172,8 @@ sub adminrem {
|
|||||||
|
|
||||||
sub adminset {
|
sub adminset {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($channel, $hostmask, $key, $value) = split /\s+/, $arguments, 4 if defined $arguments;
|
my ($channel, $hostmask, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 4);
|
||||||
|
|
||||||
if(not defined $channel or not defined $hostmask) {
|
if(not defined $channel or not defined $hostmask) {
|
||||||
return "Usage: adminset <channel> <hostmask/name> [key] [value]";
|
return "Usage: adminset <channel> <hostmask/name> [key] [value]";
|
||||||
@ -219,8 +219,8 @@ sub adminset {
|
|||||||
|
|
||||||
sub adminunset {
|
sub adminunset {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($channel, $hostmask, $key) = split /\s+/, $arguments, 3 if defined $arguments;
|
my ($channel, $hostmask, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $channel or not defined $hostmask) {
|
if(not defined $channel or not defined $hostmask) {
|
||||||
return "Usage: adminunset <channel> <hostmask/name> <key>";
|
return "Usage: adminunset <channel> <hostmask/name> <key>";
|
||||||
@ -250,7 +250,7 @@ sub join_channel {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
|
|
||||||
foreach my $channel (split /\s+/, $arguments) {
|
foreach my $channel (split /[\s+,]/, $arguments) {
|
||||||
$self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n");
|
$self->{pbot}->{logger}->log("$nick!$user\@$host made me join $channel\n");
|
||||||
$self->{pbot}->{chanops}->join_channel($channel);
|
$self->{pbot}->{chanops}->join_channel($channel);
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ sub part_channel {
|
|||||||
|
|
||||||
$arguments = $from if not $arguments;
|
$arguments = $from if not $arguments;
|
||||||
|
|
||||||
foreach my $channel (split /\s+/, $arguments) {
|
foreach my $channel (split /[\s+,]/, $arguments) {
|
||||||
$self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n");
|
$self->{pbot}->{logger}->log("$nick!$user\@$host made me part $channel\n");
|
||||||
$self->{pbot}->{chanops}->part_channel($channel);
|
$self->{pbot}->{chanops}->part_channel($channel);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ sub initialize {
|
|||||||
sub ban_user {
|
sub ban_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
$channel = '' if not defined $channel;
|
$channel = '' if not defined $channel;
|
||||||
$length = '' if not defined $length;
|
$length = '' if not defined $length;
|
||||||
@ -114,7 +114,7 @@ sub unban_user {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($target, $channel, $immediately) = split /\s+/, $arguments;
|
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if (defined $target and defined $channel and $channel !~ /^#/) {
|
if (defined $target and defined $channel and $channel !~ /^#/) {
|
||||||
my $temp = $target;
|
my $temp = $target;
|
||||||
@ -152,7 +152,7 @@ sub unban_user {
|
|||||||
sub mute_user {
|
sub mute_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($target, $channel, $length) = split(/\s+/, $arguments, 3);
|
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
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");
|
||||||
@ -222,7 +222,7 @@ sub unmute_user {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($target, $channel, $immediately) = split /\s+/, $arguments;
|
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if (defined $target and defined $channel and $channel !~ /^#/) {
|
if (defined $target and defined $channel and $channel !~ /^#/) {
|
||||||
my $temp = $target;
|
my $temp = $target;
|
||||||
|
@ -43,8 +43,8 @@ sub initialize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub set {
|
sub set {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($channel, $key, $value) = split /\s+/, $arguments, 3;
|
my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $channel) {
|
if(not defined $channel) {
|
||||||
return "Usage: chanset <channel> [key [value]]";
|
return "Usage: chanset <channel> [key [value]]";
|
||||||
@ -54,8 +54,8 @@ sub set {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub unset {
|
sub unset {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($channel, $key) = split /\s+/, $arguments;
|
my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $channel or not defined $key) {
|
if(not defined $channel or not defined $key) {
|
||||||
return "Usage: chanunset <channel> <key>";
|
return "Usage: chanunset <channel> <key>";
|
||||||
|
@ -189,7 +189,11 @@ sub levenshtein_matches {
|
|||||||
my $length = (length($primary_index_key) > length($index)) ? length $primary_index_key : length $index;
|
my $length = (length($primary_index_key) > length($index)) ? length $primary_index_key : length $index;
|
||||||
|
|
||||||
if($distance_result / $length < $distance) {
|
if($distance_result / $length < $distance) {
|
||||||
$result .= $comma . $index;
|
if ($index =~ / /) {
|
||||||
|
$result .= $comma . "\"$index\"";
|
||||||
|
} else {
|
||||||
|
$result .= $comma . $index;
|
||||||
|
}
|
||||||
$comma = ", ";
|
$comma = ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +224,11 @@ sub levenshtein_matches {
|
|||||||
$header = "" if $last_header eq $header;
|
$header = "" if $last_header eq $header;
|
||||||
$last_header = $header;
|
$last_header = $header;
|
||||||
$comma = '; ' if $comma ne '' and $header ne '';
|
$comma = '; ' if $comma ne '' and $header ne '';
|
||||||
$result .= $comma . $header . $index2;
|
if ($index2 =~ / /) {
|
||||||
|
$result .= $comma . $header . "\"$index2\"";
|
||||||
|
} else {
|
||||||
|
$result .= $comma . $header . $index2;
|
||||||
|
}
|
||||||
$comma = ", ";
|
$comma = ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ use POSIX qw(strftime);
|
|||||||
use Storable;
|
use Storable;
|
||||||
|
|
||||||
use PBot::Utils::SafeFilename;
|
use PBot::Utils::SafeFilename;
|
||||||
use PBot::Utils::ValidateString;
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
if(ref($_[1]) eq 'HASH') {
|
if(ref($_[1]) eq 'HASH') {
|
||||||
@ -100,7 +99,7 @@ sub initialize {
|
|||||||
sub call_factoid {
|
sub call_factoid {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($chan, $keyword, $args) = split /\s+/, $arguments, 3;
|
my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $chan or not defined $keyword) {
|
if(not defined $chan or not defined $keyword) {
|
||||||
return "Usage: fact <channel> <keyword> [arguments]";
|
return "Usage: fact <channel> <keyword> [arguments]";
|
||||||
@ -171,7 +170,9 @@ sub log_factoid {
|
|||||||
|
|
||||||
sub find_factoid_with_optional_channel {
|
sub find_factoid_with_optional_channel {
|
||||||
my ($self, $from, $arguments, $command, $usage, $explicit, $exact_channel) = @_;
|
my ($self, $from, $arguments, $command, $usage, $explicit, $exact_channel) = @_;
|
||||||
my ($from_chan, $from_trigger, $remaining_args) = split /\s+/, $arguments, 3;
|
|
||||||
|
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
|
||||||
|
my ($from_chan, $from_trigger, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 3);
|
||||||
|
|
||||||
if (not defined $from_chan or (not defined $from_chan and not defined $from_trigger)) {
|
if (not defined $from_chan or (not defined $from_chan and not defined $from_trigger)) {
|
||||||
return "Usage: $command [channel] <keyword>" if not $usage;
|
return "Usage: $command [channel] <keyword>" if not $usage;
|
||||||
@ -192,8 +193,8 @@ sub find_factoid_with_optional_channel {
|
|||||||
# not a channel or global, so must be a keyword
|
# not a channel or global, so must be a keyword
|
||||||
my $keyword = $from_chan;
|
my $keyword = $from_chan;
|
||||||
$from_chan = $from;
|
$from_chan = $from;
|
||||||
$remaining_args = $from_trigger . (length $remaining_args ? " $remaining_args" : "");
|
|
||||||
$from_trigger = $keyword;
|
$from_trigger = $keyword;
|
||||||
|
(undef, $remaining_args) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,8 +327,7 @@ sub list_undo_history {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub factundo {
|
sub factundo {
|
||||||
my $self = shift;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
|
||||||
|
|
||||||
my $usage = "Usage: factundo [-l [N]] [-r N] [channel] <keyword> (-l list undo history, optionally starting from N; -r jump to revision N)";
|
my $usage = "Usage: factundo [-l [N]] [-r N] [channel] <keyword> (-l list undo history, optionally starting from N; -r jump to revision N)";
|
||||||
|
|
||||||
@ -348,6 +348,7 @@ sub factundo {
|
|||||||
return $usage if not @$args;
|
return $usage if not @$args;
|
||||||
|
|
||||||
$arguments = join ' ', @$args;
|
$arguments = join ' ', @$args;
|
||||||
|
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
|
||||||
|
|
||||||
my ($channel, $trigger) = $self->find_factoid_with_optional_channel($from, $arguments, 'factundo', undef, 1, 1);
|
my ($channel, $trigger) = $self->find_factoid_with_optional_channel($from, $arguments, 'factundo', undef, 1, 1);
|
||||||
my $deleted;
|
my $deleted;
|
||||||
@ -355,7 +356,7 @@ sub factundo {
|
|||||||
if (not defined $trigger) {
|
if (not defined $trigger) {
|
||||||
# factoid not found or some error, try to continue and load undo file if it exists
|
# factoid not found or some error, try to continue and load undo file if it exists
|
||||||
$deleted = 1;
|
$deleted = 1;
|
||||||
($channel, $trigger) = split /\s+/, $arguments, 2;
|
($channel, $trigger) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
if (not defined $trigger) {
|
if (not defined $trigger) {
|
||||||
$trigger = $channel;
|
$trigger = $channel;
|
||||||
$channel = $from;
|
$channel = $from;
|
||||||
@ -519,19 +520,16 @@ sub factset {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $args) = @_;
|
my ($from, $nick, $user, $host, $args) = @_;
|
||||||
|
|
||||||
$args = validate_string($args);
|
|
||||||
|
|
||||||
my ($channel, $trigger, $arguments) = $self->find_factoid_with_optional_channel($from, $args, 'factset', 'Usage: factset [channel] <factoid> [key [value]]', 1);
|
my ($channel, $trigger, $arguments) = $self->find_factoid_with_optional_channel($from, $args, 'factset', 'Usage: factset [channel] <factoid> [key [value]]', 1);
|
||||||
return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message
|
return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message
|
||||||
|
|
||||||
my ($key, $value) = split /\s+/, $arguments, 2;
|
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
|
||||||
|
my ($key, $value) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
|
|
||||||
$channel = '.*' if $channel !~ /^#/;
|
$channel = '.*' if $channel !~ /^#/;
|
||||||
|
|
||||||
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1);
|
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1);
|
||||||
|
|
||||||
my $admininfo;
|
my $admininfo;
|
||||||
|
|
||||||
if (defined $owner_channel) {
|
if (defined $owner_channel) {
|
||||||
$admininfo = $self->{pbot}->{admins}->loggedin($owner_channel, "$nick!$user\@$host");
|
$admininfo = $self->{pbot}->{admins}->loggedin($owner_channel, "$nick!$user\@$host");
|
||||||
} else {
|
} else {
|
||||||
@ -600,9 +598,12 @@ sub factunset {
|
|||||||
|
|
||||||
my $usage = 'Usage: factunset [channel] <factoid> <key>';
|
my $usage = 'Usage: factunset [channel] <factoid> <key>';
|
||||||
|
|
||||||
my ($channel, $trigger, $key) = $self->find_factoid_with_optional_channel($from, $args, 'factset', $usage, 1);
|
my ($channel, $trigger, $arguments) = $self->find_factoid_with_optional_channel($from, $args, 'factunset', $usage, 1);
|
||||||
return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message
|
return $channel if not defined $trigger; # if $trigger is not defined, $channel is an error message
|
||||||
|
|
||||||
|
my $arglist = $self->{pbot}->{interpreter}->make_args($arguments);
|
||||||
|
my ($key) = $self->{pbot}->{interpreter}->split_args($arglist, 1);
|
||||||
|
|
||||||
return $usage if not length $key;
|
return $usage if not length $key;
|
||||||
|
|
||||||
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1);
|
my ($owner_channel, $owner_trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $trigger, undef, 1, 1);
|
||||||
@ -731,9 +732,8 @@ sub list {
|
|||||||
|
|
||||||
sub factmove {
|
sub factmove {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
$arguments = validate_string($arguments);
|
my ($src_channel, $source, $target_channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
|
||||||
my ($src_channel, $source, $target_channel, $target) = split /\s+/, $arguments, 5 if length $arguments;
|
|
||||||
|
|
||||||
my $usage = "Usage: factmove <source channel> <source factoid> <target channel/factoid> [target factoid]";
|
my $usage = "Usage: factmove <source channel> <source factoid> <target channel/factoid> [target factoid]";
|
||||||
|
|
||||||
@ -821,11 +821,10 @@ sub factmove {
|
|||||||
|
|
||||||
sub factalias {
|
sub factalias {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
$arguments = validate_string($arguments);
|
|
||||||
|
my ($chan, $alias, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
my ($chan, $alias, $command) = split /\s+/, $arguments, 3 if defined $arguments;
|
|
||||||
|
|
||||||
if (defined $chan and not ($chan eq '.*' or $chan =~ m/^#/)) {
|
if (defined $chan and not ($chan eq '.*' or $chan =~ m/^#/)) {
|
||||||
# $chan doesn't look like a channel, so shift everything right
|
# $chan doesn't look like a channel, so shift everything right
|
||||||
# and replace $chan with $from
|
# and replace $chan with $from
|
||||||
@ -838,6 +837,8 @@ sub factalias {
|
|||||||
$chan = $from;
|
$chan = $from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$chan = '.*' if $chan !~ /^#/;
|
||||||
|
|
||||||
if (not length $alias or not length $command) {
|
if (not length $alias or not length $command) {
|
||||||
return "Usage: factalias [channel] <keyword> <command>";
|
return "Usage: factalias [channel] <keyword> <command>";
|
||||||
}
|
}
|
||||||
@ -878,7 +879,6 @@ sub add_regex {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
$arguments = validate_string($arguments);
|
|
||||||
my ($keyword, $text) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments;
|
my ($keyword, $text) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments;
|
||||||
|
|
||||||
$from = '.*' if not defined $from or $from !~ /^#/;
|
$from = '.*' if not defined $from or $from !~ /^#/;
|
||||||
@ -911,16 +911,19 @@ sub add_regex {
|
|||||||
|
|
||||||
sub factadd {
|
sub factadd {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($from_chan, $keyword, $text);
|
my ($from_chan, $keyword, $text);
|
||||||
|
|
||||||
$arguments = validate_string($arguments);
|
my @arglist = @{$stuff->{arglist}};
|
||||||
|
|
||||||
if (defined $arguments) {
|
if (@arglist) {
|
||||||
if ($arguments =~ /^(#\S+|global|\.\*)\s+(\S+)\s+(?:is\s+)?(.*)$/i) {
|
if ($arglist[0] =~ m/(?:^#|^global$|^\.\*$)/i) {
|
||||||
($from_chan, $keyword, $text) = ($1, $2, $3);
|
splice @arglist, 2, 1 if lc $arglist[2] eq 'is';
|
||||||
} elsif ($arguments =~ /^(\S+)\s+(?:is\s+)?(.*)$/i) {
|
($from_chan, $keyword, $text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 3);
|
||||||
($from_chan, $keyword, $text) = ($from, $1, $2);
|
} else {
|
||||||
|
$from_chan = $from;
|
||||||
|
splice @arglist, 1, 1 if lc $arglist[1] eq 'is';
|
||||||
|
($keyword, $text) = $self->{pbot}->{interpreter}->split_args(\@arglist, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -965,10 +968,10 @@ sub factadd {
|
|||||||
|
|
||||||
sub factrem {
|
sub factrem {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
|
|
||||||
my ($from_chan, $from_trig) = split /\s+/, $arguments;
|
my ($from_chan, $from_trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if (not defined $from_trig) {
|
if (not defined $from_trig) {
|
||||||
$from_trig = $from_chan;
|
$from_trig = $from_chan;
|
||||||
@ -1038,10 +1041,10 @@ sub histogram {
|
|||||||
|
|
||||||
sub factshow {
|
sub factshow {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
|
|
||||||
my ($chan, $trig) = split /\s+/, $arguments;
|
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if (not defined $trig) {
|
if (not defined $trig) {
|
||||||
$trig = $chan;
|
$trig = $chan;
|
||||||
@ -1093,7 +1096,8 @@ sub factlog {
|
|||||||
|
|
||||||
if (not defined $trigger) {
|
if (not defined $trigger) {
|
||||||
# factoid not found or some error, try to continue and load factlog file if it exists
|
# factoid not found or some error, try to continue and load factlog file if it exists
|
||||||
($channel, $trigger) = split /\s+/, "@$args", 2;
|
my $arglist = $self->{pbot}->{interpreter}->make_args("@$args");
|
||||||
|
($channel, $trigger) = $self->{pbot}->{interpreter}->split_args($arglist, 2);
|
||||||
if (not defined $trigger) {
|
if (not defined $trigger) {
|
||||||
$trigger = $channel;
|
$trigger = $channel;
|
||||||
$channel = $from;
|
$channel = $from;
|
||||||
@ -1138,10 +1142,10 @@ sub factlog {
|
|||||||
|
|
||||||
sub factinfo {
|
sub factinfo {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
|
|
||||||
my ($chan, $trig) = split /\s+/, $arguments;
|
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if (not defined $trig) {
|
if (not defined $trig) {
|
||||||
$trig = $chan;
|
$trig = $chan;
|
||||||
@ -1178,13 +1182,13 @@ sub factinfo {
|
|||||||
|
|
||||||
sub top20 {
|
sub top20 {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
my %hash = ();
|
my %hash = ();
|
||||||
my $text = "";
|
my $text = "";
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
|
|
||||||
my ($channel, $args) = split /\s+/, $arguments, 2 if defined $arguments;
|
my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $channel) {
|
if(not defined $channel) {
|
||||||
return "Usage: top20 <channel> [nick or 'recent']";
|
return "Usage: top20 <channel> [nick or 'recent']";
|
||||||
@ -1366,7 +1370,11 @@ sub factfind {
|
|||||||
$text .= $chan eq '.*' ? "[global channel] " : "[$chan] ";
|
$text .= $chan eq '.*' ? "[global channel] " : "[$chan] ";
|
||||||
$last_chan = $chan;
|
$last_chan = $chan;
|
||||||
}
|
}
|
||||||
$text .= "$trigger ";
|
if ($trigger =~ / /) {
|
||||||
|
$text .= "\"$trigger\" ";
|
||||||
|
} else {
|
||||||
|
$text .= "$trigger ";
|
||||||
|
}
|
||||||
$last_trigger = $trigger;
|
$last_trigger = $trigger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1393,8 +1401,6 @@ sub factchange {
|
|||||||
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
|
||||||
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier);
|
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier);
|
||||||
|
|
||||||
$arguments = validate_string($arguments);
|
|
||||||
|
|
||||||
my $needs_disambig;
|
my $needs_disambig;
|
||||||
|
|
||||||
if (defined $arguments) {
|
if (defined $arguments) {
|
||||||
|
@ -46,11 +46,11 @@ sub initialize {
|
|||||||
|
|
||||||
sub ignore_user {
|
sub ignore_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
return "/msg $nick Usage: ignore nick!user\@host [channel] [timeout]" if not defined $arguments;
|
return "/msg $nick Usage: ignore nick!user\@host [channel] [timeout]" if not defined $arguments;
|
||||||
|
|
||||||
my ($target, $channel, $length) = split /\s+/, $arguments, 3;
|
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $target) {
|
if(not defined $target) {
|
||||||
return "/msg $nick Usage: ignore host [channel] [timeout]";
|
return "/msg $nick Usage: ignore host [channel] [timeout]";
|
||||||
@ -95,8 +95,8 @@ sub ignore_user {
|
|||||||
|
|
||||||
sub unignore_user {
|
sub unignore_user {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($target, $channel) = split /\s+/, $arguments if defined $arguments;
|
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $target) {
|
if(not defined $target) {
|
||||||
return "/msg $nick Usage: unignore host [channel]";
|
return "/msg $nick Usage: unignore host [channel]";
|
||||||
|
@ -206,8 +206,12 @@ sub interpret {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stuff->{command} =~ /^tell\s+(\p{PosixGraph}{1,20})\s+about\s+(.*?)\s+(.*)$/is) {
|
my $cmdlist = $self->make_args($stuff->{command});
|
||||||
($keyword, $arguments, $stuff->{nickoverride}) = ($2, $3, $1);
|
|
||||||
|
if ($self->arglist_size($cmdlist) >= 4 and lc $cmdlist->[0] eq 'tell' and lc $cmdlist->[2] eq 'about') {
|
||||||
|
$stuff->{nickoverride} = $cmdlist->[1];
|
||||||
|
($keyword, $arguments) = $self->split_args($cmdlist, 2, 3);
|
||||||
|
$arguments = '' if not defined $arguments;
|
||||||
my $similar = $self->{pbot}->{nicklist}->is_present_similar($stuff->{from}, $stuff->{nickoverride});
|
my $similar = $self->{pbot}->{nicklist}->is_present_similar($stuff->{from}, $stuff->{nickoverride});
|
||||||
if ($similar) {
|
if ($similar) {
|
||||||
$stuff->{nickoverride} = $similar;
|
$stuff->{nickoverride} = $similar;
|
||||||
@ -216,25 +220,15 @@ sub interpret {
|
|||||||
delete $stuff->{nickoverride};
|
delete $stuff->{nickoverride};
|
||||||
delete $stuff->{force_nickoverride};
|
delete $stuff->{force_nickoverride};
|
||||||
}
|
}
|
||||||
} elsif ($stuff->{command} =~ /^tell\s+(\p{PosixGraph}{1,20})\s+about\s+(.*)$/is) {
|
|
||||||
($keyword, $stuff->{nickoverride}) = ($2, $1);
|
|
||||||
my $similar = $self->{pbot}->{nicklist}->is_present_similar($stuff->{from}, $stuff->{nickoverride});
|
|
||||||
if ($similar) {
|
|
||||||
$stuff->{nickoverride} = $similar;
|
|
||||||
$stuff->{force_nickoverride} = 1;
|
|
||||||
} else {
|
|
||||||
delete $stuff->{nickoverride};
|
|
||||||
delete $stuff->{force_nickoverride};
|
|
||||||
}
|
|
||||||
} elsif ($stuff->{command} =~ /^(.*?)\s+(.*)$/s) {
|
|
||||||
($keyword, $arguments) = ($1, $2);
|
|
||||||
} else {
|
} else {
|
||||||
$keyword = $stuff->{command};
|
($keyword, $arguments) = $self->split_args($cmdlist, 2);
|
||||||
|
$arguments = "" if not defined $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length $keyword > 30) {
|
# FIXME: make this a registry item
|
||||||
$keyword = substr($keyword, 0, 30);
|
if (length $keyword > 128) {
|
||||||
$self->{pbot}->{logger}->log("Truncating keyword to 30 chars: $keyword\n");
|
$keyword = substr($keyword, 0, 128);
|
||||||
|
$self->{pbot}->{logger}->log("Truncating keyword to 128 chars: $keyword\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse out a substituted command
|
# parse out a substituted command
|
||||||
@ -318,16 +312,30 @@ sub interpret {
|
|||||||
# unescape any escaped pipes
|
# unescape any escaped pipes
|
||||||
$arguments =~ s/\\\|\s*\{/| {/g if defined $arguments;
|
$arguments =~ s/\\\|\s*\{/| {/g if defined $arguments;
|
||||||
|
|
||||||
|
$arguments = validate_string($arguments);
|
||||||
|
|
||||||
# set arguments as a plain string
|
# set arguments as a plain string
|
||||||
$stuff->{arguments} = $arguments;
|
$stuff->{arguments} = $arguments;
|
||||||
|
|
||||||
# set arguments as a positional array
|
# set arguments as an array
|
||||||
my @args = split / /, $arguments;
|
$stuff->{arglist} = $self->make_args($arguments);
|
||||||
my @pargs;
|
|
||||||
|
# handle this shit
|
||||||
|
return $self->SUPER::execute_all($stuff);
|
||||||
|
}
|
||||||
|
|
||||||
|
# creates an array of arguments from a string
|
||||||
|
sub make_args {
|
||||||
|
my ($self, $string) = @_;
|
||||||
|
|
||||||
|
my @args = split / /, $string;
|
||||||
|
my @arglist;
|
||||||
|
my @arglist_quotes;
|
||||||
|
|
||||||
while (@args) {
|
while (@args) {
|
||||||
my $arg = shift @args;
|
my $arg = shift @args;
|
||||||
|
|
||||||
|
# is this a quoted argument?
|
||||||
if ($arg =~ /^["']/) {
|
if ($arg =~ /^["']/) {
|
||||||
my $string = $arg;
|
my $string = $arg;
|
||||||
if (@args) {
|
if (@args) {
|
||||||
@ -336,43 +344,73 @@ sub interpret {
|
|||||||
}
|
}
|
||||||
my ($extracted, $rest) = extract_quotelike $string;
|
my ($extracted, $rest) = extract_quotelike $string;
|
||||||
if (defined $extracted) {
|
if (defined $extracted) {
|
||||||
|
# preserve quotes for $rest in split_args()
|
||||||
|
push @arglist_quotes, $extracted;
|
||||||
|
|
||||||
# strip quote characters
|
# strip quote characters
|
||||||
$extracted =~ s/^(.)//;
|
$extracted =~ s/^(.)//;
|
||||||
$extracted =~ s/$1$//;
|
$extracted =~ s/$1$//;
|
||||||
push @pargs, $extracted;
|
push @arglist, $extracted;
|
||||||
|
|
||||||
$rest =~ s/^ //;
|
$rest =~ s/^ //;
|
||||||
@args = split / /, $rest;
|
@args = split / /, $rest;
|
||||||
} else {
|
} else {
|
||||||
# mismatched quotes, shove the remainder as the last positional argument
|
# mismatched quotes, shove the remainder as the last positional argument
|
||||||
push @pargs, $rest;
|
push @arglist, $rest;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
push @pargs, $arg;
|
push @arglist, $arg;
|
||||||
|
push @arglist_quotes, $arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$stuff->{argumentspos} = \@pargs;
|
# copy original args with quotes intact to end of arglist
|
||||||
|
push @arglist, @arglist_quotes;
|
||||||
|
return \@arglist;
|
||||||
|
}
|
||||||
|
|
||||||
return $self->SUPER::execute_all($stuff);
|
# returns size of array of arguments
|
||||||
|
sub arglist_size {
|
||||||
|
my ($self, $args) = @_;
|
||||||
|
return @$args / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
# shifts first argument off array of arguments
|
||||||
|
sub shift_arg {
|
||||||
|
my ($self, $args) = @_;
|
||||||
|
splice @$args, @$args / 2, 1; # remove original quoted argument
|
||||||
|
return shift @$args;
|
||||||
}
|
}
|
||||||
|
|
||||||
# splits array of arguments into array with overflow arguments filling up last position
|
# splits array of arguments into array with overflow arguments filling up last position
|
||||||
# split_args(qw/dog cat bird hamster/, 3) => ("dog", "cat", "bird hamster")
|
# split_args(qw/dog cat bird hamster/, 3) => ("dog", "cat", "bird hamster")
|
||||||
sub split_args {
|
sub split_args {
|
||||||
my ($self, $args, $count) = @_;
|
my ($self, $args, $count, $offset) = @_;
|
||||||
my @result;
|
my @result;
|
||||||
|
|
||||||
while (--$count) {
|
my $max = $self->arglist_size($args);
|
||||||
my $arg = shift @$args;
|
|
||||||
push @result, $arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $rest = join ' ', @$args;
|
my $i = $offset // 0;
|
||||||
push @result, $rest;
|
do {
|
||||||
|
my $arg = $args->[$i++];
|
||||||
|
push @result, $arg;
|
||||||
|
} while (--$count > 1 and $i < $max);
|
||||||
|
|
||||||
|
# get rest from 2nd half of arglist, which contains original quotes
|
||||||
|
my $rest = join ' ', @$args[@$args / 2 + $i .. @$args - 1];
|
||||||
|
push @result, $rest if length $rest;
|
||||||
return @result;
|
return @result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# lowercases array of arguments
|
||||||
|
sub lc_args {
|
||||||
|
my ($self, $args) = @_;
|
||||||
|
for (my $i = 0; $i < @$args; $i++) {
|
||||||
|
$args->[$i] = lc $args->[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub truncate_result {
|
sub truncate_result {
|
||||||
my ($self, $from, $nick, $text, $original_result, $result, $paste) = @_;
|
my ($self, $from, $nick, $text, $original_result, $result, $paste) = @_;
|
||||||
my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len');
|
my $max_msg_len = $self->{pbot}->{registry}->get_value('irc', 'max_msg_len');
|
||||||
|
@ -42,8 +42,8 @@ sub initialize {
|
|||||||
|
|
||||||
sub regset {
|
sub regset {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($section, $item, $key, $value) = split /\s+/, $arguments, 4 if defined $arguments;
|
my ($section, $item, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 4);
|
||||||
|
|
||||||
if(not defined $section or not defined $item) {
|
if(not defined $section or not defined $item) {
|
||||||
return "Usage: regset <section> <item> [key [value]]";
|
return "Usage: regset <section> <item> [key [value]]";
|
||||||
@ -57,8 +57,8 @@ sub regset {
|
|||||||
|
|
||||||
sub regunset {
|
sub regunset {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($section, $item, $key) = split /\s+/, $arguments, 3 if defined $arguments;
|
my ($section, $item, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $section or not defined $item or not defined $key) {
|
if(not defined $section or not defined $item or not defined $key) {
|
||||||
return "Usage: regunset <section> <item> <key>"
|
return "Usage: regunset <section> <item> <key>"
|
||||||
@ -69,8 +69,8 @@ sub regunset {
|
|||||||
|
|
||||||
sub regadd {
|
sub regadd {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($section, $item, $value) = split /\s+/, $arguments, 3 if defined $arguments;
|
my ($section, $item, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
|
||||||
|
|
||||||
if(not defined $section or not defined $item or not defined $value) {
|
if(not defined $section or not defined $item or not defined $value) {
|
||||||
return "Usage: regadd <section> <item> <value>";
|
return "Usage: regadd <section> <item> <value>";
|
||||||
@ -84,8 +84,8 @@ sub regadd {
|
|||||||
|
|
||||||
sub regrem {
|
sub regrem {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my ($section, $item) = split /\s+/, $arguments if defined $arguments;
|
my ($section, $item) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $section or not defined $item) {
|
if(not defined $section or not defined $item) {
|
||||||
return "Usage: regrem <section> <item>";
|
return "Usage: regrem <section> <item>";
|
||||||
@ -106,10 +106,10 @@ sub regrem {
|
|||||||
|
|
||||||
sub regshow {
|
sub regshow {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
my $registry = $self->{pbot}->{registry}->{registry}->hash;
|
my $registry = $self->{pbot}->{registry}->{registry}->hash;
|
||||||
|
|
||||||
my ($section, $item) = split /\s+/, $arguments if defined $arguments;
|
my ($section, $item) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if(not defined $section or not defined $item) {
|
if(not defined $section or not defined $item) {
|
||||||
return "Usage: regshow <section> <item>";
|
return "Usage: regshow <section> <item>";
|
||||||
|
Loading…
Reference in New Issue
Block a user