3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 03:49:29 +01:00

Misc fixes and improvements

applets/random_quote.pl: URI encode arguments

Plugins/FuncSed: improve error handling
This commit is contained in:
Pragmatic Software 2022-08-03 05:18:33 -07:00
parent e4becb22a1
commit d824255c6e
4 changed files with 28 additions and 17 deletions

View File

@ -6,6 +6,7 @@
# Quick and dirty by :pragma
use LWP::UserAgent::WithCache;
use URI::Escape;
my ($text, $t);
@ -35,7 +36,7 @@ while (1) {
my $author = "";
$arguments =~ s/\$nick/me/gi;
$arguments =~ s/\s/+/g;
$arguments = uri_escape($arguments);
if ($arguments =~ m/\-\-author[\s\+]+(.*)/i) {
$author = $1;

View File

@ -389,6 +389,7 @@ feature qalc => sub {
};
feature random_quote => sub {
requires 'URI::Escape';
requires 'LWP::UserAgent::WithCache';
};

View File

@ -33,26 +33,35 @@ sub func_sed {
my $self = shift;
my $text = "@_";
if ($text =~ /^s(.)(.*?)(?<!\\)\1(.*?)(?<!\\)\1(\S*)\s+(.*)/p) {
my ($a, $r, $g, $m, $t) = ($5, "'\"$3\"'", index($4, "g") != -1, $4, $2);
my $result = eval {
if ($text =~ /^s(.)(.*?)(?<!\\)\1(.*?)(?<!\\)\1(\S*)\s+(.*)/p) {
my ($a, $r, $g, $m, $t) = ($5, "'\"$3\"'", index($4, "g") != -1, $4, $2);
print "a: $a, r: $r, g: $g, m: $m, t: $t\n";
print "text: [$text]\n";
#print "a: $a, r: $r, g: $g, m: $m, t: $t\n";
#print "text: [$text]\n";
if ($m =~ /P/) {
$r =~ s/^'"(.*)"'$/$1/;
$m =~ s/P//g;
if ($m =~ /P/) {
$r =~ s/^'"(.*)"'$/$1/;
$m =~ s/P//g;
if ($g) { $a =~ s|(?$m)($t)|$1=~/^[A-Z][^A-Z]/?ucfirst$r:($1=~/^[A-Z]+$/?uc$r:$r)|gie; }
else { $a =~ s|(?$m)($t)|$1=~/^[A-Z][^A-Z]/?ucfirst$r:($1=~/^[A-Z]+$/?uc$r:$r)|ie; }
if ($g) { $a =~ s|(?$m)($t)|$1=~/^[A-Z][^A-Z]/?ucfirst$r:($1=~/^[A-Z]+$/?uc$r:$r)|gie; }
else { $a =~ s|(?$m)($t)|$1=~/^[A-Z][^A-Z]/?ucfirst$r:($1=~/^[A-Z]+$/?uc$r:$r)|ie; }
} else {
if ($g) { $a =~ s/(?$m)$t/$r/geee; }
else { $a =~ s/(?$m)$t/$r/eee; }
}
return $a;
} else {
if ($g) { $a =~ s/(?$m)$t/$r/geee; }
else { $a =~ s/(?$m)$t/$r/eee; }
return 'sed: syntax error; usage: sed s/<regex>/<replacement>/[Pig]; P preserve case; i ignore case; g replace all';
}
return $a;
} else {
return "sed: syntax error";
};
if (my $e = $@) {
$e =~ s/ at .*$//;
return "sed: syntax error: $e";
}
return $result;
}
use warnings;

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4560,
BUILD_DATE => "2022-07-14",
BUILD_REVISION => 4561,
BUILD_DATE => "2022-08-03",
};
sub initialize {}