mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 11:12:42 +01:00
Minor improvements to math.pl
This commit is contained in:
parent
2a933bff87
commit
cb6d811ba2
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 532,
|
BUILD_REVISION => 533,
|
||||||
BUILD_DATE => "2014-03-23",
|
BUILD_DATE => "2014-03-23",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ my ($arguments, $response, $invalid);
|
|||||||
my @valid_keywords = (
|
my @valid_keywords = (
|
||||||
'sin', 'cos', 'tan', 'atan', 'exp', 'int', 'hex', 'oct', 'log', 'sqrt',
|
'sin', 'cos', 'tan', 'atan', 'exp', 'int', 'hex', 'oct', 'log', 'sqrt',
|
||||||
'floor', 'ceil', 'asin', 'acos', 'log10', 'sinh', 'cosh', 'tanh', 'abs',
|
'floor', 'ceil', 'asin', 'acos', 'log10', 'sinh', 'cosh', 'tanh', 'abs',
|
||||||
'pi'
|
'pi', 'deg2rad', 'rad2deg', 'atan2'
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($#ARGV < 0)
|
if ($#ARGV < 0)
|
||||||
@ -18,11 +18,12 @@ if ($#ARGV < 0)
|
|||||||
|
|
||||||
$arguments = join(' ', @ARGV);
|
$arguments = join(' ', @ARGV);
|
||||||
|
|
||||||
if($arguments =~ m/([\$`\|])/) {
|
if($arguments =~ m/([\$`\|{}"'#@=])/) {
|
||||||
$invalid = $1;
|
$invalid = $1;
|
||||||
} else {
|
} else {
|
||||||
while($arguments =~ /([a-zA-Z]+)/g) {
|
while($arguments =~ /([a-zA-Z0-9]+)/g) {
|
||||||
my $keyword = $1;
|
my $keyword = $1;
|
||||||
|
next if $keyword =~ m/^[0-9]$/;
|
||||||
$invalid = $keyword and last if not grep { /^$keyword$/ } @valid_keywords;
|
$invalid = $keyword and last if not grep { /^$keyword$/ } @valid_keywords;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,12 +33,13 @@ if($invalid) {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = eval("use POSIX qw/ceil floor/; use Math::Complex;" . $arguments);
|
$response = eval("use POSIX qw/ceil floor/; use Math::Trig; use Math::Complex;" . $arguments);
|
||||||
|
|
||||||
if($@) {
|
if($@) {
|
||||||
my $error = $@;
|
my $error = $@;
|
||||||
$error =~ s/ at \(eval \d+\) line \d+.//;
|
$error =~ s/ at \(eval \d+\) line \d+.//;
|
||||||
$error =~ s/[\n\r]+//g;
|
$error =~ s/[\n\r]+//g;
|
||||||
|
$error =~ s/Died at .*//;
|
||||||
print $error;
|
print $error;
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user