Project

General

Profile

Scripting » History » Revision 149

Revision 148 (Per Amundsen, 04/10/2012 07:28 AM) → Revision 149/246 (Per Amundsen, 08/14/2012 11:43 AM)

h1. Notice: this is info for 1.8.10 1.8.8 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 There are 2 types of scripting at the moment, one liners in Commands -> Edit Commands that have been here for a long time, and a new system. 

 h1. Custom Commands: 

 Custom Commands are created All scripting is done in Commands -> Edit Commands 

 Custom commands consists of differents ways to execute where one line represent a script either by making your own command, or use a hotkey, you can also enter a full script as a custom command and its trigger is one liner (for legacy reasons) of 3 ways: 

 <b>Alias</b> /something<whitespace>  
 keys<whitespace> 
 <pre> 
 /hello /msg $channel hello everybody 
 </pre> OnEvent<whitespace> 

 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. 

 <b>Hot keys</b> 
 <pre> 
 Ctrl&r /msg $channel hello everybody i pressed 'ctrl' Please note that variables and 'r' 
 </pre> functions are *different* for these 2 types of scripts. 

 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 h1. Normal custom commands: 

 <pre>Syntax = /something<whitespace>/somethingelse</pre> 

 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 use a full script, but it has $chan</pre> will show <pre>* kr0n says hi to be on one line, and the script editor is preferred. #adiirc</pre> when typing <pre>/hi</pre> 

 h1. Scripts: 

 <b>Events/aliases:</b> 
 There Current variables are different ways $1 to listen $9, $params, $chan and $me. $1 to the irc client/server events for legacy reasons. 
 <pre> 
 OnEvent if ($event == PRIVMSG) { /EXECUTE } 
 OnBeforeEvent if ($event == PRIVMSG) { /EXECUTE } $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> 

 On PRIVMSG { /EXECUTE } 
 OnBefore PRIVMSG { /EXECUTE } $params represents everything written after /yourcommand, $chan replaces itself with current channel and $me replaces itself with your current usernick.  

 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> 

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

 <b>Available events:</b> 
 <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 $file[path] returns data from a server is connecting 
 OnLookingUp / Called when file, $frand[path] fetchs a server is looking up the hostname 
 OnConnected / Called when random line from a server is connected 
 OnDisconnect / Called when a server file and $floop[path] gets disconnected 
 OnCommand / Called whenever one line increasingly (line1, then line2, then line3 etc). 

 h1. Custom Commands by hotkeys 

 <pre>Syntax = key&key<whitespace>/something</pre> 

 In addition to making a user types custom command trigger by typing a /slash command in the client ($0- will hold the full command, $0 you make it trigger with a hotkey instead (note, these commmands will not be useable from the first word, $1 the second new scripting engine) 

 Useable modifies are ctrl, alt and so on) shift and any character or number or F key. 

 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 An example 

 OnNickChanged / Called when a user's nick changes, <pre>ctrl&o /msg $chan ohai i just pressed ctrl and o</pre> 

 Everytime you press ctrl and 'o' now, this command will only trigger on the user unlike NICK who triggers for everyone 
 OnSongChanged / Called when a song is changed in the selected media player be fired off. 

 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 <pre>ctrl&alt&o /msg $chan ohai i just pressed ctrl and alt and o</pre> 

 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 Everytime you press ctrl and alt and 'o' now, this command will be fired off. 

 <irc numeric> / Called when h1. Unified Scripting 

 <pre>Syntax = OnEvent<whitespace>code</pre> 

 The new scripting tries to combine normal client commands, your custom commands, functions and events into one scripting language. 

 In Commands -> Edit Commands you can enter a raw irc scripting line with <irc numeric> is recived 
 <irc textual> / Called when a raw irc line with <irc textual> is recived 
 </pre> the following syntax: 

 <b>if/else if/else blocks:</b> Followed by either an expression like this (works recursivly) 

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

	 
 if (%test == null) (SOMETING ismatch SOMETHINGELSE) {  
		 /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} EXECUTE HERE }</pre> 
 } 
 </pre> or by an executed command or function 

 <b>while blocks:</b> 
 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) You can now combine expressions with && (AND) and is $iif(%nick isop $chan, opped, not opped) 
	 } || (OR) like this 
 } 
 </pre> 

 <b>goto/label:</b> 

 <pre> 
 OnCommand /goto if (SOMETHING == SOMETHING && SOMETHINGELSE != SOMETHINGELSE) { 
	 var %loop = 0  
	 EXECUTE HERE } 
 if ($1 (SOMETHING == 1) SOMETHING || SOMETHINGELSE != SOMETHINGELSE) { 
		 goto 1 
	 } EXECUTE HERE }</pre> 
 The logic behind these expressions is not fully tested, id love any feedback on this. 

 It is also possible to use else if ($1 like this 
 <pre>if (SOMETHING == 2) SOMETHING) { 
		 goto 2 
	 EXECUTE HERE } else if ($1 (SOMETHINGELSE == loop) SOMETHINGELSE) { 
		 :3 
		 /echo you typed loop 
		 %loop++ 
		 EXECUTE HERE }</pre> 
 In the future just "else" will be possible to. 

 (note: ismatch will check if (%loop < 5) { 
			 goto 3 
		 } 
		 return 
	 } SOMETHING exist inside SOMETHINGELSE e.g if something is "hello" and something else { 
		 goto 4 
	 } 

	 :1 
	 /echo You typed 1 
	 is "hello world" it would return 
	 :2 
	 /echo You typed 2 
	 return 
	 :4 
	 /echo The end 
	 return True because "hello" exist) 

 Executed commands are /slash commands already in the client e.g /msg #channel hello world. 
 } 
 </pre> Executed functions are predefined functions in the client, only two exists for now. 

 <b>client variables:</b> 
 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> 

 Furthermore there is a lot of predefined variables for use with these functions, for now they are: 

 $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 

 Currently predefined functions are: 
 $now / returns unixtime/ctime from current time. <pre> 
 $active / returns the current window Status/#channel/Nick. 
 $activeserver / returns an id .insert <nick (use null for current server nonick)>  
 <where (a channel or $channel, a nick or $nick, or status)>  
 <MsgType (MsgServer/MsgUser/MsgEmote/MsgCTCP/MsgNotice/MsgClient/MsgLog)>  
 <$msg or message></pre> 

 <pre> 
 $status / returns current server status .eat <what (text or all)></pre> 
 $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 .insert is used for inserting a specific message from 0 type into a chat window, its intended for use in cases where you want to <number>. $raw0- will return everything 
 $r! / returns override how many $raw0 $raw1 etc variables are filled (not sure if final name of it) adiirc shows a given event, but can also be used for adding additional messages. 

 <b>user set variables</b> 
 var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script .eat is done. 
 using += instead of = will append used to the variable, if both variable and new value is numbers it will combine them tell adiirc to a new number %variable += 4242. 

 If a variable is created without var, either "eat" 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 text output from an event 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 "eat" everything 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 don't act on this event at all. 

 /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 Putting it 

 /vars shows all togheter, here are a list of all variables and their values 
 </pre> few examples: 

 <b>functions:</b> <pre> 
 Several functions are exsists, they are all recursive and you can use any %variable or $variable as parameters: 
 They are also usable inside OnEvent if () else ($event == NOTICE) { if () while () statements. 
 All variable numbers are floats and all functions supports floats for precise calculations. ($msg ismatch hi there) { .insert $nick status MsgNotice $msg | .eat text } }</pre> 

 <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 insert the text 
 $right(text, pos) / return pos characters starting from right of notice into 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 server window and font tags 
 $repeat(text, times) / repeats tells adiirc to "eat" its own text X times 
 $insert(text, text2, pos) / inserts text2 into pos of text 
 $chr(num) / returns ascii character output from the number num this notice 

 <pre> 
 $char(num) / returns ascii character from the number num OnEvent if ($event == PRIVMSG && $msg == herp) { /msg $channel derp }</pre> 

 $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 if the $datematch array with values 
 $datematch(num) / returns part of event is a $datediff, 0 = milliseconds, 1 = seconds, 2 = minutes, 3 = hours, 4 = days 
 $host(nick) / returns PRIVMSG AND the hostmask of nick 
 $ident(nick) / returns $msg equals "herp", then show "derp" in the ident of nick channel 

 <pre> 
 $(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure OnEvent if final function name) 
 $cond(cond, execute1, execute2) / checks ($event == PRIVMSG) { if cond ($nick == Q || $nick == $me) { /msg $channel Q or $me is true then executes execute1, else executes execute2, will return string speaking! } }</pre> 

 if not at the begining of event is a PRIVMSG and the line 
 $iif(cond, execute1, execute2) / checks if cond $nick equals "Q" OR $me then show "Q or $me is true then executes execute1, else executes execute2, will return string if not at speaking" in the begining of the line 
 $round(num, decimals) / rounds down a float to X decimals 
 $regex(text, pattern) / does a regular expression test channel 

 <pre>OnEvent if text matches pattern, then returns ($event == OnOp && $nick == $me) { /msg $channel Thx for op! }</pre> 

 if 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 event is a regular expression 

 $file(path) / reads file to end OnOp 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 target nick is called 
 $floop(path) / reads through a file one line at me, then show "Thx for op!" in the time, line increases +1 every time the same file channel 

 A list of custom events that is called also usable as $event == 
 $filerandom(path) / returns a random line from a file <pre> 
 $frand(path) / returns a random line from a file OnOwner 
 $fread(name) / reads a line from current pos in file named name OnDeOwner 
 $fileread(name) / reads a line from current pos in file named name OnSpecialOp 
 $freadc(name) / reads a char/byte from current pos in file named name OnSpecialDeOp 
 $freadchar(name) / reads a char/byte from current pos in file named name OnOp 
 $fsize(file) / returns size off file in bytes OnDeOp 
 $filesize(file) / returns size off file in bytes OnHop 
 $fpos(name) / returns current position/byte in file named name OnDeHop 
 $filepos(name) / returns current position/byte in file named name OnVoice 
 $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 OnDeVoice 
 </pre>