summaryrefslogtreecommitdiffstats
path: root/scripts/autowrap.pl
blob: c110c91c54b2a72ba523a13a3330169fa69bc9d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use strict;
use Text::Wrap;

use vars qw($VERSION %IRSSI);
$VERSION = '2007031900';
%IRSSI = (
	authors		=> 'Bitt Faulk',
	contact		=> 'lxsfx3h02@sneakemail.com',
	name		=> 'autowrap',
	description	=> 'Automatically wraps long sent messages into multiple shorter sent messages',
	license		=> 'BSD',
	url		=> 'none',
	modules		=> 'Text::Wrap',
);

sub event_send_text () {
	my ($line, $server_rec, $wi_item_rec) = @_;
	my @shortlines;
	if (length($line) <= 400) {
		return;
	} else {
		# split line, recreate multiple "send text" events
		local($Text::Wrap::columns) = 400;
		@shortlines = split(/\n/,wrap('','',$line));
		foreach (@shortlines) {
			if ($_ >= 400) {
				Irssi::print("autowrap: unable to split long line.  sent as-is");
				return;
			}
		}
		foreach (@shortlines) {
			Irssi::signal_emit('send text', $_,  $server_rec, $wi_item_rec);
		}
		Irssi::signal_stop();
	}
}

Irssi::signal_add_first('send text', "event_send_text");