3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-05 19:49:32 +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;
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;

View File

@ -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 {}