3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-02 01:18:40 +02:00

Allow multiple substitutions in interactive-editing

This commit is contained in:
Pragmatic Software 2010-05-14 23:41:38 +00:00
parent 8529d79f49
commit 3aaf717bef

View File

@ -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;
if(length $suffix and $suffix =~ m/[^gi]/) { while($subcode =~ m/^\s*(and)?\s*s\/.*\//) {
print "$nick: Bad regex modifier '$suffix'. Only 'i' and 'g' are allowed.\n"; $got_sub = 1;
exit 0; $subcode =~ s/^\s*(and)?\s*s//;
}
if($inner_regex =~ m/(.*)\/(.*)/) {
my ($regex, $to) = ($1, $2);
if(defined $last_code[0]) { my ($regex, $to);
$code = $last_code[0]; 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]/) {
print "$nick: Bad regex modifier '$suffix'. Only 'i' and 'g' are allowed.\n";
exit 0;
}
if(defined $prevchange) {
$code = $prevchange;
} else { } else {
print "$nick: No recent code to change.\n"; print "$nick: No recent code to change.\n";
exit 0; exit 0;
@ -145,14 +176,17 @@ 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;
} }
} }
open FILE, "> ideone_last_code.txt"; open FILE, "> ideone_last_code.txt";