Project

General

Profile

Scripting » History » Version 151

Per Amundsen, 08/14/2012 11:47 AM

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 148 Per Amundsen
*[[Scripting BETA]] Click here to see scripting in the latest beta versions.*
6 1 Per Amundsen
7 149 Per Amundsen
You can write full scripts in Commands -> Edit Scripts or you can create one liners in Commands -> Edit Commands
8 38 Per Amundsen
9 149 Per Amundsen
h1. Custom Commands:
10 1 Per Amundsen
11 149 Per Amundsen
Custom Commands are created in Commands -> Edit Commands
12 1 Per Amundsen
13 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)
14 1 Per Amundsen
15 150 Per Amundsen
*Alias*
16 149 Per Amundsen
<pre>
17
/hello /msg $channel hello everybody
18
</pre>
19 1 Per Amundsen
20 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.
21 1 Per Amundsen
22 150 Per Amundsen
*Hot keys*
23 149 Per Amundsen
<pre>
24
Ctrl&r /msg $channel hello everybody i pressed 'ctrl' and 'r'
25
</pre>
26 1 Per Amundsen
27 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.
28 1 Per Amundsen
29 149 Per Amundsen
You can comment out a command by putting a # in front of it.
30 1 Per Amundsen
31 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.
32 1 Per Amundsen
33 149 Per Amundsen
h1. Scripts:
34 1 Per Amundsen
35 150 Per Amundsen
*Events:*
36 149 Per Amundsen
There are different ways to listen to the irc client/server events for legacy reasons.
37
<pre>
38
OnEvent if ($event == PRIVMSG) { /EXECUTE }
39
OnBeforeEvent if ($event == PRIVMSG) { /EXECUTE }
40 1 Per Amundsen
41 149 Per Amundsen
On PRIVMSG { /EXECUTE }
42
OnBefore PRIVMSG { /EXECUTE }
43 1 Per Amundsen
44 149 Per Amundsen
OnBefore OnCommand { /EXECUTE }
45
OnCommand /mode { /EXECUTE }
46
</pre>
47 1 Per Amundsen
48 150 Per Amundsen
*Available events:*
49 149 Per Amundsen
<pre>
50
OnLoad / Called when the script is loaded
51
OnUnload / Called when the script is unloaded
52
OnReload / Called when the script is reloaded
53
OnConnecting / Called when a server is connecting
54
OnLookingUp / Called when a server is looking up the hostname
55
OnConnected / Called when a server is connected
56
OnDisconnect / Called when a server gets disconnected
57
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)
58 1 Per Amundsen
59 149 Per Amundsen
OnCTCPRequest / Called when a user recives a CTCP request
60
OnCTCPReply / Called when a user recives a CTCP reply
61
OnDCCRequest / Called when a user recived a DCC request
62 1 Per Amundsen
63 149 Per Amundsen
OnNickChanged / Called when a user's nick changes, will only trigger on the user unlike NICK who triggers for everyone
64
OnSongChanged / Called when a song is changed in the selected media player
65 1 Per Amundsen
66 149 Per Amundsen
OnDeVoice / Called when a user gets devoiced
67
OnVoice / Called when a user gets voiced
68
OnDeHop / Called when a user gets dehalfoppeed
69
OnHop / Called when a user gets halfopped
70
OnOp / Called when a user gets opped
71
OnDeOp / Called when a user gets deopped
72
OnDeOwner/ Called when a user gets owner deopped
73
OnOwner/ Called when a user gets owner opped
74
OnDeSop / Called when a user gets special deopped
75
OnSop / Called when a user gets special opped
76 1 Per Amundsen
77 149 Per Amundsen
MODE / Called whenever a channel or user mode is changed
78
JOIN / Called whenever a user joins a channel
79
PART / Called when a user parts a channel 
80
NICK / Called when a user changes their nick
81
TOPIC / Called when a topic is set/changed
82
KICK / Called when any user gets kicked
83
NOTICE / Called when any notice is recived
84
QUIT / Called when a user quits irc
85
PRIVMSG / Called when any message is recived
86
WHOIS / Called when any whois reply is recived
87
LIST / Called when a user gets a /list
88
KILL / Called when a user gets killed
89
ACTION / Called when a user recives a ACTION (/me) message
90 1 Per Amundsen
91 149 Per Amundsen
<irc numeric> / Called when a raw irc line with <irc numeric> is recived
92
<irc textual> / Called when a raw irc line with <irc textual> is recived
93
</pre>
94 1 Per Amundsen
95 150 Per Amundsen
*if/else if/else blocks:*
96 1 Per Amundsen
97 149 Per Amundsen
You can use any combination of if, else if, else and while
98
<pre>
99
OnEvent if ($event == PRIVMSG) { 
100
	if (%test == null) { 
101
		/echo Hello world
102
		if (%test == null) { 
103
			/echo Hello world
104
		}
105
		else /echo Hello World
106
	} else if (%test == null) { 
107
		/echo Hello world
108
	} else (%test == null) { 
109
		/echo Hello world 
110
	} 
111 1 Per Amundsen
112 149 Per Amundsen
	if (%test == null) { 
113
		/echo Hello world
114
		while (%test == null) {
115
			/echo Hello world
116
		}
117
	}
118 1 Per Amundsen
119 149 Per Amundsen
	if(%test == null)/echo Hello World
120
	else if(%test == null)/echo Hello World
121
	else/echo Hello world
122
	
123
	if(%test == null){/echo Hello World
124
	}else if(%test == null){/echo Hello World
125
	}else{/echo Hello World
126
	}
127 1 Per Amundsen
128 149 Per Amundsen
	if(%test == null){/echo Hello World}else if(%test == null){/echo Hello World}else{/echo Hello World}
129
}
130
</pre>
131 1 Per Amundsen
132 150 Per Amundsen
*while blocks:*
133 151 Per Amundsen
<pre>
134 149 Per Amundsen
On JOIN {
135
	var %t = 0
136
	/echo There are ($user($chan, 0)) users in ($chan)
137
	
138
	while (%t < $user($chan, 0)) {
139
		%t++
140
		var %nick = $user($chan, %t)
141
		/echo User (%t) is (%nick) and is $iif(%nick isop $chan, opped, not opped)
142
	}
143
}
144
</pre>
145 1 Per Amundsen
146 150 Per Amundsen
*goto/label:*
147 1 Per Amundsen
148
<pre>
149 149 Per Amundsen
OnCommand /goto {
150
	var %loop = 0 
151
	if ($1 == 1) {
152
		goto 1
153
	} else if ($1 == 2) {
154
		goto 2
155
	} else if ($1 == loop) {
156
		:3
157
		/echo you typed loop
158
		%loop++
159
		if (%loop < 5) {
160
			goto 3
161
		}
162
		return
163
	} else {
164
		goto 4
165
	}
166 1 Per Amundsen
167 149 Per Amundsen
	:1
168
	/echo You typed 1
169
	return
170
	:2
171
	/echo You typed 2
172
	return
173
	:4
174
	/echo The end
175
	return
176
}
177
</pre>
178 1 Per Amundsen
179 150 Per Amundsen
*client variables:*
180 1 Per Amundsen
$event / current event, e.g PRIVMSG 001 MODE and so forth
181
$channel / the channel the event occurred on, if any
182
$msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick
183
$nick / the nick the event was sent from, can be a irc.server.com, a nick or null
184
$me / my current nick
185
$network / the network the event occured on e.g Quakenet
186
$ident / the from user ident if any
187
$host / the from user hostname if any
188
$myident / my ident
189
$myhost / my host
190
$server / host from the server e.g irc.server.com
191 149 Per Amundsen
$now / returns unixtime/ctime from current time.
192
$active / returns the current window Status/#channel/Nick.
193
$activeserver / returns an id for current server
194
$status / returns current server status
195
$crlf / returns newline \r\n
196
$0-$9 / will return parts of the $msg, $<number>- will combine parts of the $msg from 0 to <number>. $0- will return everything
197
$! / returns how many $0 $1 etc variables are filled (not sure if final name of it)
198
$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
199
$r! / returns how many $raw0 $raw1 etc variables are filled (not sure if final name of it)
200 1 Per Amundsen
201 150 Per Amundsen
*user set variables*
202 149 Per Amundsen
var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script is done.
203
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.
204 1 Per Amundsen
205 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.
206
207 150 Per Amundsen
*Commands for manipulating variables:*
208 1 Per Amundsen
<pre>
209 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
210 1 Per Amundsen
211 149 Per Amundsen
/unset [var] / deletes a variable
212 1 Per Amundsen
213 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
214 1 Per Amundsen
215 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
216 1 Per Amundsen
217 149 Per Amundsen
/vars shows a list of all variables and their values
218
</pre>
219 1 Per Amundsen
220 150 Per Amundsen
*functions:*
221 149 Per Amundsen
Several functions are exsists, they are all recursive and you can use any %variable or $variable as parameters:
222
They are also usable inside if () else if () while () statements.
223
All variable numbers are floats and all functions supports floats for precise calculations.
224 36 Per Amundsen
225
<pre>
226 149 Per Amundsen
$replace(text, text2, text3) / replace all occurrences of text2 in text with text3
227
$upper(text) / return text uppercase
228
$lower(text) return text lowercase
229
$mid(text, startpos, endpos) / return part of text from startpos to endpos
230
$substr(text, startpos, endpos) / return part of text from startpos to endpos
231
$left(text, pos) / return pos characters starting from left of the text
232
$right(text, pos) / return pos characters starting from right of the text
233
$remove(text, text2) / replace all occurrences of text2 from text
234
$len(text) / return length of text
235
$count(text, text2) / counts all occurrences of text2 in text
236
$pos(text, text2) / returns first occurrences position of text2 in text
237
$lastpos(text, text2) / returns last occurrences position of text2 in text
238
$strip(text) / removes all color and font tags
239
$repeat(text, times) / repeats text X times
240
$insert(text, text2, pos) / inserts text2 into pos of text
241
$chr(num) / returns ascii character from the number num
242
$char(num) / returns ascii character from the number num
243 1 Per Amundsen
244 149 Per Amundsen
$calc(formula) / calculate any variation of +-*/
245
$formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
246
$fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc
247
$ctime(datestamp) / converts most variations of a date stamp to unix/ctime
248
$datediff(ctime1, ctime2) / diffs two unix/ctime and fills the $datematch array with values
249
$datematch(num) / returns part of a $datediff, 0 = milliseconds, 1 = seconds, 2 = minutes, 3 = hours, 4 = days
250
$host(nick) / returns the hostmask of nick
251
$ident(nick) / returns the ident of nick
252
$(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name)
253
$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
254
$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
255
$round(num, decimals) / rounds down a float to X decimals
256
$regex(text, pattern) / does a regular expression test if text matches pattern, then returns the matched part
257
$regmatch(num) / returns the captured group at pos num from a $regex. 0 returns group count
258
$regreplace(text, pattern, text2) / replace any occurence in text of patterh with text2 where pattern is a regular expression
259 3 Per Amundsen
260 149 Per Amundsen
$file(path) / reads file to end and returns the entire output without newlines
261
$fileloop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
262
$floop(path) / reads through a file one line at the time, line increases +1 every time the same file is called
263
$filerandom(path) / returns a random line from a file
264
$frand(path) / returns a random line from a file
265
$fread(name) / reads a line from current pos in file named name
266
$fileread(name) / reads a line from current pos in file named name
267
$freadc(name) / reads a char/byte from current pos in file named name
268
$freadchar(name) / reads a char/byte from current pos in file named name
269
$fsize(file) / returns size off file in bytes
270
$filesize(file) / returns size off file in bytes
271
$fpos(name) / returns current position/byte in file named name
272
$filepos(name) / returns current position/byte in file named name
273
$flines(file) / returns amount of lines in file
274
$filelines(file) / returns amount of lines in file
275
$fileexists(file) / returns if file exists or not
276
$isfile(file) / returns if file exists or not
277 1 Per Amundsen
278 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
279
$user(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
280
$nick(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num
281
$server(num) / if num is 0 returns how many servers you are connected to else returns server id in position num
282 1 Per Amundsen
283 149 Per Amundsen
$sread(name) / reads available bytes from socket named name (on sockread)
284
$sockread(name) / reads available bytes from socket named name (on sockread)
285
$sbytes(name) / returns amount of available bytes to be read from socket named name
286
$sockbytes(name) / returns amount of available bytes to be read from socket named name
287 1 Per Amundsen
</pre>