From 51b1b25b16be934c9a2151d07c403b6ced07baef Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 20 Nov 2017 16:10:48 -0800 Subject: [PATCH] Add `debugcontext` registry item for $stuff dumps --- PBot/Commands.pm | 11 ++++++----- PBot/FactoidModuleLauncher.pm | 13 +++++++++++-- PBot/Factoids.pm | 25 ++++++++++++------------- PBot/Interpreter.pm | 33 ++++++++++++++++++--------------- 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/PBot/Commands.pm b/PBot/Commands.pm index d217516b..31823d38 100644 --- a/PBot/Commands.pm +++ b/PBot/Commands.pm @@ -88,13 +88,14 @@ sub exists { sub interpreter { my ($self, $stuff) = @_; - #my ($from, $nick, $user, $host, $depth, $keyword, $arguments, $tonick, $unused, $referenced, $root_keyword) = @_; my $result; - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Commands::interpreter\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Commands::interpreter\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } my $admin = $self->{pbot}->{admins}->loggedin($stuff->{from}, "$stuff->{nick}!$stuff->{user}\@$stuff->{host}"); my $level = defined $admin ? $admin->{level} : 0; diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index dc41f6e0..ec58e50c 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -44,10 +44,16 @@ sub initialize { } sub execute_module { -# my ($self, $from, $tonick, $nick, $user, $host, $command, $root_channel, $root_keyword, $keyword, $arguments, $preserve_whitespace, $referenced) = @_; my ($self, $stuff) = @_; my $text; + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("FML::execute_module\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } + $stuff->{arguments} = "" if not defined $stuff->{arguments}; my @factoids = $self->{pbot}->{factoids}->find_factoid($stuff->{from}, $stuff->{keyword}, undef, 2, 2); @@ -174,7 +180,10 @@ sub execute_module { sub module_pipe_reader { my ($self, $buf) = @_; - my $stuff = decode_json $buf or return; + my $stuff = decode_json $buf or do { + $self->{pbot}->{logger}->log("Failed to decode bad json: [$buf]\n"); + return; + }; if (not defined $stuff->{result} or not length $stuff->{result}) { $self->{pbot}->{logger}->log("No result from module.\n"); diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 0d183c50..46334789 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -715,16 +715,14 @@ sub execute_code_factoid { sub interpreter { my ($self, $stuff) = @_; -=cut - my $self = shift; - my ($from, $nick, $user, $host, $depth, $keyword, $arguments, $tonick, $ref_from, $referenced, $root_keyword) = @_; -=cut my $pbot = $self->{pbot}; - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Factoids::interpreter\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Factoids::interpreter\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } #$self->{pbot}->{logger}->log("enter factoid interpreter [$keyword][" . (defined $arguments ? $arguments : '') . "] referenced = $referenced\n"); return undef if not length $stuff->{keyword} or $stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'); @@ -855,13 +853,14 @@ sub interpreter { } sub handle_action { -# my ($self, $nick, $user, $host, $from, $channel, $root_keyword, $keyword, $arguments, $action, $tonick, $depth, $referenced, $ref_from, $original_keyword) = @_; my ($self, $stuff, $action) = @_; - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Factoids::handle_action [$action]\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Factoids::handle_action [$action]\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } return "" if not length $action; diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 8653bc16..559bf7d6 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -203,17 +203,18 @@ sub process_line { sub interpret { my ($self, $stuff) = @_; -# my ($from, $nick, $user, $host, $depth, $command, $tonick, $referenced, $root_keyword) = @_; my ($keyword, $arguments) = ("", ""); my $text; my $pbot = $self->{pbot}; $pbot->{logger}->log("=== Enter interpret_command: [" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "][$stuff->{nick}!$stuff->{user}\@$stuff->{host}][$stuff->{interpret_depth}][$stuff->{command}]\n"); - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Interpreter::interpret\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Interpreter::interpret\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } return "Too many levels of recursion, aborted." if(++$stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion')); @@ -335,14 +336,15 @@ sub truncate_result { sub handle_result { my ($self, $stuff, $result) = @_; -# my ($self, $from, $nick, $user, $host, $text, $command, $result, $checkflood, $preserve_whitespace) = @_; $stuff->{preserve_whitespace} = 0 if not defined $stuff->{preserve_whitespace}; - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Interpreter::handle_result [$result]\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Interpreter::handle_result [$result]\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } $result = $stuff->{result} if not defined $result; @@ -462,13 +464,14 @@ sub handle_result { sub output_result { my ($self, $stuff) = @_; -# my ($self, $from, $nick, $user, $host, $command, $line, $checkflood) = @_; my ($pbot, $botnick) = ($self->{pbot}, $self->{pbot}->{registry}->get_value('irc', 'botnick')); - use Data::Dumper; - $Data::Dumper::Sortkeys = 1; - $self->{pbot}->{logger}->log("Interpreter::output_result\n"); - $self->{pbot}->{logger}->log(Dumper $stuff); + if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) { + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $self->{pbot}->{logger}->log("Interpreter::output_result\n"); + $self->{pbot}->{logger}->log(Dumper $stuff); + } my $line = $stuff->{line};