From 716db7066470be8e0133c45adb1a3bcb123a9f2b Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 18 Aug 2017 00:53:12 -0700 Subject: [PATCH] Add `eval` command to evaluate arbitrary bot code (level 99+ admins only) --- PBot/BotAdminCommands.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PBot/BotAdminCommands.pm b/PBot/BotAdminCommands.pm index bb1d86c1..265da55a 100644 --- a/PBot/BotAdminCommands.pm +++ b/PBot/BotAdminCommands.pm @@ -51,6 +51,7 @@ sub initialize { $pbot->{commands}->register(sub { return $self->sl(@_) }, "sl", 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->evalcmd(@_) }, "eval", 99); } 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 { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_;