aboutsummaryrefslogtreecommitdiffstats
path: root/docs/Irssi.pm
blob: a741b2e7ba3b14faabd9d0f55525c2661da61bdf (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
__END__

=head1 NAME

Irssi.pm

=head1 DESCRIPTION

L<Irssi|http://irssi.org> is a console based fullscreen IRC client.  It is
written in the C programming language, and can be modified through both
I<Modules> -- dynamically loadable compiled libraries -- and I<Scripts>, written
in L<Perl|http://perl.org>.

Modules are not covered in this documentation, other than to note that Perl
scripting support itself may be compiled as a module rather than built directly
into Irssi.  The C</LOAD> command can be used from within Irssi to check if Perl
support is available. If not, refer to the F<INSTALL> file for how to recompile
irssi.

The C<Irssi> package is the basis of Perl scripting in Irssi. It does not export any
functions, and requires that all function-calls be fully qualified with the
C<Irssi::I<cmd>> prefix.

=head1 CLASSES

This documentation has been split into a number of pages, each documenting a
particular class or pseudo-class.  The following list contains all of these
additional pages.

=over 4

=item L<Irssi::Ban>

=item L<Irssi::Chatnet>

=item L<Irssi::Chatnet>

=item L<Irssi::Client>

=item L<Irssi::Command>

=item L<Irssi::Dcc>

=item L<Irssi::Ignore>

=item L<Irssi::Log>

=item L<Irssi::Logitem>

=item L<Irssi::Nick>

=item L<Irssi::Notifylist>

=item L<Irssi::Process>

=item L<Irssi::Query>

=item L<Irssi::Rawlog>

=item L<Irssi::Reconnect>

=item L<Irssi::Script>

=item L<Irssi::Server>

=item L<Irssi::Theme>

=item L<Irssi::Window>

=item L<Irssi::Windowitem>

=back

=head1 METHODS

=head2 Accessors

=head3 active_win

C<my $win = Irssi::active_win();>

returns the currently active L<Irssi::Window>

=head3 active_server

C<my $server = Irssi::active_server();>

returns the currently active L<Irssi::Server> in active window.

=head3 windows

returns a list of all L<windows|Irssi::Window>.

=head3 servers

returns a list of all L<servers|Irssi::Server>.

=head3 reconnects

returns a list of all L<server reconnections|Irssi::Reconnect>.

=head3 channels

returns a list of all L<channels|Irssi::Channel>.

=head3 queries

returns a list of all L<queries|Irssi::Query>.

=head3 commands

returns a list of all L<commands|Irssi::Command>.

=head3 logs

returns a list of all L<log files|Irssi::Log>.

=head3 ignores

returns a list of all L<ignores|Irssi::Ignore>.

=head3 dccs

returns a list of all L<DCC connections|Irssi::Dcc>

=head2 Signals

See also L<Signals>

Irssi is pretty much based on sending and handling different signals.
Like when you receive a message from server, say:

C<:nick!user@there.org PRIVMSG you :blahblah>

Irssi will first send a signal:

C<"server incoming", SERVER_REC, "nick!user@there PRIVMSG ...">

You probably don't want to use this signal. Default handler for this
signal interprets the header and sends a signal:

C<"server event", Irssi::Server, "PRIVMSG ...", "nick", "user@there.org">

You probably don't want to use this either, since this signal's default
handler parses the event string and sends a signal:

C<"event privmsg", Irssi::Server, "you :blahblah", "nick", "user@there.org">

You can at any point grab the signal, do whatever you want to do with
it and optionally stop it from going any further by calling
L<Irssi::signal_stop|Irssi/signal_stop>

For example:

    sub event_privmsg {
        # $data = "nick/#channel :text"
        my ($server, $data, $nick, $address) = @_;
        my ($target, $text) = split(/ :/, $data, 2);

        Irssi::signal_stop() if ($text =~ /free.*porn/ || $nick =~ /idiot/);
    }

    Irssi::signal_add("event privmsg", "event_privmsg");

This will hide all public or private messages that match the regexp
C<"free.*porn"> or the sender's nick contain the word "idiot". Yes, you
could use /IGNORE instead for both of these C<:)>

You can also use L<Irssi::signal_add_last|/signal_add_last> if you wish to let the
Irssi's internal functions be run before yours.

A list of signals that irssi sends can be found in the L<Signals> documentation.




=head3 Handling Signals

=head4 C<signal_add $sig_name, $func>

Bind C<$sig_name> to function C<$func>. The C<$func> argument may be either
a string containing the name of a function to call, or a coderef.

For example:

    Irssi::signal_add("default command", sub { ... });

    Irssi::signal_add("default command", "my_function");

    Irssi::signal_add("default command", \&my_function);

In all cases, the specified function will be passed arguments in C<@_> as specified
in L<Signals>.

=head4 C<signal_add_first $sig_name, $func>

Bind C<$sig_name> to function C<$func>. Call C<$func> as soon as possible when
the signal is raised.

=head4 C<signal_add_last $sig_name, $func>

Bind C<$sig_name> to function C<$func>. Call C<$func> as late as possible (after
all other signal handlers).

=head4 C<signal_remove $sig_name, $func>

Unbind C<$sig_name> from function C<$func>.
B<TODO: Can you unbind a signal from a C<sub { ...}> coderef? What happens?>


=head3 Controlling Signal Propagation

=head4 C<signal_emit $sig_name, @params>

Send a signal of type C<$sig_name>. Up to 6 parameters can be passed in C<@params>.

=head4 C<signal_continue @params>

Propagate a currently emitted signal, but with different parameters.  This only
needs to be called if you wish to change them, otherwise all subsequent handlers
will be invoked as normal.

B<Should only be called from within a signal handler>

=head4 C<signal_stop>

Stop the signal that's currently being emitted, no other handlers after this one will
be called.

=head4 C<signal_stop_by_name $sig_name>

Stop the signal with name C<$sig_name> that is currently being emitted.

=head3 Registering New Signals

=head4 C<signal_register $hashref>

Register parameter types for one or more signals.  C<$hashref> must map one or
more signal names to references to arrays containing 0 to 6 type names. Some
recognized type names include int for integers, intptr for references to
integers and string for strings. For all standard signals see
F<src/perl/perl-signals-list.h> in the source code (this is generated by
F<src/perl/get-signals.pl>).

For example:

    my $signal_config_hash = { "new signal" => [ qw/string string integer/ ] };
    Irssi::signal_register($signal_config_hash);

Any signals that were already registered are unaffected.

B<Signals are not persistent.>  Once registered, a signal cannot be unregistered without
restarting Irssi. B<TODO: True?>, including modifying the type signature.

Registration is required to get any parameters to signals written in
Perl and to emit and continue signals from Perl.

B<TODO: What are the complete list of recognised types?>




=head2 Commands

See also L<Irssi::Command>

=head3 Registering Commands

=head4 C<command_bind $cmd, $func, $category

Bind a command string C<$cmd> to call function C<$func>. C<$func> can be
either a string or coderef. C<$category> is an optional string specifying
the category to display the command in when C</HELP> is used.

=head4 C<command_runsub $cmd, $data, $server, $item>

Run subcommands for `cmd'. First word in `data' is parsed as
subcommand. `server' is L<Irssi::Server> record for current
L<Irssi::Windowitem> `item'.

Call command_runsub in handler function for `cmd' and bind
with command_bind("`cmd' `subcmd'", subcmdfunc[, category]);

B<TODO: example here>

=head4 C<command_unbind $cmd, $func>

Unbind command C<$cmd> from function C<$func>.

=head3 Invoking Commands

=head4 C<command $string>

Run the command specified in C<$string> in the currently active context.

B<TODO: passing args in C<@_> vs concatenating into the command string?>

See also L<Irssi::Server/command $string>

=head3 Parsing Command Arguments

=head4 C<command_set_options(cmd, data)>

Set options for command `cmd' to `data'. `data' is a string of
space separated words which specify the options. Each word can be
optionally prefixed with one of the following character:

=over

=item  '-': optional argument

=item   '+': argument required

=item   '@': optional numeric argument

=back

=head4 C<command_parse_options(cmd, data)>

Parse options for command `cmd' in `data'. It returns a reference to
an hash table with the options and a string with the remaining part
of `data'. On error it returns the undefined value.



=head2 Settings


=head3 Creating New Settings

=head4 C<settings_add_str(section, key, def)>

=head4 C<settings_add_int(section, key, def)>

=head4 C<settings_add_bool(section, key, def)>

=head4 C<settings_add_time(section, key, def)>

=head4 C<settings_add_level(section, key, def)>

=head4 C<settings_add_size(section, key, def)>


=head3 Retrieving Settings

=head4 C<settings_get_str($key)>

=head4 C<settings_get_int($key)>

=head4 C<settings_get_bool($key)>

=head4 C<settings_get_time($key)>

=head4 C<settings_get_level($key)>

=head4 C<settings_get_size($key)>

=head3 Modifying Settings

Set value for setting.

B<If you change the settings of another module/script with one of these, you
must emit a C<"setup changed"> signal afterwards.>

=head4 C<settings_set_str(key, value)>

=head4 C<settings_set_int(key, value)>

=head4 C<settings_set_bool(key, value)>

=head4 C<settings_set_time(key, value)>

=head4 C<settings_set_level(key, value)>

=head4 C<settings_set_size(key, value)>

=head4 C<settings_remove(key)>

Remove a setting.


=head2 IO and Process Management

timeout_add(msecs, func, data)
  Call `func' every `msecs' milliseconds (1000 = 1 second) with
  parameter `data'. Returns tag which can be used to stop the timeout.

timeout_add_once(msecs, func, data);
  Call `func' once after `msecs' milliseconds (1000 = 1 second)
  with parameter `data'. Returns tag which can be used to stop the timeout.

timeout_remove(tag)
  Remove timeout with tag.

input_add(source, condition, func, data)
  Call `func' with parameter `data' when specified IO happens.
  `source' is the file handle that is being listened. `condition' can
  be INPUT_READ, INPUT_WRITE or both. Returns tag which can be used to
  remove the listener.

input_remove(tag)
  Remove listener with tag.

pidwait_add(pid)
  Adds `pid' to the list of processes to wait for. The pid must identify
  a child process of the irssi process. When the process terminates, a
  "pidwait" signal will be sent with the pid and the status from
  waitpid(). This is useful to avoid zombies if your script forks.

pidwait_remove(pid)
  Removes `pid' from the list of processes to wait for. Terminated
  processes are removed automatically, so it is usually not necessary
  to call this function.



=head2 Message Levels

level2bits(level)
  Level string -> number

bits2level(bits)
  Level number -> string

combine_level(level, str)
  Combine level number to level string ("+level -level").
  Return new level number.


=head2 Themes

See also L<Irssi::Theme>

You can have user configurable texts in scripts that work just like
irssi's internal texts that can be changed in themes.

First you'll have to register the formats:


Irssi::theme_register([
  'format_name', '{hilight my perl format!}',
  'format2', 'testing.. nick = $0, channel = $1'
]);

Printing happens with one of the functions:

printformat(level, format, ...)
Window::printformat(level, format, ...)
Server::printformat(target, level, format, ...)
Windowitem::printformat(level, format, ...)

For example:

  $channel->printformat(MSGLEVEL_CRAP, 'format2',
		        'nick', $channel->{name});


=head2 DCC

See also L<Irssi::Dcc>

Dcc
dcc_find_item(type, nick, arg)
  Find DCC connection.

Dcc
dcc_find_by_port(nick, port)
  Find DCC connection by port.


=head2 Channels

Channel
channel_find(channel)
  Find channel from any server.

=head2 Ignores


ignore_add_rec(ignore)
  Add ignore record.

ignore_update_rec(ignore)
  Update ignore record in configuration

ignore_check(nick, host, channel, text, level)

=head2 Logging


Log
log_create_rec(fname, level)
  Create log file.


Log
log_find(fname)
  Find log with file name.

=head2 Raw Logging

Rawlog rawlog_create()
  Create a new rawlog.

rawlog_set_size(lines)
  Set the default rawlog size for new rawlogs.

=head2 Chat-Nets

chatnet_find(name)
  Find chat network with name.


=head1 COPYRIGHT

All the content of this site is copyright © 2000-2010 The Irssi project.

Formatting to POD and linking by Tom Feist
 L<shabble+irssi@metavore.org|mailto:shabble+irssi@metavore.org>