X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Context.pm;h=8a0a911a3b2abbaca49a0e8995dc853540c8b19d;hb=82c9be26b28b12fded144d363ef81a6047e20d11;hp=abe59b24cf538b477f794153241a11649a1865b7;hpb=ae37bc6b64270f8c65298a36fce1f4bad761231f;p=NDIRC.git diff --git a/Context.pm b/Context.pm index abe59b2..8a0a911 100644 --- a/Context.pm +++ b/Context.pm @@ -97,16 +97,46 @@ sub check_user_roles { sub reply { my ($self,$msg) = @_; - $self->message($self->reply_string , $msg); + my @command = split / /, $self->reply_string; + $self->message(@command, $msg); } sub message { - my ($self,$command,$msg) = @_; + my ($self,$command, $target, $msg) = @_; $msg =~ s`(.*?)`${\(chr(2))}$1${\(chr(15))}`gi; $msg =~ s`(.*?)`${\(chr(3))}$1$2${\(chr(15))}`gi; - $self->server->command("$command $msg"); + #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); +} + +sub command { + my ($self,@command) = @_; + + $self->server->yield(@command); } sub intel_log {