Project

General

Profile

Scripting » History » Version 142

Per Amundsen, 04/08/2012 08:28 AM

1 42 Per Amundsen
h1. Notice: this is info for 1.8.8 and higher.
2 39 Per Amundsen
3 1 Per Amundsen
h1. Scripting
4
5
In the latest beta's, I am experimenting with a little more advanced scripting features and I will use this wiki to track progress and features.
6
7 8 Per Amundsen
Syntax, variables and functions will probably change a lot, so don't except previous scripts to still work in the next beta and so forth.
8 1 Per Amundsen
9 30 Per Amundsen
There are 2 types of scripting at the moment, one that have been here for a long time, and a new system.
10 16 Per Amundsen
11 38 Per Amundsen
All scripting is done in Commands -> Edit Commands where one line represent a script or a custom command and its trigger is one of 3 ways:
12
13
/something<whitespace> 
14 37 Per Amundsen
keys<whitespace>
15
OnEvent<whitespace>
16 16 Per Amundsen
17 1 Per Amundsen
Please note that variables and functions are *different* for these 2 types of scripts.
18 37 Per Amundsen
19
You can comment out a command by putting a # in front of it.
20 17 Per Amundsen
21 1 Per Amundsen
h1. Normal custom commands:
22 26 Per Amundsen
23 25 Per Amundsen
<pre>Syntax = /something<whitespace>/somethingelse</pre>
24 16 Per Amundsen
25 23 Per Amundsen
Here are some variables which can be used in Custom Commands, its like creating aliases of already available commands, e.g <pre>/hi /me says hi to $chan</pre> will show <pre>* kr0n says hi to #adiirc</pre> when typing <pre>/hi</pre>
26 16 Per Amundsen
27 32 Per Amundsen
Current variables are $1 to $9, $params, $chan and $me. $1 to $9 represents what you type after /yourcommand e.g <pre>/sup /say whats up $1</pre> when typing <pre>/sup kr0n</pre> it will show like this <pre>User: whats up kr0n</pre>
28 16 Per Amundsen
29 29 Per Amundsen
$params represents everything written after /yourcommand, $chan replaces itself with current channel and $me replaces itself with your current usernick. 
30 16 Per Amundsen
31 131 Per Amundsen
You can make combo commands by using | as a seperator, e.g <pre>/hi /me says hi to $chan | /me says hi again to $chan</pre>
32 16 Per Amundsen
33 1 Per Amundsen
$file[path] returns data from a file, $frand[path] fetchs a random line from a file and $floop[path] gets one line increasingly (line1, then line2, then line3 etc).
34 23 Per Amundsen
35 27 Per Amundsen
h1. Custom Commands by hotkeys
36 1 Per Amundsen
37 25 Per Amundsen
<pre>Syntax = key&key<whitespace>/something</pre>
38 1 Per Amundsen
39 27 Per Amundsen
In addition to making a custom command trigger by typing a /slash command, you make it trigger with a hotkey instead (note, these commmands will not be useable from the new scripting engine)
40
41 23 Per Amundsen
Useable modifies are ctrl, alt and shift and any character or number or F key.
42
43
An example
44
45 24 Per Amundsen
<pre>ctrl&o /msg $chan ohai i just pressed ctrl and o</pre>
46 23 Per Amundsen
47 1 Per Amundsen
Everytime you press ctrl and 'o' now, this command will be fired off.
48 24 Per Amundsen
49
<pre>ctrl&alt&o /msg $chan ohai i just pressed ctrl and alt and o</pre>
50
51 1 Per Amundsen
Everytime you press ctrl and alt and 'o' now, this command will be fired off.
52 16 Per Amundsen
53 27 Per Amundsen
h1. Unified Scripting
54 1 Per Amundsen
55 27 Per Amundsen
<pre>Syntax = OnEvent<whitespace>code</pre>
56
57 1 Per Amundsen
The new scripting tries to combine normal client commands, your custom commands, functions and events into one scripting language.
58
59 25 Per Amundsen
In Commands -> Edit Commands you can enter a scripting line with the following syntax:
60 1 Per Amundsen
61
Followed by either an expression like this (works recursivly)
62
63
<pre>
64
if (SOMETING == SOMETHINGELSE) { EXECUTE HERE }
65
if (SOMETING != SOMETHINGELSE) { EXECUTE HERE }
66 13 Per Amundsen
if (SOMETING ismatch SOMETHINGELSE) { EXECUTE HERE }</pre>
67 1 Per Amundsen
or by an executed command or function
68
69 2 Per Amundsen
You can now combine expressions with && (AND) and || (OR) like this
70 1 Per Amundsen
<pre>
71 2 Per Amundsen
if (SOMETHING == SOMETHING && SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE }
72 13 Per Amundsen
if (SOMETHING == SOMETHING || SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE }</pre>
73 1 Per Amundsen
The logic behind these expressions is not fully tested, id love any feedback on this.
74 33 Per Amundsen
75
It is also possible to use else if like this
76
<pre>if (SOMETHING == SOMETHING) { EXECUTE HERE } else if (SOMETHINGELSE == SOMETHINGELSE) { EXECUTE HERE }</pre>
77
In the future just "else" will be possible to.
78 12 Per Amundsen
79
(note: ismatch will check if SOMETHING exist inside SOMETHINGELSE e.g if something is "hello" and something else is "hello world" it would return True because "hello" exist)
80 2 Per Amundsen
81 1 Per Amundsen
Executed commands are /slash commands already in the client e.g /msg #channel hello world.
82
Executed functions are predefined functions in the client, only two exists for now.
83
84 131 Per Amundsen
An execution block can consist of both commands and functions if seperated by | (pipe) character like this <pre>/msg #channel hello world | .function bla bla | /msg #channel2 hello world</pre>
85 1 Per Amundsen
86
Furthermore there is a lot of predefined variables for use with these functions, for now they are:
87
88
$event / current event, e.g PRIVMSG 001 MODE and so forth
89
$channel / the channel the event occurred on, if any
90
$msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick
91
$nick / the nick the event was sent from, can be a irc.server.com, a nick or null
92
$me / my current nick
93
$network / the network the event occured on e.g Quakenet
94
$ident / the from user ident if any
95
$host / the from user hostname if any
96
$myident / my ident
97
$myhost / my host
98 14 Per Amundsen
$server / host from the server e.g irc.server.com
99 1 Per Amundsen
100
Currently predefined functions are:
101
<pre>
102 36 Per Amundsen
.insert <nick (use null for nonick)> 
103
<where (a channel or $channel, a nick or $nick, or status)> 
104
<MsgType (MsgServer/MsgUser/MsgEmote/MsgCTCP/MsgNotice/MsgClient/MsgLog)> 
105
<$msg or message></pre>
106 1 Per Amundsen
107
<pre>
108 13 Per Amundsen
.eat <what (text or all)></pre>
109 1 Per Amundsen
.insert is used for inserting a specific message type into a chat window, its intended for use in cases where you want to override how adiirc shows a given event, but can also be used for adding additional messages.
110
111
.eat is used to tell adiirc to either "eat" the text output from an event or "eat" everything and don't act on this event at all.
112
113
Putting it all togheter, here are a few examples:
114
115
<pre>
116 131 Per Amundsen
OnEvent if ($event == NOTICE) { if ($msg ismatch hi there) { .insert $nick status MsgNotice $msg | .eat text } }</pre>
117 1 Per Amundsen
118
insert the notice into the server window and tells adiirc to "eat" its own text output from this notice
119
120
<pre>
121 41 Per Amundsen
OnEvent if ($event == PRIVMSG && $msg == herp) { /msg $channel derp }</pre>
122 7 Per Amundsen
123 1 Per Amundsen
if the event is a PRIVMSG AND the $msg equals "herp", then show "derp" in the channel
124
125 6 Per Amundsen
<pre>
126 13 Per Amundsen
OnEvent if ($event == PRIVMSG) { if ($nick == Q || $nick == $me) { /msg $channel Q or $me is speaking! } }</pre>
127 1 Per Amundsen
128
if the event is a PRIVMSG and the $nick equals "Q" OR $me then show "Q or $me is speaking" in the channel
129 9 Per Amundsen
130 34 Per Amundsen
<pre>OnEvent if ($event == OnOp && $nick == $me) { /msg $channel Thx for op! }</pre>
131
132 35 Per Amundsen
if the event is OnOp and the target nick is me, then show "Thx for op!" in the channel
133
134 3 Per Amundsen
A list of custom events that is also usable as $event ==
135 4 Per Amundsen
<pre>
136 3 Per Amundsen
OnOwner
137
OnDeOwner
138
OnSpecialOp
139
OnSpecialDeOp
140
OnOp
141
OnDeOp
142
OnHop
143
OnDeHop
144 1 Per Amundsen
OnVoice
145 42 Per Amundsen
OnDeVoice
146 46 Per Amundsen
</pre>
147 1 Per Amundsen
148 46 Per Amundsen
h1. Scripting changes in latest beta
149
This does not apply to the latest stable release!
150 1 Per Amundsen
151
*Scripting is now unified completly which means all variables applies to all scripts and:
152 112 Per Amundsen
$file[path] is now $file(path);
153 111 Per Amundsen
$frand[path] is now $frand(path);
154 131 Per Amundsen
$floop[path] is now $floop(path);
155 137 Per Amundsen
COMMAND|COMMAND must now be COMMAND | COMMAND for parsing simplicity, this will possibly be removed in the future please use COMMAND ; COMMAND instead*
156 111 Per Amundsen
157 60 Per Amundsen
*OnEvent* is now executed *AFTER* the event, use *OnBeforeEvent* for events where you want to .eat or in other ways manipulate the event.
158
159 119 Per Amundsen
Shorter aliases are added for simplicity.
160
<pre>
161
OnCommand /command { EXECUTE }
162
163 120 Per Amundsen
On EVENT { EXECUTE }
164 119 Per Amundsen
165
OnBefore EVENT { EXECUTE }
166
</pre>
167 118 Per Amundsen
168 50 Per Amundsen
New command /nmsg added for cross network output, and a new event OnSongChanged. 
169 1 Per Amundsen
170 50 Per Amundsen
Combine them and you can automatically announce song changes in a channel or to a user with:
171
172 42 Per Amundsen
<pre>
173 123 Per Amundsen
OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $0-; }
174 42 Per Amundsen
</pre>
175 62 Per Amundsen
176 42 Per Amundsen
Announce to several channels with:
177 62 Per Amundsen
178 42 Per Amundsen
<pre>
179 123 Per Amundsen
OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $0-;/nmsg <network> <channel/Nick> $0-; }
180 42 Per Amundsen
</pre>
181 1 Per Amundsen
182 61 Per Amundsen
Network is the network name where the channel is, e.g NordicIRC, freenode, Quakenet, look at the name of the server window you are connected on to find it.
183 46 Per Amundsen
184
Also added is better escaping, variables and a "null" variable, e.g
185
186
<pre>
187 125 Per Amundsen
OnEvent if ($event == PRIVMSG) { if (%test == null) { %test = SOMETHING;/echo test is %test } }
188 46 Per Amundsen
</pre>
189
190 95 Per Amundsen
New variable $now returns unixtime/ctime from current time.
191 97 Per Amundsen
New variable $active returns the current window Status/#channel/Nick.
192 104 Per Amundsen
New variable $! returns how many $0 $1 etc variables are filled (not sure if final name of it)
193 132 Per Amundsen
New variable $r! returns how many $raw0 $raw1 etc variables are filled (not sure if final name of it)
194
New variable $activeserver returns an id for current server
195
New variable $status returns current server status
196 95 Per Amundsen
197 116 Per Amundsen
These variables are saved into vars.ini unless removed (%var set to null) and reloaded when adiirc starts.
198 89 Per Amundsen
You can change/use them in any script.
199 48 Per Amundsen
200 49 Per Amundsen
Note also that all user set variables starts with % and client variables starts with $.
201
202 91 Per Amundsen
Some commands for manipulate variables:
203
204
<pre>
205 93 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
206 92 Per Amundsen
207 91 Per Amundsen
/unset [var] / deletes a variable
208 92 Per Amundsen
209 93 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
210 92 Per Amundsen
211 93 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
212 92 Per Amundsen
213
/vars shows a list of all variables and their values
214 91 Per Amundsen
</pre>
215
216 126 Per Amundsen
var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script is done.
217 134 Per Amundsen
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.
218 126 Per Amundsen
219 1 Per Amundsen
Variables is still work in progress, id love some feedback/ideas of what it can be used for.
220 50 Per Amundsen
221 99 Per Amundsen
halt can now be used instead of .eat all, it will halt immediately, ignoring rest of the script.
222
return will halt immediately, ignoring rest of the script, but not eat anything.
223
224 51 Per Amundsen
<pre>
225 73 Per Amundsen
OnLoad / Called when the script is loaded
226
OnUnload / Called when the script is unloaded
227
OnReload / Called when the script is reloaded
228
OnConnecting / Called when a server is connecting
229
OnLookingUp / Called when a server is looking up the hostname
230
OnConnected / Called when a server is connected
231
OnDisconnect / Called when a server gets disconnected
232 124 Per Amundsen
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)
233 99 Per Amundsen
OnCTCPRequest / Called when a user recives a CTCP request
234
OnCTCPReply / Called when a user recives a CTCP reply
235 1 Per Amundsen
ACTION / Called when a user recives a ACTION (/me) message
236 100 Per Amundsen
OnNickChanged / Called when a user's nick changes, will only trigger on the user unlike NICK who triggers for everyone
237 123 Per Amundsen
OnSongChanged / Called when a song is changed in the selected media player
238 51 Per Amundsen
</pre>
239
240
A few examples using these.
241 1 Per Amundsen
242
<pre>
243
OnEvent if ($event == OnLoad) { %myvariable = This was set at startup }
244
OnEvent if ($event == OnUnLoad) { .msgbox varible set at startup was %myvariable }
245
OnEvent if ($event == OnReLoad) { .msgbox Script reloaded }
246 99 Per Amundsen
OnEvent if ($event == OnConnecting) { /echo i r conecting }
247
OnEvent if ($event == OnLookingUp ) { /echo i r looking up hostname }
248
OnEvent if ($event == OnConnected ) { /echo i r connected }
249
OnEvent if ($event == OnDisconnect) { /echo i r disconnected }
250
OnEvent if ($event == OnCommand) { if ($0 == /me) { /echo i typed /me } }
251
OnEvent if ($event == OnCommand) { /echo i typed $0, full command was $0- }
252 100 Per Amundsen
OnEvent if ($event == OnCTCPRequest) { /echo CTCP Request $0- from $nick }
253
OnEvent if ($event == OnCTCPReply) { /echo CTCP Reply $0- from $nick }
254 1 Per Amundsen
OnEvent if ($event == ACTION) { /echo ACTION $0- from $nick }
255 123 Per Amundsen
OnEvent if ($event == OnNickChanged) { /echo My nick is now $0 } 
256 52 Per Amundsen
OnEvent if ($event == OnSongChanged) { /echo Song changed to $0- }
257 53 Per Amundsen
</pre>
258 1 Per Amundsen
259 132 Per Amundsen
New Operators, all operators can now use ! to reverse the logic e.g !ison. If no operators are added it will test if remaining text is not null if (%test), if ($channel) or if (!$channel) etc.
260 65 Per Amundsen
261
<pre>
262 101 Per Amundsen
> / Will try and cast left and right variable to int and try "int1 greater than int2"
263
< / Will try and cast left and right variable to int and try "int1 lower than int2"
264
>= / Will try and cast left and right variable to int and try "int1 greater than or equal to int2"
265
<= / Will try and cast left and right variable to int and try "int1 lower than or equal to int2"
266
isbetween / Will try and cast left variable to int and right variable have to be int-int, e.g "40 isbetween 30-50"
267
ison / check if ($nick ison $channel) nick is the channel
268
isop / check if ($nick isop $channel) is operator on the channel
269
ishop / check if ($nick ishop $channel) is half operator on the channel
270
issop / check if ($nick issop $channel) is special operator on the channel
271
isowner / check if ($nick isowner $channel) is channel owner
272
hasvoice / check if ($nick hasvoice $channel) have voice on the channel
273
inchan / check if i am in chan (#channel inchan) (#channel !inchan)
274
isnum / check something is a number (5 isnum) (5 !isnum)
275 65 Per Amundsen
</pre>
276
277 140 Per Amundsen
; is now useable like | for line ending and is prefered from now on.
278 53 Per Amundsen
A complete rewrite of the parser logic is done, introducing the "else" keyword, and you can now use any nested length of "if" "else if" and "else" e.g:
279
280
<pre>
281 135 Per Amundsen
OnEvent if ($event == PRIVMSG) { 
282 1 Per Amundsen
	if (%test == null) { 
283 140 Per Amundsen
		/echo Hello world
284 1 Per Amundsen
		if (%test == null) { 
285 140 Per Amundsen
			/echo Hello world
286
		}
287
		else /echo Hello World
288 135 Per Amundsen
	} else if (%test == null) { 
289 125 Per Amundsen
		/echo Hello world
290 135 Per Amundsen
	} else (%test == null) { 
291 55 Per Amundsen
		/echo Hello world 
292 1 Per Amundsen
	} 
293
294
	if (%test == null) { 
295
		/echo Hello world 
296 140 Per Amundsen
	}
297
298
	if(%test == null)/echo Hello World
299
	else if(%test == null)/echo Hello World
300
	else/echo Hello world
301
	
302 141 Per Amundsen
	if(%test == null){/echo Hello World
303
	}else if(%test == null){/echo Hello World
304
	}else{/echo Hello World
305
	}
306
307
	if(%test == null){/echo Hello World}else if(%test == null){/echo Hello World}else{/echo Hello World}
308 1 Per Amundsen
}
309
</pre>
310 54 Per Amundsen
311 57 Per Amundsen
Simple kickcounter script:
312 122 Per Amundsen
<pre>
313 142 Per Amundsen
OnBefore OnCommand { 
314 138 Per Amundsen
	if ($0 != /kick)  return
315 117 Per Amundsen
		
316 138 Per Amundsen
	if (%kickcount == null) %kickcount = 0
317 117 Per Amundsen
318 138 Per Amundsen
	%kickcount++
319 133 Per Amundsen
		 
320 138 Per Amundsen
	if ($2 == null) { 
321
		/kick $channel $1 Kick number %kickcount
322
		halt
323 69 Per Amundsen
	} 
324
}
325 85 Per Amundsen
</pre>
326 69 Per Amundsen
327
You can now use "-" on $<number> variables to get all words from $<number> and after.
328
329
<pre>
330
OnEvent if ($event == OnCommand) { /echo $2- }
331 85 Per Amundsen
</pre>
332 69 Per Amundsen
333
When you type "/msg $me this is a test" you will get only "this is a test"
334
335
<pre>
336
OnEvent if ($event == OnCommand) { /echo $3- }
337 85 Per Amundsen
</pre>
338 1 Per Amundsen
339
When you type "/msg $me this is a test" you will get only "is a test"
340
341
<pre>
342 100 Per Amundsen
OnEvent if ($event == OnCommand) { /echo $0- }
343 1 Per Amundsen
</pre>
344
345 73 Per Amundsen
When you type "/msg $me this is a test" you will get "/msg $me this is a test"
346 76 Per Amundsen
347 79 Per Amundsen
$0- is now equal to $params and $msg, and $0 will return the first part e.g the command "/msg"
348 73 Per Amundsen
349 74 Per Amundsen
Also you can use $raw<number> like $raw0 $raw1 $raw0- to get parts of the raw irc message. This will likely be the default way when better parsing functions are added.
350
351
Several functions are added, they are all recursive and you can use any %variable or $variable as parameters:
352
They are also usable inside if () statements.
353 128 Per Amundsen
All variable numbers are floats and all functions supports floats for precise calculations.
354 74 Per Amundsen
<pre>
355
$replace(text, text2, text3) / replace all occurrences of text2 in text with text3
356
$upper(text) / return text uppercase
357
$lower(text) return text lowercase
358
$mid(text, startpos, endpos) / return part of text from startpos to endpos
359
$substr(text, startpos, endpos) / return part of text from startpos to endpos
360
$left(text, pos) / return pos characters starting from left of the text
361
$right(text, pos) / return pos characters starting from right of the text
362
$remove(text, text2) / replace all occurrences of text2 from text
363
$len(text) / return length of text
364
$count(text, text2) / counts all occurrences of text2 in text
365 77 Per Amundsen
$pos(text, text2) / returns first occurrences position of text2 in text
366
$lastpos(text, text2) / returns last occurrences position of text2 in text
367 96 Per Amundsen
$strip(text) / removes all color and font tags
368 1 Per Amundsen
$repeat(text, times) / repeats text X times
369
$insert(text, text2, pos) / inserts text2 into pos of text
370 132 Per Amundsen
$chr(num) / returns ascii character from the number num
371
$char(num) / returns ascii character from the number num
372
373 1 Per Amundsen
$calc(formula) / calculate any variation of +-*/
374 112 Per Amundsen
$formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
375
$fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
376 1 Per Amundsen
$host(nick) / returns the hostmask of nick
377
$ident(nick) / returns the ident of nick
378
$(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name)
379 132 Per Amundsen
$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
380
$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
381
$round(num, decimals) / rounds down a float to X decimals
382
$regex(text, pattern) / does a regular expression test if text matches pattern, then returns the matched part
383
384 1 Per Amundsen
$file(path) / reads file to end and returns the entire output without newlines
385
$fileloop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
386
$floop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
387 113 Per Amundsen
$filerandom(path) / returns a random line from a file
388 1 Per Amundsen
$frand(path) / returns a random line from a file
389 132 Per Amundsen
390
$chan(num) / if num is 0 returns how many channels you are joined on this server else returns channel name in position num
391
$user(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
392
$nick(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
393
$server(num) / if num is 0 returns how many servers you are connected to else returns server id in position num
394 75 Per Amundsen
</pre>
395
396 1 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.
397
All characters that needs to be escaped before used as strings are \ { } ;
398 134 Per Amundsen
In some cases you might have to escape ( ) | , # $ %
399
/* and */ needs to be escaped if you want to display them together\/* and \*/
400 75 Per Amundsen
401
<pre>
402 125 Per Amundsen
OnEvent if ($event == JOIN) { /echo $replace(this is a test, test, replaced test) }
403 82 Per Amundsen
</pre>
404 1 Per Amundsen
405
Shows "this is a replaced test"
406
407
<pre>
408
OnEvent if ($event == JOIN) { /echo $replace($replace(this is a test, test, replaced test), replaced test, replaced again test) }
409
</pre>
410 125 Per Amundsen
411 106 Per Amundsen
Shows "this is a replaced again test"
412 1 Per Amundsen
413 106 Per Amundsen
Here is an fullblown kickban example script using the script editor
414
<pre>
415 1 Per Amundsen
OnCommand /kb {
416
	if (!$1) {
417 138 Per Amundsen
		/echo /kb - Nick missing
418
		return
419 117 Per Amundsen
	}
420 126 Per Amundsen
421 138 Per Amundsen
	var %msg = $iif($channel, $2-, $3-)
422
	var %chan = $iif($channel, $channel, $2)
423 1 Per Amundsen
		
424
	# Set this for default ban reason, or remove for no default reason
425 138 Per Amundsen
	# Can be shortened to %msg = $iif(%msg, %msg, GTFO)
426
	if (%msg == null) %msg = GTFO
427 117 Per Amundsen
428
	if ($me isop %chan) {
429 138 Per Amundsen
		/raw MODE %chan +b *!$ident($1)@$host($1)
430
		/raw KICK %chan $1 %msg
431
	} 
432
	else /echo You are not oper on %chan
433 117 Per Amundsen
}
434
</pre>
435 1 Per Amundsen
436
Simple calculator script:
437
<pre>
438 106 Per Amundsen
OnCommand /calc {
439 1 Per Amundsen
	if (!$1) {
440 138 Per Amundsen
		/echo /calc - Parameters missing
441
		return
442 1 Per Amundsen
	}
443
		
444
	# typing /calc -p <expression> sends output to channel
445
	if ($1 == -p) {
446 138 Per Amundsen
		/msg $channel Calculating : $2-
447
		/msg $channel Result is : $calc($2-)
448 106 Per Amundsen
	} else {
449 138 Per Amundsen
		/echo Calculating : $1-
450
		/echo Result is : $calc($1-)
451 106 Per Amundsen
	}
452
}
453 1 Per Amundsen
</pre>
454
455 106 Per Amundsen
Colored version
456
<pre>
457
OnCommand /calc {
458 117 Per Amundsen
	if (!$1) {
459 138 Per Amundsen
		/echo /calc - Parameters missing
460
		return
461 98 Per Amundsen
	}
462 106 Per Amundsen
	
463
	# typing /calc -p <expression> sends output to channel
464 104 Per Amundsen
	if ($1 == -p) {
465 138 Per Amundsen
		/msg $channel $chr(3)4Calculating : $2-
466
		/msg $channel $chr(3)4Result is : $calc($2-)
467 106 Per Amundsen
	} else {
468 138 Per Amundsen
		/echo $chr(3)4Calculating : 4$1-
469
		/echo $chr(3)4Result is : $calc($1-)
470 133 Per Amundsen
	}
471 138 Per Amundsen
}*/
472 1 Per Amundsen
</pre>
473
474
CTCP flood detection example
475 103 Per Amundsen
476
<pre>
477 138 Per Amundsen
On OnCTCPRequest {
478
	if (%count == null) /set -u 10 %count 1
479
	else /inc -u 10 %count 1
480
481
	if (%count > 4) /ignore  -u 30 -t $nick!$ident@$host
482 1 Per Amundsen
}
483
</pre>
484 103 Per Amundsen
485
while (CONDITION) { EXECUTE } is now useable for a loop
486 1 Per Amundsen
487 103 Per Amundsen
Mass mode example
488
489
<pre>
490 117 Per Amundsen
OnCommand /mass {
491 133 Per Amundsen
	if (!$2) {
492 138 Per Amundsen
		/echo /mass - Parameters missing [+/-<mode> <nick> <nick> <nick>]
493
		return
494 1 Per Amundsen
	}
495 103 Per Amundsen
496 138 Per Amundsen
	%len = 2
497 1 Per Amundsen
	
498 117 Per Amundsen
	# equal to while (%len <= $count(%len, $chr(32)))
499 1 Per Amundsen
	while (%len <= $!) {
500 138 Per Amundsen
		if ($(%len) ison $channel) /mode $channel $1 $(%len)
501
		/inc %len
502 1 Per Amundsen
	}
503
}
504
</pre>
505
506
It is now possible to use custom commands as functions, lets say you make a /calc like this.
507
508
<pre>
509
OnCommand /mycalc {
510 121 Per Amundsen
	return $calc($0+$1);
511
}
512
</pre>
513
514
Then you can call this function with eiter /mycalc <number> <number> the normal way or $mycalc(<number, <number>) like this
515
<pre>
516
OnCommand /testcalc {
517
	/echo $0 + $1 is $mycalc($0, $1);
518
	/echo 5 + 4 is $mycalc(5, 4);
519
}
520
</pre>
521
522
Typing /testcalc will show the result. These custom functions are fully nested like the client functions.
523
524
Simple convert temperature C to F or F to C
525
<pre>
526 129 Per Amundsen
OnCommand /temp {
527 138 Per Amundsen
	if ($1 == C) /echo $calc(($2 * 9/5) + 32) F
528
	elseif ($1 == F) /echo $round($calc(($2 - 32) * 5/9), 1) C
529
	else /echo Temp missing
530 1 Per Amundsen
}
531
</pre>
532
/temp C 20 will print 68 F
533
534
Shows info about users on a channel
535
<pre>
536
On JOIN {
537 138 Per Amundsen
	var %t = 0
538
	/echo There are ($user($chan, 0)) users in ($chan)
539 132 Per Amundsen
	
540
	while (%t < $user($chan, 0)) {
541 138 Per Amundsen
		%t++
542
		var %nick = $user($chan, %t)
543
		/echo User (%t) is (%nick) and is $iif(%nick isop $chan, opped, not opped)
544 132 Per Amundsen
	}
545
}
546
</pre>
547
548
Shows info about servers, channels and users
549
<pre>
550
On JOIN {
551
	var %s = $server(0), %c = 0, %u = 0, %t = 0, %c2 = 0;
552
	
553
	while (%t < %s) {
554 138 Per Amundsen
		%t++
555 132 Per Amundsen
		/setserver $server(%t);
556 138 Per Amundsen
		%c += $chan(0)
557 132 Per Amundsen
	
558 138 Per Amundsen
		%c2 = 0
559 132 Per Amundsen
		while (%c2 < $chan(0)) {
560 138 Per Amundsen
			%c2++
561
			%u += $user($chan(%c2), 0)
562 132 Per Amundsen
		}
563
	}
564 138 Per Amundsen
565
	/echo You are on (%s) servers, (%c) channels with (%u) users
566 132 Per Amundsen
}
567 138 Per Amundsen
</pre>