aboutsummaryrefslogtreecommitdiffstats
path: root/docs/perl.txt
blob: 89588cadd9a1fb6190dac1278eff85eaa57db6b5 (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
 Installation problems
 ---------------------

You'll need to have perl support compiled with irssi. If "/LOAD"
doesn't show perl in list of loaded modules, you have a problem. See
INSTALL file for information about perl problems.


 Running scripts
 ---------------

Scripts are run with /SCRIPT LOAD command, or the default /RUN alias.
"/SCRIPT" shows list of running script, and /SCRIPT UNLOAD can unload
scripts.

Scripts should be placed to ~/.irssi/scripts/ or
/usr/local/lib/irssi/scripts/ (or depending on where irssi was
installed) directories. After that /RUN script_name should work, you
don't need to add the .pl suffix.


 Creating/replacing /COMMANDS
 ----------------------------

You can create your own commands, or replace existing ones with
Irssi::command_bind(). The command handling work internally pretty much
the same as signal handlers, so if you replace existing command and don't
wish to let it run, call Irssi::signal_stop().

Here's an example:

  # Usage: /HELLO [<nick>]
  sub cmd_hello {
    # data - contains the parameters for /HELLO
    # server - the active server in window
    # witem - the active window item (eg. channel, query)
    #         or undef if the window is empty
    my ($data, $server, $witem) = @_;

    if (!$server || !$server->{connected}) {
      Irssi::print("Not connected to server");
      return;
    }

    if ($data) {
      $server->command("MSG $data Hello!");
    } elsif ($witem && ($witem->{type} eq "CHANNEL" ||
                        $witem->{type} eq "QUERY")) {
      # there's query/channel active in window
      $witem->command("MSG ".$witem->{name}." Hello!");
    } else {
      Irssi::print("Nick not given, and no active channel/query in window");
    }
  }

  Irssi::command_bind('hello', 'cmd_hello');


 Message levels
 --------------

Several functions expect message levels. They're used to roughly
classify messages. They're used by a lot of things including logging,
ignoring, highlighting, etc. so you should use as good level as
possible. It's possible to have several levels in one message, like
ACTIONS+PUBLIC or ACTIONS+MSGS.

Here's all the levels that irssi supports currently:

  CRAP, MSGS, PUBLIC, NOTICES, SNOTES, CTCPS, ACTIONS, JOINS, PARTS
  QUITS, KICKS, MODES, TOPICS, WALLOPS, INVITES, NICKS, DCC, DCCMSGS,
  CLIENTNOTICE, CLIENTCRAP, CLIENTERROR

And a few special ones that could be included with the levels above:

  HILIGHT - text is highlighted
  NOHILIGHT - don't check highlighting for this message
  NO_ACT - don't trigger channel activity when printing this message
  NEVER - never ignore or log this message (not a good idea usually)

You can use them with a MSGLEVEL_ prefix, for example:

  $server->print("#channel", 'Hello, world', MSGLEVEL_CLIENTCRAP);

Writes text to #channel window with CLIENTCRAP level.




 Functions that you can use in Irssi's Perl scripts
 --------------------------------------------------

If there's a "Xxxx::" text before the command, it means that it belongs to
that package. Like "Server::command" means that you should either call it as
  Irssi::Server::command($server, $cmd);
or more easily:
  $server->command($cmd);

Commands that don't have the Xxxx prefix are called as Irssi::command();

Information from most objects can be fetched with $object->{data}, for
example current nick in server could be read with $server->{nick}. List
of all the information that are in objects are in "Object->{}" sections
below.

Commands are split in two groups, generic ones that could be used with
any chat protocol, and IRC specific commands. If you want to use IRC
specific commands, or use IRC specific ->{data} in your scripts, you'll
need to add "use Irssi::Irc" to your scripts. IRC specific commands are
listed after the generic ones.


 *** General



print(str[, level])
  Print `str'. Default level is MSGLEVEL_CLIENTNOTICE.

command(cmd)
  Send a command `cmd' (in current channel). The '/' char isn't needed.


 *** Themes



 *** Settings


 *** Signals

  *** timeouts / IO listener / pidwait



 *** Message levels



 *** Commands




 *** Windows



Windowitem window_item_find(name)
Server::window_item_find(name)

window_refnum_prev(refnum, wrap)
window_refnum_next(refnum, wrap)
  Return refnum for window that's previous/next in windows list.

windows_refnum_last()
  Return refnum for last window.


 *** Server Connects

Connect->{}
  type - "SERVER CONNECT" text
  chat_type - String ID of chat protocol, for example "IRC"

  address - Address where we connected (irc.blah.org)
  port - Port where we connected
  chatnet - Chat network

  password - Password we used in connection.
  wanted_nick - Nick which we would prefer to use
  username - User name
  realname - Real name

Connect
server_create_conn(address[, port=6667[, password=''[, nick=''[, channels='']]]])
  Create new server connection.


 *** Server functions



 *** Server reconnections



 *** Chat networks



 *** Server redirections

This is a powerful feature of Irssi that I haven't seen in other IRC
clients. You can EASILY grab the server's reply for a command you send
to server without any horrible kludges.

redirect_register(command, remote, timeout, start, stop, opt)
   Register new redirection command. By default irssi has already
   registered at least: whois, whowas, who, list, ison, userhost, ping,
   "mode channel" (/MODE #channel), "mode b" (/MODE #channel b), "mode e"
   and "mode I".

   `command' specifies the name of the command to register, it doesn't
   have to be a real command name, but something you just specify to
   redirect_event() when using this redirection.

   `remote' specifies if the command is by default a remote command
   (eg. sent to another server). redirect_event() may override this.

   `timeout' - If remote is TRUE, specifies how many seconds to wait for
   reply before aborting.

   `start', `stop', `opt' - hash references with "event" => argpos entries.
   List of events that start and stop this redirection.
   Start event list may be empty, but there must be at least one
   stop event. Optional events are checked only if they are received
   immediately after one of the stop-events. `argpos' specifies the
   word number in event string which is compared to wanted argument,
   -1 = don't compare, TRUE always.

  Example (already done by irssi):

  Irssi::redirect_register('mode channel', 0, 0,
  	undef, # no start events
	{ # stop events
	  "event 324" => 1, # MODE-reply
	  "event 403" => 1, # no such channel
	  "event 442" => 1, # "you're not on that channel"
	  "event 479" => 1  # "Cannot join channel (illegal name)"
	}, { # optional events
	  "event 329", 1 # Channel create time
	} );

Server::redirect_event(command, count, arg, remote, failure_signal, signals)
   Specify that the next command sent to server will be redirected.
   NOTE: This command MUST be called before sending the command to server.

   `command' - Name of the registered redirection that we're using.

   `count' - How many times to execute the redirection. Some commands may
   send multiple stop events, like MODE #a,#b.

   `arg' - The argument to be compared in event strings. You can give multiple
   arguments separated with space.

   `remote' - Specifies if the command is a remote command, -1 = use default.

   `failure_signal' - If irssi can't find the stop signal for the redirection,
   this signal is called.

   `signals' - hash reference with "event" => "redir signal" entries.
   If the event is "", all the events belonging to the redirection but not
   specified here, will be sent there.

  Example:

  # ignore all events generated by whois query, except 311.
  $server->redirect_event("whois", 1, "cras", 0, undef, {
			  "event 311" => "redir whois",
			  "" => "event empty" });
  $server->send_raw("WHOIS :cras");


 *** Window items



 *** Channels



 *** Nick list


 *** Queries


Query
query_create(chat_type, server_tag, nick, automatic)
  Create a new query.

Query
query_find(nick)
  Find query from any server.

Query
Server::query_find(nick)
  Find query from specified server.


 *** Masks

You should use the Server version of the function if possible, since
with different chat protocols the mask matching could be different.

mask_match(mask, nick, user, host)
Server::mask_match(mask, nick, user, host)
  Return 1 if `mask' matches nick!user@host.

mask_match_address(mask, nick, address)
Server::mask_match_address(mask, nick, address)
  Return 1 if `mask' matches nick!address.

masks_match(masks, nick, address)
Server::masks_match(masks, nick, address)
  Return 1 if any mask in the `masks' (string separated with spaces)
  matches nick!address.




 *** Logging



 *** Ignores


 *** /EXEC processes



 ***
 *** IRC specific functions. All objects below this are prefixed with Irc::
 ***

 *** IRC servers

Irc::Server->{}
  (..contains all the same data as core Server object..)
  real_address - Address the IRC server gives
  usermode - User mode in server
  userhost - Your user host in server

Irc::Connect->{}
  (..contains all the same data as core Connect object..)
  alternate_nick - Alternate nick to use if default nick is taken.

Connect::connect()
  Connect to IRC server.

Server::get_channels(server)
  Return a string of all channels (and keys, if any have them) in server,
  like "#a,#b,#c,#d x,b_chan_key,x,x" or just "#e,#f,#g"

Server::send_raw(cmd)
  Send raw message to server, it will be flood protected so you
  don't need to worry about it.

Server::send_raw_now(cmd)
  Send raw message to server immediately without flood protection.

Server::send_raw_split(cmd, nickarg, max_nicks)
  Split the `cmd' into several commands so `nickarg' argument has only
  `max_nicks' number of nicks.

  Example:
    $server->send_raw_split("KICK #channel nick1,nick2,nick3 :byebye", 3, 2);

  Irssi will send commands "KICK #channel nick1,nick2 :byebye" and
  "KICK #channel nick3 :byebye" to server.

Server::ctcp_send_reply(data)
  Send CTCP reply. This will be "CTCP flood protected" so if there's too
  many CTCP requests in buffer, this reply might not get sent. The data
  is the full raw command to be sent to server, like
    "NOTICE nick :\001VERSION irssi\001"

Server::isupport(name)
  Returns the value of the named item in the ISUPPORT (005) numeric to the
  script. If the item is not present returns undef, if the item has no value
  then "" is returned use defined $server->isupport("name") if you need to
  check whether a property is present.
  See http://tools.ietf.org/id/draft-brocklesby-irc-isupport-03.txt
  for more information on the ISUPPORT numeric.

 *** IRC channels



 *** DCC





 *** Netsplits

Netsplit->{}
  nick - Nick
  address - Nick's host
  destroy - Timestamp when this record should be destroyed
  server - Netsplitserver object
  channels - list of channels (Netsplitchannel objects) the nick was in

Netsplitserver->{}
  server - The server nick was in
  destserver - The other server where split occured.
  count - Number of splits in server

Netsplitchannel->{}
  name - Channel name
  nick - Nick object



 *** Notify list


notifies() - Return list of all notifies

Notifylist
notifylist_add(mask, ircnets, away_check, idle_check_time)
  Add new item to notify list.

notifylist_remove(mask)
  Remove item from notify list.

Notifylist
notifylist_find(mask, ircnet)
  Find notify.

Server
notifylist_ison(nick, serverlist)
  Check if `nick' is in IRC. `serverlist' is a space separated
  list of server tags. If it's empty string, all servers will be checked.

Server::notifylist_ison_server(nick)
  Check if `nick' is on IRC server.

 *** Proxy clients


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