3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

interpreter: improved long message truncation semantics

This commit is contained in:
Pragmatic Software 2011-02-10 07:10:50 +00:00
parent 0c0b2e7836
commit 0655598d4a
2 changed files with 14 additions and 14 deletions

View File

@ -107,20 +107,20 @@ sub process_line {
}
if(defined $result && length $result > 0) {
my $len = length $result;
if($len > $pbot->max_msg_len) {
my $link = paste_codepad("[$from] <$nick> $text\n\n$result");
my $trunc = "... truncated; see $link for full text.";
$pbot->logger->log("Message truncated -- pasted to $link\n");
$result =~ s/[\n\r]+/ /g;
$result =~ s/\s+/ /g;
my $original_result = $result;
$result =~ s/[\n\r]+/ /g;
$result =~ s/\s+/ /g;
if(length $result > $pbot->max_msg_len) {
my $link = paste_codepad("[$from] <$nick> $text\n\n$original_result");
my $trunc = "... [truncated; see $link for full text.]";
$pbot->logger->log("Message truncated -- pasted to $link\n");
$result = substr($result, 0, $pbot->max_msg_len);
substr($result, $pbot->max_msg_len - length $trunc) = $trunc;
} else {
$result =~ s/[\n\r]+/ /g;
$result =~ s/\s+/ /g;
my $trunc_len = length $result < $pbot->max_msg_len ? length $result : $pbot->max_msg_len;
$result = substr($result, 0, $trunc_len);
substr($result, $trunc_len - length $trunc) = $trunc;
}
$pbot->logger->log("Final result: $result\n");

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 302,
BUILD_DATE => "2011-02-07",
BUILD_REVISION => 1,
BUILD_DATE => "2011-02-09",
};
1;