3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

Add eval command to evaluate arbitrary bot code (level 99+ admins only)

This commit is contained in:
Pragmatic Software 2017-08-18 00:53:12 -07:00
parent f9fbae2663
commit 716db70664

View File

@ -51,6 +51,7 @@ sub initialize {
$pbot->{commands}->register(sub { return $self->sl(@_) }, "sl", 90); $pbot->{commands}->register(sub { return $self->sl(@_) }, "sl", 90);
$pbot->{commands}->register(sub { return $self->export(@_) }, "export", 90); $pbot->{commands}->register(sub { return $self->export(@_) }, "export", 90);
$pbot->{commands}->register(sub { return $self->reload(@_) }, "reload", 90); $pbot->{commands}->register(sub { return $self->reload(@_) }, "reload", 90);
$pbot->{commands}->register(sub { return $self->evalcmd(@_) }, "eval", 99);
} }
sub sl { sub sl {
@ -245,6 +246,24 @@ sub export {
} }
} }
sub evalcmd {
my ($self, $from, $nick, $user, $host, $arguments) = @_;
$self->{pbot}->{logger}->log("[$from] $nick!$user\@$host Evaluating [$arguments]\n");
my $ret;
my $result = eval $arguments;
if ($@) {
if (length $result) {
$ret .= "[Error: $@] ";
} else {
$ret .= "Error: $@";
}
$ret =~ s/ at \(eval \d+\) line 1.//;
}
return "$ret $result";
}
sub reload { sub reload {
my $self = shift; my $self = shift;
my ($from, $nick, $user, $host, $arguments) = @_; my ($from, $nick, $user, $host, $arguments) = @_;