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:
parent
0c0b2e7836
commit
0655598d4a
@ -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.";
|
||||
|
||||
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 =~ s/[\n\r]+/ /g;
|
||||
$result =~ s/\s+/ /g;
|
||||
|
||||
$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");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user