3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 10:59:29 +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) { if(defined $result && length $result > 0) {
my $len = length $result;
if($len > $pbot->max_msg_len) { my $original_result = $result;
my $link = paste_codepad("[$from] <$nick> $text\n\n$result");
my $trunc = "... truncated; see $link for full text."; $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"); $pbot->logger->log("Message truncated -- pasted to $link\n");
$result =~ s/[\n\r]+/ /g; my $trunc_len = length $result < $pbot->max_msg_len ? length $result : $pbot->max_msg_len;
$result =~ s/\s+/ /g; $result = substr($result, 0, $trunc_len);
substr($result, $trunc_len - length $trunc) = $trunc;
$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;
} }
$pbot->logger->log("Final result: $result\n"); $pbot->logger->log("Final result: $result\n");

View File

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