Project

General

Profile

Scripting » History » Revision 151

Revision 150 (Per Amundsen, 08/14/2012 11:45 AM) → Revision 151/246 (Per Amundsen, 08/14/2012 11:47 AM)

h1. Notice: this is info for 1.8.10 and higher. 

 h1. Scripting 

 *[[Scripting BETA]] Click here to see scripting in the latest beta versions.* 

 You can write full scripts in Commands -> Edit Scripts or you can create one liners in Commands -> Edit Commands 

 h1. Custom Commands: 

 Custom Commands are created in Commands -> Edit Commands 

 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) 

 *Alias* 
 <pre> 
 /hello /msg $channel hello everybody 
 </pre> 

 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. 

 *Hot keys* 
 <pre> 
 Ctrl&r /msg $channel hello everybody i pressed 'ctrl' and 'r' 
 </pre> 

 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. 

 You can comment out a command by putting a # in front of it. 

 It is also possible to use a full script, but it has to be on one line, and the script editor is preferred. 

 h1. Scripts: 

 *Events:* 
 There are different ways to listen to the irc client/server events for legacy reasons. 
 <pre> 
 OnEvent if ($event == PRIVMSG) { /EXECUTE } 
 OnBeforeEvent if ($event == PRIVMSG) { /EXECUTE } 

 On PRIVMSG { /EXECUTE } 
 OnBefore PRIVMSG { /EXECUTE } 

 OnBefore OnCommand { /EXECUTE } 
 OnCommand /mode { /EXECUTE } 
 </pre> 

 *Available events:* 
 <pre> 
 OnLoad / Called when the script is loaded 
 OnUnload / Called when the script is unloaded 
 OnReload / Called when the script is reloaded 
 OnConnecting / Called when a server is connecting 
 OnLookingUp / Called when a server is looking up the hostname 
 OnConnected / Called when a server is connected 
 OnDisconnect / Called when a server gets disconnected 
 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) 

 OnCTCPRequest / Called when a user recives a CTCP request 
 OnCTCPReply / Called when a user recives a CTCP reply 
 OnDCCRequest / Called when a user recived a DCC request 

 OnNickChanged / Called when a user's nick changes, will only trigger on the user unlike NICK who triggers for everyone 
 OnSongChanged / Called when a song is changed in the selected media player 

 OnDeVoice / Called when a user gets devoiced 
 OnVoice / Called when a user gets voiced 
 OnDeHop / Called when a user gets dehalfoppeed 
 OnHop / Called when a user gets halfopped 
 OnOp / Called when a user gets opped 
 OnDeOp / Called when a user gets deopped 
 OnDeOwner/ Called when a user gets owner deopped 
 OnOwner/ Called when a user gets owner opped 
 OnDeSop / Called when a user gets special deopped 
 OnSop / Called when a user gets special opped 

 MODE / Called whenever a channel or user mode is changed 
 JOIN / Called whenever a user joins a channel 
 PART / Called when a user parts a channel  
 NICK / Called when a user changes their nick 
 TOPIC / Called when a topic is set/changed 
 KICK / Called when any user gets kicked 
 NOTICE / Called when any notice is recived 
 QUIT / Called when a user quits irc 
 PRIVMSG / Called when any message is recived 
 WHOIS / Called when any whois reply is recived 
 LIST / Called when a user gets a /list 
 KILL / Called when a user gets killed 
 ACTION / Called when a user recives a ACTION (/me) message 

 <irc numeric> / Called when a raw irc line with <irc numeric> is recived 
 <irc textual> / Called when a raw irc line with <irc textual> is recived 
 </pre> 

 *if/else if/else blocks:* 

 You can use any combination of if, else if, else and while 
 <pre> 
 OnEvent if ($event == PRIVMSG) {  
	 if (%test == null) {  
		 /echo Hello world 
		 if (%test == null) {  
			 /echo Hello world 
		 } 
		 else /echo Hello World 
	 } else if (%test == null) {  
		 /echo Hello world 
	 } else (%test == null) {  
		 /echo Hello world  
	 }  

	 if (%test == null) {  
		 /echo Hello world 
		 while (%test == null) { 
			 /echo Hello world 
		 } 
	 } 

	 if(%test == null)/echo Hello World 
	 else if(%test == null)/echo Hello World 
	 else/echo Hello world 
	
	 if(%test == null){/echo Hello World 
	 }else if(%test == null){/echo Hello World 
	 }else{/echo Hello World 
	 } 

	 if(%test == null){/echo Hello World}else if(%test == null){/echo Hello World}else{/echo Hello World} 
 } 
 </pre> 

 *while blocks:* 
 <pre> 
 On JOIN { 
	 var %t = 0 
	 /echo There are ($user($chan, 0)) users in ($chan) 
	
	 while (%t < $user($chan, 0)) { 
		 %t++ 
		 var %nick = $user($chan, %t) 
		 /echo User (%t) is (%nick) and is $iif(%nick isop $chan, opped, not opped) 
	 } 
 } 
 </pre> 

 *goto/label:* 

 <pre> 
 OnCommand /goto { 
	 var %loop = 0  
	 if ($1 == 1) { 
		 goto 1 
	 } else if ($1 == 2) { 
		 goto 2 
	 } else if ($1 == loop) { 
		 :3 
		 /echo you typed loop 
		 %loop++ 
		 if (%loop < 5) { 
			 goto 3 
		 } 
		 return 
	 } else { 
		 goto 4 
	 } 

	 :1 
	 /echo You typed 1 
	 return 
	 :2 
	 /echo You typed 2 
	 return 
	 :4 
	 /echo The end 
	 return 
 } 
 </pre> 

 *client variables:* 
 $event / current event, e.g PRIVMSG 001 MODE and so forth 
 $channel / the channel the event occurred on, if any 
 $msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick 
 $nick / the nick the event was sent from, can be a irc.server.com, a nick or null 
 $me / my current nick 
 $network / the network the event occured on e.g Quakenet 
 $ident / the from user ident if any 
 $host / the from user hostname if any 
 $myident / my ident 
 $myhost / my host 
 $server / host from the server e.g irc.server.com 
 $now / returns unixtime/ctime from current time. 
 $active / returns the current window Status/#channel/Nick. 
 $activeserver / returns an id for current server 
 $status / returns current server status 
 $crlf / returns newline \r\n 
 $0-$9 / will return parts of the $msg, $<number>- will combine parts of the $msg from 0 to <number>. $0- will return everything 
 $! / returns how many $0 $1 etc variables are filled (not sure if final name of it) 
 $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 
 $r! / returns how many $raw0 $raw1 etc variables are filled (not sure if final name of it) 

 *user set variables* 
 var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script is done. 
 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. 

 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. 

 *Commands for manipulating variables:* 
 <pre> 
 /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 

 /unset [var] / deletes a variable 

 /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 

 /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 

 /vars shows a list of all variables and their values 
 </pre> 

 *functions:* 
 Several functions are exsists, they are all recursive and you can use any %variable or $variable as parameters: 
 They are also usable inside if () else if () while () statements. 
 All variable numbers are floats and all functions supports floats for precise calculations. 

 <pre> 
 $replace(text, text2, text3) / replace all occurrences of text2 in text with text3 
 $upper(text) / return text uppercase 
 $lower(text) return text lowercase 
 $mid(text, startpos, endpos) / return part of text from startpos to endpos 
 $substr(text, startpos, endpos) / return part of text from startpos to endpos 
 $left(text, pos) / return pos characters starting from left of the text 
 $right(text, pos) / return pos characters starting from right of the text 
 $remove(text, text2) / replace all occurrences of text2 from text 
 $len(text) / return length of text 
 $count(text, text2) / counts all occurrences of text2 in text 
 $pos(text, text2) / returns first occurrences position of text2 in text 
 $lastpos(text, text2) / returns last occurrences position of text2 in text 
 $strip(text) / removes all color and font tags 
 $repeat(text, times) / repeats text X times 
 $insert(text, text2, pos) / inserts text2 into pos of text 
 $chr(num) / returns ascii character from the number num 
 $char(num) / returns ascii character from the number num 

 $calc(formula) / calculate any variation of +-*/ 
 $formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc 
 $fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc 
 $ctime(datestamp) / converts most variations of a date stamp to unix/ctime 
 $datediff(ctime1, ctime2) / diffs two unix/ctime and fills the $datematch array with values 
 $datematch(num) / returns part of a $datediff, 0 = milliseconds, 1 = seconds, 2 = minutes, 3 = hours, 4 = days 
 $host(nick) / returns the hostmask of nick 
 $ident(nick) / returns the ident of nick 
 $(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name) 
 $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 
 $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 
 $round(num, decimals) / rounds down a float to X decimals 
 $regex(text, pattern) / does a regular expression test if text matches pattern, then returns the matched part 
 $regmatch(num) / returns the captured group at pos num from a $regex. 0 returns group count 
 $regreplace(text, pattern, text2) / replace any occurence in text of patterh with text2 where pattern is a regular expression 

 $file(path) / reads file to end and returns the entire output without newlines 
 $fileloop(path) / reads through a file one line at the time, line increases +1 every time the same file is called 
 $floop(path) / reads through a file one line at the time, line increases +1 every time the same file is called 
 $filerandom(path) / returns a random line from a file 
 $frand(path) / returns a random line from a file 
 $fread(name) / reads a line from current pos in file named name 
 $fileread(name) / reads a line from current pos in file named name 
 $freadc(name) / reads a char/byte from current pos in file named name 
 $freadchar(name) / reads a char/byte from current pos in file named name 
 $fsize(file) / returns size off file in bytes 
 $filesize(file) / returns size off file in bytes 
 $fpos(name) / returns current position/byte in file named name 
 $filepos(name) / returns current position/byte in file named name 
 $flines(file) / returns amount of lines in file 
 $filelines(file) / returns amount of lines in file 
 $fileexists(file) / returns if file exists or not 
 $isfile(file) / returns if file exists or not 

 $chan(num) / if num is 0 returns how many channels you are joined on this server else returns channel name in position num 
 $user(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num 
 $nick(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num 
 $server(num) / if num is 0 returns how many servers you are connected to else returns server id in position num 

 $sread(name) / reads available bytes from socket named name (on sockread) 
 $sockread(name) / reads available bytes from socket named name (on sockread) 
 $sbytes(name) / returns amount of available bytes to be read from socket named name 
 $sockbytes(name) / returns amount of available bytes to be read from socket named name 
 </pre>