mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Allow multiple substitutions in interactive-editing
This commit is contained in:
parent
8529d79f49
commit
3aaf717bef
@ -7,7 +7,7 @@ use SOAP::Lite;
|
|||||||
$SOAP::Constants::DO_NOT_USE_XML_PARSER = 1;
|
$SOAP::Constants::DO_NOT_USE_XML_PARSER = 1;
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
use HTML::Entities;
|
use HTML::Entities;
|
||||||
use Text::Balanced qw(extract_codeblock);
|
use Text::Balanced qw(extract_codeblock extract_delimited);
|
||||||
|
|
||||||
my $user = 'test';
|
my $user = 'test';
|
||||||
my $pass = 'test';
|
my $pass = 'test';
|
||||||
@ -115,19 +115,50 @@ if($code =~ m/^\s*show\s*$/i) {
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($code =~ m/^\s*s\/(.*)\/(.*)\s*$/) {
|
{
|
||||||
my ($inner_regex, $suffix) = ($1, $2);
|
my $subcode = $code;
|
||||||
|
my $prevchange = $last_code[0];
|
||||||
|
my $got_changes = 0;
|
||||||
|
my $got_sub = 0;
|
||||||
|
|
||||||
|
while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
|
||||||
|
$got_sub = 1;
|
||||||
|
$subcode =~ s/^\s*(and)?\s*s//;
|
||||||
|
|
||||||
|
my ($regex, $to);
|
||||||
|
my ($e, $r) = extract_delimited($subcode, '/');
|
||||||
|
|
||||||
|
if(defined $e) {
|
||||||
|
$regex = $e;
|
||||||
|
$regex =~ s/^\///;
|
||||||
|
$regex =~ s/\/$//;
|
||||||
|
$subcode = "/$r";
|
||||||
|
} else {
|
||||||
|
print "$nick: Unbalanced slashes. Usage: !cc s/regex/substitution/[gi] [and s/.../.../ [and ...]]\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
($e, $r) = extract_delimited($subcode, '/');
|
||||||
|
|
||||||
|
if(defined $e) {
|
||||||
|
$to = $e;
|
||||||
|
$to =~ s/^\///;
|
||||||
|
$to =~ s/\/$//;
|
||||||
|
$subcode = $r;
|
||||||
|
} else {
|
||||||
|
print "$nick: Unbalanced slashes. Usage: !cc s/regex/substitution/[gi] [and s/.../.../ [and ...]]\n";
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $suffix;
|
||||||
|
$suffix = $1 if $subcode =~ s/^([^ ]+)//;
|
||||||
|
|
||||||
if(length $suffix and $suffix =~ m/[^gi]/) {
|
if(length $suffix and $suffix =~ m/[^gi]/) {
|
||||||
print "$nick: Bad regex modifier '$suffix'. Only 'i' and 'g' are allowed.\n";
|
print "$nick: Bad regex modifier '$suffix'. Only 'i' and 'g' are allowed.\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
if(defined $prevchange) {
|
||||||
if($inner_regex =~ m/(.*)\/(.*)/) {
|
$code = $prevchange;
|
||||||
my ($regex, $to) = ($1, $2);
|
|
||||||
|
|
||||||
if(defined $last_code[0]) {
|
|
||||||
$code = $last_code[0];
|
|
||||||
} else {
|
} else {
|
||||||
print "$nick: No recent code to change.\n";
|
print "$nick: No recent code to change.\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
@ -145,12 +176,15 @@ if($code =~ m/^\s*s\/(.*)\/(.*)\s*$/) {
|
|||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not $ret) {
|
if($ret) {
|
||||||
print "$nick: No changes made.\n";
|
$got_changes = 1;
|
||||||
exit 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
print "$nick: Unbalanced slashes. Usage: !cc s/regex/substitution/[gi]\n";
|
$prevchange = $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($got_sub and not $got_changes) {
|
||||||
|
print "$nick: No changes made.\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user