mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 04:02:37 +01:00
Add eval
command to evaluate arbitrary bot code (level 99+ admins only)
This commit is contained in:
parent
f9fbae2663
commit
716db70664
@ -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) = @_;
|
||||||
|
Loading…
Reference in New Issue
Block a user