From 5c43b464776d0c868c9e3a1056f05eaacce79425 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 4 Aug 2021 18:50:07 -0700 Subject: [PATCH] Plugin/RunCommand: improve pumping and handle lines longer than maximum IRC mesasge length --- lib/PBot/Plugin/RunCommand.pm | 24 ++++++++++++++++-------- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/PBot/Plugin/RunCommand.pm b/lib/PBot/Plugin/RunCommand.pm index 5ea47637..528bac24 100644 --- a/lib/PBot/Plugin/RunCommand.pm +++ b/lib/PBot/Plugin/RunCommand.pm @@ -55,24 +55,32 @@ sub cmd_runcmd { my $lines = 0; while (pump $h) { - if ($out =~ s/^(.*?)\n//) { - $self->{pbot}->{conn}->privmsg($context->{from}, $1); - $lines++; - } + $lines += $self->send_lines($context, \$out); } finish $h; - if (length $out) { - my @lines = split /\n/, $out; + $lines += $self->send_lines($context, \$out); - foreach my $line (@lines) { + return "No output." if not $lines; +} + +sub send_lines { + my ($self, $context, $buffer) = @_; + + my ($line, $lines); + + while ($$buffer =~ s/(.{1,370})//) { + $line = $1; + $line =~ s/^\s+|\s+$//g; + + if (length $line) { $self->{pbot}->{conn}->privmsg($context->{from}, $line); $lines++; } } - return "No output." if not $lines; + return $lines; } 1; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index e08ff03c..caada57c 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4340, - BUILD_DATE => "2021-08-02", + BUILD_REVISION => 4341, + BUILD_DATE => "2021-08-04", }; sub initialize {}