2002-03-10 16:28:38 -05:00
|
|
|
# /set splitlong_max_length
|
|
|
|
# specifies the maximum length of a msg, automatically chosen when set to "0"
|
2005-08-15 18:32:26 -04:00
|
|
|
# default: 0
|
|
|
|
#
|
|
|
|
# /set splitlong_line_start
|
|
|
|
# /set splitlong_line_end
|
|
|
|
# self-explanatory
|
|
|
|
# defaults: "... ", " ..."
|
2002-03-10 16:28:38 -05:00
|
|
|
###
|
|
|
|
use strict;
|
|
|
|
use vars qw($VERSION %IRSSI);
|
|
|
|
|
|
|
|
use Irssi 20011001;
|
|
|
|
|
2005-08-15 18:32:26 -04:00
|
|
|
$VERSION = "0.20";
|
2002-03-10 16:28:38 -05:00
|
|
|
%IRSSI = (
|
|
|
|
authors => "Bjoern \'fuchs\' Krombholz",
|
|
|
|
contact => "bjkro\@gmx.de",
|
|
|
|
name => "splitlong",
|
2002-03-10 23:21:01 -05:00
|
|
|
licence => "Public Domain",
|
2002-03-10 16:28:38 -05:00
|
|
|
description => "Split overlong PRIVMSGs to msgs with length allowed by ircd",
|
2005-08-15 18:32:26 -04:00
|
|
|
changed => "Wed Jun 25 00:17:00 CET 2003",
|
|
|
|
changes => "Actually the real 0.19 (now 0.20), but upload didn't work some month ago, target problem fixed..."
|
2002-03-10 16:28:38 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
sub sig_command_msg {
|
2005-08-15 18:32:26 -04:00
|
|
|
my ($cmd, $server, $winitem) = @_;
|
|
|
|
my ( $param, $target,$data) = $cmd =~ /^(-\S*\s)?(\S*)\s(.*)/;
|
|
|
|
|
2002-03-10 16:28:38 -05:00
|
|
|
my $maxlength = Irssi::settings_get_int('splitlong_max_length');
|
2005-08-15 18:32:26 -04:00
|
|
|
my $lstart = Irssi::settings_get_str('splitlong_line_start');
|
|
|
|
my $lend = Irssi::settings_get_str('splitlong_line_end');
|
2002-03-10 16:28:38 -05:00
|
|
|
|
|
|
|
if ($maxlength == 0) {
|
|
|
|
# 497 = 510 - length(":" . "!" . " PRIVMSG " . " :");
|
|
|
|
$maxlength = 497 - length($server->{nick} . $server->{userhost} . $target);
|
|
|
|
}
|
2005-08-15 18:32:26 -04:00
|
|
|
my $maxlength2 = $maxlength - length($lend);
|
2002-03-10 16:28:38 -05:00
|
|
|
|
|
|
|
if (length($data) > ($maxlength)) {
|
|
|
|
my @spltarr;
|
|
|
|
|
|
|
|
while (length($data) > ($maxlength2)) {
|
|
|
|
my $pos = rindex($data, " ", $maxlength2);
|
2005-08-15 18:32:26 -04:00
|
|
|
push @spltarr, substr($data, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos) . $lend;
|
|
|
|
$data = $lstart . substr($data, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
push @spltarr, $data;
|
|
|
|
foreach (@spltarr) {
|
2005-08-15 18:32:26 -04:00
|
|
|
Irssi::signal_emit("command msg", "$target $_", $server, $winitem);
|
2002-03-10 16:28:38 -05:00
|
|
|
}
|
|
|
|
Irssi::signal_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Irssi::settings_add_int('misc', 'splitlong_max_length', 0);
|
2005-08-15 18:32:26 -04:00
|
|
|
Irssi::settings_add_str('misc', 'splitlong_line_start', "... ");
|
|
|
|
Irssi::settings_add_str('misc', 'splitlong_line_end', " ...");
|
2002-03-10 16:28:38 -05:00
|
|
|
Irssi::command_bind('msg', 'sig_command_msg');
|