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