3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

Plugin/RunCommand: improve pumping and handle lines longer than maximum IRC mesasge length

This commit is contained in:
Pragmatic Software 2021-08-04 18:50:07 -07:00
parent 4c5492f5e9
commit 5c43b46477
2 changed files with 18 additions and 10 deletions

View File

@ -55,24 +55,32 @@ sub cmd_runcmd {
my $lines = 0; my $lines = 0;
while (pump $h) { while (pump $h) {
if ($out =~ s/^(.*?)\n//) { $lines += $self->send_lines($context, \$out);
$self->{pbot}->{conn}->privmsg($context->{from}, $1);
$lines++;
}
} }
finish $h; finish $h;
if (length $out) { $lines += $self->send_lines($context, \$out);
my @lines = split /\n/, $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); $self->{pbot}->{conn}->privmsg($context->{from}, $line);
$lines++; $lines++;
} }
} }
return "No output." if not $lines; return $lines;
} }
1; 1;

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script # These are set by the /misc/update_version script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 4340, BUILD_REVISION => 4341,
BUILD_DATE => "2021-08-02", BUILD_DATE => "2021-08-04",
}; };
sub initialize {} sub initialize {}