dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

splitlong.pl (1966B)


      1 # /set splitlong_max_length
      2 #   specifies the maximum length of a msg, automatically chosen when set to "0"
      3 #   default: 0
      4 #
      5 # /set splitlong_line_start
      6 # /set splitlong_line_end
      7 #   self-explanatory
      8 #   defaults: "... ", " ..."
      9 ###
     10 use strict;
     11 use vars qw($VERSION %IRSSI);
     12 
     13 use Irssi 20011001;
     14 
     15 $VERSION = "0.20";
     16 %IRSSI = (
     17 	authors     => "Bjoern \'fuchs\' Krombholz",
     18 	contact     => "bjkro\@gmx.de",
     19 	name        => "splitlong",
     20 	license     => "Public Domain",
     21 	description => "Split overlong PRIVMSGs to msgs with length allowed by ircd",
     22 	changed     => "Wed Jun 25 00:17:00 CET 2003",
     23 	changes     => "Actually the real 0.19 (now 0.20), but upload didn't work some month ago, target problem fixed..."
     24 );
     25 
     26 sub sig_command_msg {
     27 	my ($cmd, $server, $winitem) = @_;
     28 	my ( $param, $target,$data) = $cmd =~ /^(-\S*\s)?(\S*)\s(.*)/;
     29     
     30 	my $maxlength = Irssi::settings_get_int('splitlong_max_length');
     31 	my $lstart    = Irssi::settings_get_str('splitlong_line_start');
     32 	my $lend      = Irssi::settings_get_str('splitlong_line_end');
     33 
     34 	if ($maxlength == 0) {
     35 		# 497 = 510 - length(":" . "!" . " PRIVMSG " . " :");
     36 		$maxlength = 497 - length($server->{nick} . $server->{userhost} . $target);
     37 	}
     38 	my $maxlength2 = $maxlength - length($lend);
     39 
     40 	if (length($data) > ($maxlength)) {
     41 		my @spltarr;
     42 
     43 		while (length($data) > ($maxlength2)) {
     44 			my $pos = rindex($data, " ", $maxlength2);
     45 			push @spltarr, substr($data, 0, ($pos < ($maxlength/10 + 4)) ? $maxlength2  : $pos)  . $lend;
     46 			$data = $lstart . substr($data, ($pos < ($maxlength/10 + 4)) ? $maxlength2 : $pos+1);
     47 		}
     48 
     49 		push @spltarr, $data;
     50 		foreach (@spltarr) {
     51 			Irssi::signal_emit("command msg", "$target $_", $server, $winitem);
     52 		}
     53 		Irssi::signal_stop();
     54 	}
     55 }
     56 
     57 Irssi::settings_add_int('misc', 'splitlong_max_length', 0);
     58 Irssi::settings_add_str('misc', 'splitlong_line_start', "... ");
     59 Irssi::settings_add_str('misc', 'splitlong_line_end', " ...");
     60 Irssi::command_bind('msg', 'sig_command_msg');