Project

General

Profile

Scripting » History » Version 165

Per Amundsen, 09/19/2012 04:42 PM

1 149 Per Amundsen
h1. Notice: this is info for 1.8.10 and higher.
2 39 Per Amundsen
3 1 Per Amundsen
h1. Scripting
4
5 165 Per Amundsen
h1. NB. in next beta I will be aiming for 1:1 compatibility with mIRC scripting, much of these info will be invalidated, have that in mind when writing scripts.
6 164 Per Amundsen
7 148 Per Amundsen
*[[Scripting BETA]] Click here to see scripting in the latest beta versions.*
8 1 Per Amundsen
9 149 Per Amundsen
You can write full scripts in Commands -> Edit Scripts or you can create one liners in Commands -> Edit Commands
10 38 Per Amundsen
11 149 Per Amundsen
h1. Custom Commands:
12 1 Per Amundsen
13 149 Per Amundsen
Custom Commands are created in Commands -> Edit Commands
14 1 Per Amundsen
15 149 Per Amundsen
Custom commands consists of differents ways to execute a script either by making your own command, or use a hotkey, you can also enter a full script as a one liner (for legacy reasons)
16 1 Per Amundsen
17 150 Per Amundsen
*Alias*
18 149 Per Amundsen
<pre>
19
/hello /msg $channel hello everybody
20
</pre>
21 1 Per Amundsen
22 149 Per Amundsen
This creates a alias named "/hello", everytime you type "/hello" the script "/msg $channel hello everybody" will be executed, you can use any script features here.
23 1 Per Amundsen
24 150 Per Amundsen
*Hot keys*
25 149 Per Amundsen
<pre>
26
Ctrl&r /msg $channel hello everybody i pressed 'ctrl' and 'r'
27
</pre>
28 1 Per Amundsen
29 149 Per Amundsen
Every time you press ctrl + r, the script "/msg $channel hello everybody i pressed 'ctrl' and 'r'" will be executed, you can use any script features her.
30 1 Per Amundsen
31 149 Per Amundsen
You can comment out a command by putting a # in front of it.
32 1 Per Amundsen
33 149 Per Amundsen
It is also possible to use a full script, but it has to be on one line, and the script editor is preferred.
34 1 Per Amundsen
35 149 Per Amundsen
h1. Scripts:
36 1 Per Amundsen
37 150 Per Amundsen
*Events:*
38 149 Per Amundsen
There are different ways to listen to the irc client/server events for legacy reasons.
39 158 Per Amundsen
On/OnEvent will be executed after the event
40
OnBefore/OnBeforeEvent will be executed before the event
41
42 149 Per Amundsen
<pre>
43
OnEvent if ($event == PRIVMSG) { /EXECUTE }
44
OnBeforeEvent if ($event == PRIVMSG) { /EXECUTE }
45 1 Per Amundsen
46 149 Per Amundsen
On PRIVMSG { /EXECUTE }
47
OnBefore PRIVMSG { /EXECUTE }
48 1 Per Amundsen
49 149 Per Amundsen
OnBefore OnCommand { /EXECUTE }
50
OnCommand /mode { /EXECUTE }
51
</pre>
52 1 Per Amundsen
53 150 Per Amundsen
*Available events:*
54 149 Per Amundsen
<pre>
55 161 Per Amundsen
SockOpen / Called when a script opens a socket
56
SockRead / Called when a socket have data to read
57
SockOpen / Called when a script socket is closed
58 160 Per Amundsen
59 149 Per Amundsen
OnLoad / Called when the script is loaded
60
OnUnload / Called when the script is unloaded
61
OnReload / Called when the script is reloaded
62
OnConnecting / Called when a server is connecting
63
OnLookingUp / Called when a server is looking up the hostname
64
OnConnected / Called when a server is connected
65
OnDisconnect / Called when a server gets disconnected
66
OnCommand / Called whenever a user types a /slash command in the client ($0- will hold the full command, $0 will be the first word, $1 the second and so on)
67 1 Per Amundsen
68 149 Per Amundsen
OnCTCPRequest / Called when a user recives a CTCP request
69
OnCTCPReply / Called when a user recives a CTCP reply
70
OnDCCRequest / Called when a user recived a DCC request
71 1 Per Amundsen
72 149 Per Amundsen
OnNickChanged / Called when a user's nick changes, will only trigger on the user unlike NICK who triggers for everyone
73
OnSongChanged / Called when a song is changed in the selected media player
74 1 Per Amundsen
75 149 Per Amundsen
OnDeVoice / Called when a user gets devoiced
76
OnVoice / Called when a user gets voiced
77
OnDeHop / Called when a user gets dehalfoppeed
78
OnHop / Called when a user gets halfopped
79
OnOp / Called when a user gets opped
80
OnDeOp / Called when a user gets deopped
81
OnDeOwner/ Called when a user gets owner deopped
82
OnOwner/ Called when a user gets owner opped
83
OnDeSop / Called when a user gets special deopped
84
OnSop / Called when a user gets special opped
85 1 Per Amundsen
86 149 Per Amundsen
MODE / Called whenever a channel or user mode is changed
87
JOIN / Called whenever a user joins a channel
88
PART / Called when a user parts a channel 
89
NICK / Called when a user changes their nick
90
TOPIC / Called when a topic is set/changed
91
KICK / Called when any user gets kicked
92
NOTICE / Called when any notice is recived
93
QUIT / Called when a user quits irc
94
PRIVMSG / Called when any message is recived
95
WHOIS / Called when any whois reply is recived
96
LIST / Called when a user gets a /list
97
KILL / Called when a user gets killed
98
ACTION / Called when a user recives a ACTION (/me) message
99 1 Per Amundsen
100 149 Per Amundsen
<irc numeric> / Called when a raw irc line with <irc numeric> is recived
101
<irc textual> / Called when a raw irc line with <irc textual> is recived
102
</pre>
103 1 Per Amundsen
104 150 Per Amundsen
*if/else if/else blocks:*
105 1 Per Amundsen
106 149 Per Amundsen
You can use any combination of if, else if, else and while
107
<pre>
108
OnEvent if ($event == PRIVMSG) { 
109
	if (%test == null) { 
110
		/echo Hello world
111
		if (%test == null) { 
112
			/echo Hello world
113
		}
114
		else /echo Hello World
115
	} else if (%test == null) { 
116
		/echo Hello world
117
	} else (%test == null) { 
118
		/echo Hello world 
119
	} 
120 1 Per Amundsen
121 149 Per Amundsen
	if (%test == null) { 
122
		/echo Hello world
123
		while (%test == null) {
124
			/echo Hello world
125
		}
126
	}
127 1 Per Amundsen
128 149 Per Amundsen
	if(%test == null)/echo Hello World
129
	else if(%test == null)/echo Hello World
130
	else/echo Hello world
131
	
132
	if(%test == null){/echo Hello World
133
	}else if(%test == null){/echo Hello World
134
	}else{/echo Hello World
135
	}
136 1 Per Amundsen
137 149 Per Amundsen
	if(%test == null){/echo Hello World}else if(%test == null){/echo Hello World}else{/echo Hello World}
138
}
139
</pre>
140 1 Per Amundsen
141 150 Per Amundsen
*while blocks:*
142 151 Per Amundsen
<pre>
143 149 Per Amundsen
On JOIN {
144
	var %t = 0
145
	/echo There are ($user($chan, 0)) users in ($chan)
146
	
147
	while (%t < $user($chan, 0)) {
148
		%t++
149
		var %nick = $user($chan, %t)
150
		/echo User (%t) is (%nick) and is $iif(%nick isop $chan, opped, not opped)
151
	}
152
}
153
</pre>
154 1 Per Amundsen
155 150 Per Amundsen
*goto/label:*
156 1 Per Amundsen
157
<pre>
158 149 Per Amundsen
OnCommand /goto {
159
	var %loop = 0 
160
	if ($1 == 1) {
161
		goto 1
162
	} else if ($1 == 2) {
163
		goto 2
164
	} else if ($1 == loop) {
165
		:3
166
		/echo you typed loop
167
		%loop++
168
		if (%loop < 5) {
169
			goto 3
170
		}
171
		return
172
	} else {
173
		goto 4
174
	}
175 1 Per Amundsen
176 149 Per Amundsen
	:1
177
	/echo You typed 1
178
	return
179
	:2
180
	/echo You typed 2
181
	return
182
	:4
183
	/echo The end
184
	return
185
}
186
</pre>
187 1 Per Amundsen
188 150 Per Amundsen
*client variables:*
189 159 Per Amundsen
All client variables starts with $
190
191 152 Per Amundsen
<pre>
192 1 Per Amundsen
$event / current event, e.g PRIVMSG 001 MODE and so forth
193
$channel / the channel the event occurred on, if any
194
$msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick
195
$nick / the nick the event was sent from, can be a irc.server.com, a nick or null
196
$me / my current nick
197
$network / the network the event occured on e.g Quakenet
198
$ident / the from user ident if any
199
$host / the from user hostname if any
200
$myident / my ident
201
$myhost / my host
202
$server / host from the server e.g irc.server.com
203 149 Per Amundsen
$now / returns unixtime/ctime from current time.
204
$active / returns the current window Status/#channel/Nick.
205
$activeserver / returns an id for current server
206
$status / returns current server status
207
$crlf / returns newline \r\n
208
$0-$9 / will return parts of the $msg, $<number>- will combine parts of the $msg from 0 to <number>. $0- will return everything
209
$! / returns how many $0 $1 etc variables are filled (not sure if final name of it)
210
$raw0-$raw9 / will return parts of the raw message, $raw<number>- will combine parts of the raw message from 0 to <number>. $raw0- will return everything
211 1 Per Amundsen
$r! / returns how many $raw0 $raw1 etc variables are filled (not sure if final name of it)
212 159 Per Amundsen
$+ / use to combine variables output e.g "$now $+ $server"
213 152 Per Amundsen
</pre>
214 162 Per Amundsen
215
All sysinfo/mediaplayer variables are available as well.
216
217 153 Per Amundsen
*user set variables:*
218 159 Per Amundsen
All user set variables starts with %
219
220 149 Per Amundsen
var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script is done.
221
using += instead of = will append to the variable, if both variable and new value is numbers it will combine them to a new number %variable += 4242.
222 1 Per Amundsen
223 149 Per Amundsen
If a variable is created without var, the variable will be available to all scripts, saved to a file and restored when AdiIRC is started.
224
225 157 Per Amundsen
Commands for manipulating variables:
226 1 Per Amundsen
<pre>
227 149 Per Amundsen
/set {-u seconds/-d] [%var] [value] / create or update a variable with value -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it
228 1 Per Amundsen
229 149 Per Amundsen
/unset [var] / deletes a variable
230 1 Per Amundsen
231 149 Per Amundsen
/inc {-u seconds/-d] [%var] [value] / increases a variable with value (only if value and var is ints) -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it
232 1 Per Amundsen
233 149 Per Amundsen
/dec {-u seconds/-d] [%var] [value] / decreases a variable with value (only if value and var is ints) -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it
234 1 Per Amundsen
235 149 Per Amundsen
/vars shows a list of all variables and their values
236
</pre>
237 1 Per Amundsen
238 150 Per Amundsen
*functions:*
239 149 Per Amundsen
Several functions are exsists, they are all recursive and you can use any %variable or $variable as parameters:
240
They are also usable inside if () else if () while () statements.
241
All variable numbers are floats and all functions supports floats for precise calculations.
242 36 Per Amundsen
243
<pre>
244 149 Per Amundsen
$replace(text, text2, text3) / replace all occurrences of text2 in text with text3
245
$upper(text) / return text uppercase
246
$lower(text) return text lowercase
247
$mid(text, startpos, endpos) / return part of text from startpos to endpos
248
$substr(text, startpos, endpos) / return part of text from startpos to endpos
249
$left(text, pos) / return pos characters starting from left of the text
250
$right(text, pos) / return pos characters starting from right of the text
251
$remove(text, text2) / replace all occurrences of text2 from text
252
$len(text) / return length of text
253
$count(text, text2) / counts all occurrences of text2 in text
254
$pos(text, text2) / returns first occurrences position of text2 in text
255
$lastpos(text, text2) / returns last occurrences position of text2 in text
256
$strip(text) / removes all color and font tags
257
$repeat(text, times) / repeats text X times
258
$insert(text, text2, pos) / inserts text2 into pos of text
259
$chr(num) / returns ascii character from the number num
260
$char(num) / returns ascii character from the number num
261 1 Per Amundsen
262 149 Per Amundsen
$calc(formula) / calculate any variation of +-*/
263
$formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
264
$fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
265
$ctime(datestamp) / converts most variations of a date stamp to unix/ctime
266
$datediff(ctime1, ctime2) / diffs two unix/ctime and fills the $datematch array with values
267
$datematch(num) / returns part of a $datediff, 0 = milliseconds, 1 = seconds, 2 = minutes, 3 = hours, 4 = days
268
$host(nick) / returns the hostmask of nick
269
$ident(nick) / returns the ident of nick
270
$(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name)
271
$cond(cond, execute1, execute2) / checks if cond is true then executes execute1, else executes execute2, will return string if not at the begining of the line
272
$iif(cond, execute1, execute2) / checks if cond is true then executes execute1, else executes execute2, will return string if not at the begining of the line
273
$round(num, decimals) / rounds down a float to X decimals
274
$regex(text, pattern) / does a regular expression test if text matches pattern, then returns the matched part
275
$regmatch(num) / returns the captured group at pos num from a $regex. 0 returns group count
276
$regreplace(text, pattern, text2) / replace any occurence in text of patterh with text2 where pattern is a regular expression
277 3 Per Amundsen
278 149 Per Amundsen
$file(path) / reads file to end and returns the entire output without newlines
279
$fileloop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
280
$floop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
281
$filerandom(path) / returns a random line from a file
282
$frand(path) / returns a random line from a file
283
$fread(name) / reads a line from current pos in file named name
284
$fileread(name) / reads a line from current pos in file named name
285
$freadc(name) / reads a char/byte from current pos in file named name
286
$freadchar(name) / reads a char/byte from current pos in file named name
287
$fsize(file) / returns size off file in bytes
288
$filesize(file) / returns size off file in bytes
289
$fpos(name) / returns current position/byte in file named name
290
$filepos(name) / returns current position/byte in file named name
291
$flines(file) / returns amount of lines in file
292
$filelines(file) / returns amount of lines in file
293
$fileexists(file) / returns if file exists or not
294
$isfile(file) / returns if file exists or not
295 1 Per Amundsen
296 149 Per Amundsen
$chan(num) / if num is 0 returns how many channels you are joined on this server else returns channel name in position num
297
$user(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
298
$nick(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
299
$server(num) / if num is 0 returns how many servers you are connected to else returns server id in position num
300 1 Per Amundsen
301 149 Per Amundsen
$sread(name) / reads available bytes from socket named name (on sockread)
302
$sockread(name) / reads available bytes from socket named name (on sockread)
303
$sbytes(name) / returns amount of available bytes to be read from socket named name
304
$sockbytes(name) / returns amount of available bytes to be read from socket named name
305 1 Per Amundsen
</pre>
306
307 158 Per Amundsen
*operators:*
308
309
All operators can use ! to reverse the logic e.g !ison. 
310
If no operators are added it will test if remaining text is not null if (%test), if ($channel) or if (!$channel) etc.
311
312
<pre>
313 163 Per Amundsen
== / Will check if left and right string or int is the same
314 158 Per Amundsen
> / Will try and cast left and right variable to int and try "int1 greater than int2"
315
< / Will try and cast left and right variable to int and try "int1 lower than int2"
316
>= / Will try and cast left and right variable to int and try "int1 greater than or equal to int2"
317
<= / Will try and cast left and right variable to int and try "int1 lower than or equal to int2"
318
isbetween / Will try and cast left variable to int and right variable have to be int-int, e.g "40 isbetween 30-50"
319
ison / check if ($nick ison $channel) nick is the channel
320
isop / check if ($nick isop $channel) is operator on the channel
321
ishop / check if ($nick ishop $channel) is half operator on the channel
322
issop / check if ($nick issop $channel) is special operator on the channel
323
isowner / check if ($nick isowner $channel) is channel owner
324
hasvoice / check if ($nick hasvoice $channel) have voice on the channel
325
inchan / check if i am in chan (#channel inchan) (#channel !inchan)
326
isnum / check something is a number (5 isnum) (5 !isnum)
327
ismatch / will check if left contains right value or right contains left value
328
isin / same as ismatch except only checking if left value is in right value, ismatch checks both
329
</pre>
330
331
*tips:*
332
/ is not needed to execute a command in scripts e.g /echo and echo is the same.
333
use null to check for nothing "if ($nick == null)"
334
Comment out a line with # or several lines with /* code */
335 159 Per Amundsen
All paths needs to be escaped e.g c:\\users\\kr0n\\file.txt if only a filename is entered, the script directory will be used.
336
All characters that needs to be escaped before used as strings are \ { } ;
337
In some cases you might have to escape ( ) | , # $ %
338
; as a newline "/echo 1; /echo 2" is the same as
339
/echo 1
340
/echo 2
341
342
"halt" will halt the script immediately, telling the client to eat the event and ignoring the rest of the script.
343
"return" will halt immediately, ignoring rest of the script, but not eat anything.
344 158 Per Amundsen
345 155 Per Amundsen
h1. Example scripts
346 154 Per Amundsen
347
Simple kickcounter script:
348
349
<pre>
350
OnBefore OnCommand { 
351
	if ($0 != /kick)  return
352
		
353
	if (%kickcount == null) %kickcount = 0
354
355
	%kickcount++
356
		 
357
	if ($2 == null) { 
358
		/kick $channel $1 Kick number %kickcount
359
		halt
360
	} 
361
}
362
</pre>
363
364
Kickban example
365
<pre>
366
OnCommand /kb {
367
	if (!$1) {
368
		/echo /kb - Nick missing
369
		return
370
	}
371
372
	var %msg = $iif($channel, $2-, $3-)
373
	var %chan = $iif($channel, $channel, $2)
374
		
375
	# Set this for default ban reason, or remove for no default reason
376
	# Can be shortened to %msg = $iif(%msg, %msg, GTFO)
377
	if (%msg == null) %msg = GTFO
378
379
	if ($me isop %chan) {
380
		/raw MODE %chan +b *!$ident($1)@$host($1)
381
		/raw KICK %chan $1 %msg
382
	} 
383
	else /echo You are not oper on %chan
384
}
385
</pre>
386
387
Simple calculator script:
388
<pre>
389
OnCommand /calc {
390
	if (!$1) {
391
		/echo /calc - Parameters missing
392
		return
393
	}
394
		
395
	# typing /calc -p <expression> sends output to channel
396
	if ($1 == -p) {
397
		/msg $channel Calculating : $2-
398
		/msg $channel Result is : $calc($2-)
399
	} else {
400
		/echo Calculating : $1-
401
		/echo Result is : $calc($1-)
402
	}
403
}
404
</pre>
405
406
Colored version
407
<pre>
408
OnCommand /calc {
409
	if (!$1) {
410
		/echo /calc - Parameters missing
411
		return
412
	}
413
	
414
	# typing /calc -p <expression> sends output to channel
415
	if ($1 == -p) {
416
		/msg $channel $chr(3)4Calculating : $2-
417
		/msg $channel $chr(3)4Result is : $calc($2-)
418
	} else {
419
		/echo $chr(3)4Calculating : 4$1-
420
		/echo $chr(3)4Result is : $calc($1-)
421
	}
422
}*/
423
</pre>
424
425
CTCP flood detection example
426
427
<pre>
428
On OnCTCPRequest {
429
	if (%count == null) /set -u 10 %count 1
430
	else /inc -u 10 %count 1
431
432
	if (%count > 4) /ignore  -u 30 -t $nick!$ident@$host
433
}
434
</pre>
435
436
Mass mode example
437
438
<pre>
439
OnCommand /mass {
440
	if (!$2) {
441
		/echo /mass - Parameters missing [+/-<mode> <nick> <nick> <nick>]
442
		return
443
	}
444
445
	%len = 2
446
	
447
	# equal to while (%len <= $count(%0-, $chr(32)))
448
	while (%len <= $!) {
449
		if ($(%len) ison $channel) /mode $channel $1 $(%len)
450
		/inc %len
451
	}
452
}
453
</pre>
454
455
Shows info about servers, channels and users
456
<pre>
457
On JOIN {
458
	var %s = $server(0), %c = 0, %u = 0, %t = 0, %c2 = 0;
459
	
460
	while (%t < %s) {
461
		%t++
462
		/setserver $server(%t);
463
		%c += $chan(0)
464
	
465
		%c2 = 0
466
		while (%c2 < $chan(0)) {
467
			%c2++
468
			%u += $user($chan(%c2), 0)
469
		}
470
	}
471
472
	/echo You are on (%s) servers, (%c) channels with (%u) users
473
}
474
</pre>
475
476 156 Per Amundsen
It is possible to use scripts as functions.
477
These functions are fully nested like the client functions.
478 154 Per Amundsen
479
Lets say you make a /mycalc like this.
480
<pre>
481
OnCommand /mycalc {
482
	return $calc($0+$1);
483
}
484
</pre>
485
486
Then you can call this function with eiter /mycalc <number> <number> the normal way or $mycalc(<number, <number>)
487
Typing /testcalc will show the result.
488
<pre>
489
OnCommand /testcalc {
490
	/echo $0 + $1 is $mycalc($0, $1);
491
	/echo 5 + 4 is $mycalc(5, 4);
492
}
493
</pre>
494
495
Simple convert temperature C to F or F to C
496
/temp C 20 will print 68 F
497
498
<pre>
499
OnCommand /temp {
500
	if ($1 == C) /echo $calc(($2 * 9/5) + 32) F
501
	else if ($1 == F) /echo $round($calc(($2 - 32) * 5/9), 1) C
502
	else /echo Temp missing
503
}
504
</pre>
505
506
Test if input contains a link
507
<pre>
508
OnCommand /testlink {
509
	if (!$1) {
510
		/echo Link missing
511
		return
512
	}
513
514
	/echo $iif($regex($1, (?i)\\b((?:[a-z][\\w-]+:(?:/\{1\,3\}|[a-z0-9%])|www\\d\{0\,3\}[.]|[a-z0-9.\\-]+[.][a-z]\{2\,4\}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]\\\{\\\}\\\;:'".\,<>?«»“”‘’]))), yes, no)
515
}
516
517
</pre>
518
519
Retrives plot summary from captured imbd links
520
<pre>
521
On PRIVMSG {
522
	var %reg = $regex($0-, http://www\\.imdb\\.com(/title/[a-z0-9]+/))
523
	if (!%reg) { return }
524
		
525
	/sockclose imdb
526
	%text = null
527
	%imdb = $regmatch(1)plotsummary
528
	%imdbchan = $channel
529
	/sockopen imdb www.imdb.com 80
530
}
531
532
On SockOpen {
533
	if ($1 != imdb) { return }
534
535
	/sockwrite -n imdb GET %imdb HTTP/1.1
536
	/sockwrite -n imdb Host: www.imdb.com
537
	/sockwrite -n imdb User-Agent: Mozilla/5.0 (Windows NT 6.1\; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.24 Safari/536.5
538
	/sockwrite -n imdb Referer: http://www.imdb.com
539
	/sockwrite -n imdb Accept: text/xml,application/xml,application/xhtml+xml,text/html\;q=0.9,text/plain\;q=0.8,video/x-mng,image/png,image/jpeg,image/gif\;q=0.2,text/css,*\/*\;q=0.1
540
	/sockwrite -n imdb Accept-Language: en-us, en\;q=0.50
541
	/sockwrite -n imdb Connection: Close$crlf
542
}
543
544
On SockRead {
545
	if ($1 != imdb) { return }
546
		
547
	%text += $sockread(imdb)
548
}
549
550
On SockClose {
551
	if ($1 != imdb) { return }
552
	
553
	if ($regex(%text, <p class="plotpar">([\\s\\S]*?)<i>)) {
554
		/msg %imdbchan $regmatch(1)
555
	}
556
557
	%text = null
558
}
559
</pre>
560
561
An example showing the difference between dates
562
<pre>
563
OnCommand /test {
564
	$datediff($ctime(1/1 2042), $now)
565
	
566
	var %text = Difference is
567
	%text += $chr(32)$datematch(4) $iif($datematch(4) == 1, day, days)
568
	%text += $chr(32)$datematch(3) $iif($datematch(3) == 1, hour, hours) 
569
	%text += $chr(32)$datematch(2) $iif($datematch(3) == 1, minut, minutes) 
570
    
571
	/echo %text
572
}
573
</pre>
574 158 Per Amundsen
575
Announce song changes in a channel or to a user
576
<pre>
577
On OnSongChanged { 
578
	/nmsg <network> <channel/Nick> $0-
579
}
580
</pre>
581
582
Announce to several channels with:
583
<pre>
584
On OnSongChanged { 
585
	/nmsg <network> <channel1/Nick>,<channel2/Nick> $0-
586
	/nmsg <network2> <channel3/Nick> $0- 
587
}
588 154 Per Amundsen
</pre>