3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 11:59:43 +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 # Quick and dirty by :pragma
use LWP::UserAgent::WithCache; use LWP::UserAgent::WithCache;
use URI::Escape;
my ($text, $t); my ($text, $t);
@ -35,7 +36,7 @@ while (1) {
my $author = ""; my $author = "";
$arguments =~ s/\$nick/me/gi; $arguments =~ s/\$nick/me/gi;
$arguments =~ s/\s/+/g; $arguments = uri_escape($arguments);
if ($arguments =~ m/\-\-author[\s\+]+(.*)/i) { if ($arguments =~ m/\-\-author[\s\+]+(.*)/i) {
$author = $1; $author = $1;

View File

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

View File

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

View File

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