]> ruin.nu Git - NDIRC.git/commitdiff
Split long lines, using the algorithm from irssi splitlong.pl
authorMichael Andreen <harv@ruin.nu>
Thu, 20 Aug 2009 14:22:52 +0000 (16:22 +0200)
committerMichael Andreen <harv@ruin.nu>
Thu, 20 Aug 2009 14:44:58 +0000 (16:44 +0200)
Context.pm

index 02aac95a7ba84819a49e6713acc7c241bec48d85..8a0a911a3b2abbaca49a0e8995dc853540c8b19d 100644 (file)
@@ -107,6 +107,29 @@ sub message {
        $msg =~ s`<b>(.*?)</b>`${\(chr(2))}$1${\(chr(15))}`gi;
        $msg =~ s`<c(\d+)>(.*?)</c>`${\(chr(3))}$1$2${\(chr(15))}`gi;
 
+       #Split the message, using the, slightly modified, algorithm from splitlong.pl in the irssi distribution.
+       if ($command eq 'privmsg'){
+               my $lend = ' ...';
+               my $lstart = '... ';
+               my $maxlength = $self->server->{msg_length} - bytes::length("privmsg $target :" . $self->server->nick_name());
+               my $maxlength2 = $maxlength - bytes::length($lend);
+
+               if (bytes::length($msg) > ($maxlength)) {
+                       my @spltarr;
+
+                       while (bytes::length($msg) > ($maxlength)) {
+                               my $pos = rindex($msg, " ", $maxlength2);
+                               push @spltarr, substr($msg, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2  : $pos)  . $lend;
+                               $msg = $lstart . substr($msg, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
+                       }
+
+                       push @spltarr, $msg;
+                       for (@spltarr) {
+                               $self->command($command, $target, $_);
+                       }
+                       return;
+               }
+       }
        $self->command($command, $target, $msg);
 }