Scripting » History » Version 149
Per Amundsen, 08/14/2012 11:43 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 | 149 | Per Amundsen | <b>Alias</b> |
| 16 | <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 | 149 | Per Amundsen | <b>Hot keys</b> |
| 23 | <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 | 149 | Per Amundsen | <b>Events/aliases:</b> |
| 36 | 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 | 149 | Per Amundsen | <b>Available events:</b> |
| 49 | <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 | 149 | Per Amundsen | <b>if/else if/else blocks:</b> |
| 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 | 149 | Per Amundsen | <b>while blocks:</b> |
| 133 | On JOIN { |
||
| 134 | var %t = 0 |
||
| 135 | /echo There are ($user($chan, 0)) users in ($chan) |
||
| 136 | |||
| 137 | while (%t < $user($chan, 0)) { |
||
| 138 | %t++ |
||
| 139 | var %nick = $user($chan, %t) |
||
| 140 | /echo User (%t) is (%nick) and is $iif(%nick isop $chan, opped, not opped) |
||
| 141 | } |
||
| 142 | } |
||
| 143 | </pre> |
||
| 144 | 1 | Per Amundsen | |
| 145 | 149 | Per Amundsen | <b>goto/label:</b> |
| 146 | 1 | Per Amundsen | |
| 147 | <pre> |
||
| 148 | 149 | Per Amundsen | OnCommand /goto { |
| 149 | var %loop = 0 |
||
| 150 | if ($1 == 1) { |
||
| 151 | goto 1 |
||
| 152 | } else if ($1 == 2) { |
||
| 153 | goto 2 |
||
| 154 | } else if ($1 == loop) { |
||
| 155 | :3 |
||
| 156 | /echo you typed loop |
||
| 157 | %loop++ |
||
| 158 | if (%loop < 5) { |
||
| 159 | goto 3 |
||
| 160 | } |
||
| 161 | return |
||
| 162 | } else { |
||
| 163 | goto 4 |
||
| 164 | } |
||
| 165 | 1 | Per Amundsen | |
| 166 | 149 | Per Amundsen | :1 |
| 167 | /echo You typed 1 |
||
| 168 | return |
||
| 169 | :2 |
||
| 170 | /echo You typed 2 |
||
| 171 | return |
||
| 172 | :4 |
||
| 173 | /echo The end |
||
| 174 | return |
||
| 175 | } |
||
| 176 | </pre> |
||
| 177 | 1 | Per Amundsen | |
| 178 | 149 | Per Amundsen | <b>client variables:</b> |
| 179 | 1 | Per Amundsen | $event / current event, e.g PRIVMSG 001 MODE and so forth |
| 180 | $channel / the channel the event occurred on, if any |
||
| 181 | $msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick |
||
| 182 | $nick / the nick the event was sent from, can be a irc.server.com, a nick or null |
||
| 183 | $me / my current nick |
||
| 184 | $network / the network the event occured on e.g Quakenet |
||
| 185 | $ident / the from user ident if any |
||
| 186 | $host / the from user hostname if any |
||
| 187 | $myident / my ident |
||
| 188 | $myhost / my host |
||
| 189 | $server / host from the server e.g irc.server.com |
||
| 190 | 149 | Per Amundsen | $now / returns unixtime/ctime from current time. |
| 191 | $active / returns the current window Status/#channel/Nick. |
||
| 192 | $activeserver / returns an id for current server |
||
| 193 | $status / returns current server status |
||
| 194 | $crlf / returns newline \r\n |
||
| 195 | $0-$9 / will return parts of the $msg, $<number>- will combine parts of the $msg from 0 to <number>. $0- will return everything |
||
| 196 | $! / returns how many $0 $1 etc variables are filled (not sure if final name of it) |
||
| 197 | $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 |
||
| 198 | $r! / returns how many $raw0 $raw1 etc variables are filled (not sure if final name of it) |
||
| 199 | 1 | Per Amundsen | |
| 200 | 149 | Per Amundsen | <b>user set variables</b> |
| 201 | var %variable = 4242, %variable2 = 4343; will create local variables that gets deleted when the script is done. |
||
| 202 | 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. |
||
| 203 | 1 | Per Amundsen | |
| 204 | 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. |
| 205 | |||
| 206 | Commands for manipulating variables: |
||
| 207 | 1 | Per Amundsen | <pre> |
| 208 | 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 |
| 209 | 1 | Per Amundsen | |
| 210 | 149 | Per Amundsen | /unset [var] / deletes a variable |
| 211 | 1 | Per Amundsen | |
| 212 | 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 |
| 213 | 1 | Per Amundsen | |
| 214 | 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 |
| 215 | 1 | Per Amundsen | |
| 216 | 149 | Per Amundsen | /vars shows a list of all variables and their values |
| 217 | </pre> |
||
| 218 | 1 | Per Amundsen | |
| 219 | 149 | Per Amundsen | <b>functions:</b> |
| 220 | Several functions are exsists, they are all recursive and you can use any %variable or $variable as parameters: |
||
| 221 | They are also usable inside if () else if () while () statements. |
||
| 222 | All variable numbers are floats and all functions supports floats for precise calculations. |
||
| 223 | 36 | Per Amundsen | |
| 224 | <pre> |
||
| 225 | 149 | Per Amundsen | $replace(text, text2, text3) / replace all occurrences of text2 in text with text3 |
| 226 | $upper(text) / return text uppercase |
||
| 227 | $lower(text) return text lowercase |
||
| 228 | $mid(text, startpos, endpos) / return part of text from startpos to endpos |
||
| 229 | $substr(text, startpos, endpos) / return part of text from startpos to endpos |
||
| 230 | $left(text, pos) / return pos characters starting from left of the text |
||
| 231 | $right(text, pos) / return pos characters starting from right of the text |
||
| 232 | $remove(text, text2) / replace all occurrences of text2 from text |
||
| 233 | $len(text) / return length of text |
||
| 234 | $count(text, text2) / counts all occurrences of text2 in text |
||
| 235 | $pos(text, text2) / returns first occurrences position of text2 in text |
||
| 236 | $lastpos(text, text2) / returns last occurrences position of text2 in text |
||
| 237 | $strip(text) / removes all color and font tags |
||
| 238 | $repeat(text, times) / repeats text X times |
||
| 239 | $insert(text, text2, pos) / inserts text2 into pos of text |
||
| 240 | $chr(num) / returns ascii character from the number num |
||
| 241 | $char(num) / returns ascii character from the number num |
||
| 242 | 1 | Per Amundsen | |
| 243 | 149 | Per Amundsen | $calc(formula) / calculate any variation of +-*/ |
| 244 | $formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc |
||
| 245 | $fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc |
||
| 246 | $ctime(datestamp) / converts most variations of a date stamp to unix/ctime |
||
| 247 | $datediff(ctime1, ctime2) / diffs two unix/ctime and fills the $datematch array with values |
||
| 248 | $datematch(num) / returns part of a $datediff, 0 = milliseconds, 1 = seconds, 2 = minutes, 3 = hours, 4 = days |
||
| 249 | $host(nick) / returns the hostmask of nick |
||
| 250 | $ident(nick) / returns the ident of nick |
||
| 251 | $(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name) |
||
| 252 | $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 |
||
| 253 | $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 |
||
| 254 | $round(num, decimals) / rounds down a float to X decimals |
||
| 255 | $regex(text, pattern) / does a regular expression test if text matches pattern, then returns the matched part |
||
| 256 | $regmatch(num) / returns the captured group at pos num from a $regex. 0 returns group count |
||
| 257 | $regreplace(text, pattern, text2) / replace any occurence in text of patterh with text2 where pattern is a regular expression |
||
| 258 | 3 | Per Amundsen | |
| 259 | 149 | Per Amundsen | $file(path) / reads file to end and returns the entire output without newlines |
| 260 | $fileloop(path) / reads through a file one line at the time, line increases +1 every time the same file is called |
||
| 261 | $floop(path) / reads through a file one line at the time, line increases +1 every time the same file is called |
||
| 262 | $filerandom(path) / returns a random line from a file |
||
| 263 | $frand(path) / returns a random line from a file |
||
| 264 | $fread(name) / reads a line from current pos in file named name |
||
| 265 | $fileread(name) / reads a line from current pos in file named name |
||
| 266 | $freadc(name) / reads a char/byte from current pos in file named name |
||
| 267 | $freadchar(name) / reads a char/byte from current pos in file named name |
||
| 268 | $fsize(file) / returns size off file in bytes |
||
| 269 | $filesize(file) / returns size off file in bytes |
||
| 270 | $fpos(name) / returns current position/byte in file named name |
||
| 271 | $filepos(name) / returns current position/byte in file named name |
||
| 272 | $flines(file) / returns amount of lines in file |
||
| 273 | $filelines(file) / returns amount of lines in file |
||
| 274 | $fileexists(file) / returns if file exists or not |
||
| 275 | $isfile(file) / returns if file exists or not |
||
| 276 | 1 | Per Amundsen | |
| 277 | 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 |
| 278 | $user(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num |
||
| 279 | $nick(#chan, num) / if num is 0 returns how many users are on this #chan else returns nick in position num |
||
| 280 | $server(num) / if num is 0 returns how many servers you are connected to else returns server id in position num |
||
| 281 | 1 | Per Amundsen | |
| 282 | 149 | Per Amundsen | $sread(name) / reads available bytes from socket named name (on sockread) |
| 283 | $sockread(name) / reads available bytes from socket named name (on sockread) |
||
| 284 | $sbytes(name) / returns amount of available bytes to be read from socket named name |
||
| 285 | $sockbytes(name) / returns amount of available bytes to be read from socket named name |
||
| 286 | 1 | Per Amundsen | </pre> |