From acc88ac049851a1218ac7515e268af81ef6f6a05 Mon Sep 17 00:00:00 2001 From: Gregory Bartholomew Date: Jan 16 2022 18:32:58 +0000 Subject: Make zinebot output zodbot commands on separate lines --- diff --git a/bot/commands/matrix.pm b/bot/commands/matrix.pm index c4dd67e..2397127 100644 --- a/bot/commands/matrix.pm +++ b/bot/commands/matrix.pm @@ -107,18 +107,44 @@ sub event_handler { } } + # $ret may or may not be a String::Tagged object; + # use the 'ref' command to check if (length $ret) { - my $msg = build_formatted_message $ret; + my $reg = qr{^\#}m; + my @txt = (ref $ret) ? $ret->split($reg) : split($reg, $ret); + + # reprefix the delimiter that was removed by the above split; + # be careful to preserve String::Tagged objects + my $shift = sub { + my $txt = shift @{$_[0]}; + + if (ref $txt) { + $txt->insert(0, '#'); + } elsif (defined $txt) { + $txt = '#' . $txt; + } - # colorize some things and fix line endings - colorize(\$msg->{'formatted_body'}); - $msg->{'formatted_body'} =~ s{^\x{2015}$}{
}gm; - $msg->{'formatted_body'} =~ s{\n}{\x{200b}
}g; + return $txt; + }; - $self->send_message( - 'type' => 'm.text', - %{ $msg }, - ); + # if the first item is the empty string, $ret started with $reg + my $txt = shift @txt || $shift->(\@txt); + while (defined $txt) { + my $msg = build_formatted_message $txt; + my $bdy = \$msg->{'formatted_body'}; + + # colorize some things and fix line endings + colorize($bdy); + $$bdy =~ s{^\x{2015}$}{
}gm; + $$bdy =~ s{\n}{\x{200b}
}g; + + $self->send_message( + 'type' => 'm.text', + %{ $msg }, + ); + + $txt = $shift->(\@txt); + } } }