1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-23 06:35:36 +00:00
irssi/scripts/splitlong.pl
Timo Sirainen 1ec1cb8382 updated
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2577 dbcabf3a-b0e7-0310-adc4-f8d773084564
2002-03-11 04:21:01 +00:00

53 lines
1.6 KiB
Perl

# /set splitlong_max_length
# specifies the maximum length of a msg, automatically chosen when set to "0"
###
use strict;
use vars qw($VERSION %IRSSI);
#don't know which version exactly, probably even works with 0.7.98.4
use Irssi 20011001;
$VERSION = "0.17";
%IRSSI = (
authors => "Bjoern \'fuchs\' Krombholz",
contact => "bjkro\@gmx.de",
name => "splitlong",
licence => "Public Domain",
description => "Split overlong PRIVMSGs to msgs with length allowed by ircd",
changed => "Wed Mar 8 03:03:10 CET 2002",
changes => "fixed some strange bug, depends on new switches to msg command (-nick|-channel)"
);
sub sig_command_msg {
my ($cmd, $server, $winitem, $TEST) = @_;
my ($type, $target, $data) = $cmd =~ /^(\S*)\s(\S*)\s(.*)/;
my $maxlength = Irssi::settings_get_int('splitlong_max_length');
if ($maxlength == 0) {
# 497 = 510 - length(":" . "!" . " PRIVMSG " . " :");
$maxlength = 497 - length($server->{nick} . $server->{userhost} . $target);
}
my $maxlength2 = $maxlength - length("... ");
if (length($data) > ($maxlength)) {
my @spltarr;
while (length($data) > ($maxlength2)) {
my $pos = rindex($data, " ", $maxlength2);
push @spltarr, substr($data, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos) . " ...";
$data = "... " . substr($data, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
}
push @spltarr, $data;
foreach (@spltarr) {
Irssi::signal_emit("command msg", "$type $target $_", $server, $winitem);
}
Irssi::signal_stop();
}
}
Irssi::settings_add_int('misc', 'splitlong_max_length', 0);
Irssi::command_bind('msg', 'sig_command_msg');