1use strict;
2use Irssi;
3use vars qw($VERSION %IRSSI);
4
5$VERSION = '0.1';
6%IRSSI = (
7    authors     => 'Kimmo Lehto',
8    contact     => 'kimmo@a-men.org' ,
9    name        => 'Paste-KimmoKe',
10    description => 'Provides /start, /stop, /play <-nopack> <-nospace> paste mechanism - start and stop recording and then replay without linebreaks. Also /see to view what was recorded.',
11    license     => 'Public Domain',
12    changed	=> 'Wed Mar 27 14:51 EET 2002'
13);
14
15my $_active = undef;
16my @_record = undef;
17my $_recorded_stuff = undef;
18my $_nospace = undef;
19my $_nopack = undef;
20
21sub cmd_start
22{
23	my ($arg, $server, $witem) = @_;
24
25	if ($_active)
26	{
27		Irssi::print("ERROR - Already recording.");
28		return 0;
29	}
30
31	$_active = 1;
32	Irssi::print("Recording, enter /stop to end...");
33	@_record = ();
34	Irssi::signal_add_first("send text", "record");
35}
36
37sub cmd_stop
38{
39	my ($arg, $server, $witem) = @_;
40
41	if (!$_active)
42	{
43		Irssi::print("ERROR - Not recording.");
44		return 0;
45	}
46
47	$_active = undef;
48	Irssi::signal_remove("send text", "record");
49
50	Irssi::print('Recording ended. ' . ($#_record + 1) . ' lines captured. Use /see to see and /play to play recording without linefeeds (-help for reformatting options).');
51}
52
53sub record {
54        my ($data) = @_;
55	push @_record, $data;
56	Irssi::signal_stop();
57}
58
59
60
61sub reformat {
62	my ($arg) = @_;
63	my $data;
64
65        if ($arg =~ /\-nospace/)
66        {
67		$data = join("", @_record);
68        }
69	else
70	{
71		$data = join(" ", @_record);
72	}
73        if ($arg !~ /\-nopack/)
74        {
75		$data =~ s/\s+|\t+/ /g;
76	}
77        if ($arg =~ /help/i)
78        {
79                return("You can use -nospace if you wish to join the input lines without replacing linefeeds with spaces, or -nopack if you don\'t want to replace multiple spaces with only one space.");
80        }
81	return $data;
82}
83
84sub cmd_see {
85        my ($arg, $server, $witem) = @_;
86
87	@_record && Irssi::print(reformat($arg));
88	Irssi::print("End of recorded input.");
89}
90
91sub cmd_play {
92	my ($arg, $server, $witem) = @_;
93	if ($arg =~ /help/i) { Irssi::print(reformat($arg)); return 0; }
94	if (@_record)
95	{
96		Irssi::signal_emit("send text", reformat($arg), $server, $witem);
97	}
98	else
99	{
100		Irssi::print("ERROR - Nothing to play.");
101	}
102}
103
104Irssi::command_bind('start', 'cmd_start');
105Irssi::command_bind('stop', 'cmd_stop');
106Irssi::command_bind('see', 'cmd_see');
107Irssi::command_bind('play', 'cmd_play');
108
109
110
111