Scripting » History » Version 237
  Per Amundsen, 02/02/2019 06:45 AM 
  
| 1 | 202 | Per Amundsen | {{>toc}} | 
|---|---|---|---|
| 2 | |||
| 3 | 189 | Per Amundsen | h1. Scripting | 
| 4 | 39 | Per Amundsen | |
| 5 | 220 | Per Amundsen | AdiIRC has a powerful scripting language which can be used to extend/change the clients behavior. | 
| 6 | 209 | Per Amundsen | |
| 7 | 210 | Per Amundsen | It's modeled after the popular mIRC scripting language, make sure you read the [[Scripting#mIRC-scripting-compatibility|compatibility section]]. | 
| 8 | 209 | Per Amundsen | |
| 9 | Choose a category to read more: | ||
| 10 | |||
| 11 | 223 | Per Amundsen | ** [[Scripting Events|Events]] | 
| 12 | ** [[Scripting Operators|Operators]] | ||
| 13 | ** [[Scripting Identifiers|Identifiers]] | ||
| 14 | ** [[Scripting Commands|Commands]] | ||
| 15 | ** [[Scripting Menus|Menus]] | ||
| 16 | ** [[Scripting DLL|DLL Support]] | ||
| 17 | ** [[Scripting Com|COM Support]] | ||
| 18 | ** [[Scripting Regex|Regular Expressions]] | ||
| 19 | ** [[Scripting Variables|Variables]] | ||
| 20 | ** [[Scripting Binary Variables|Binary Variables]] | ||
| 21 | ** [[Scripting Hash Tables|Hash Tables]] | ||
| 22 | ** [[Scripting Scripts|Scripts]] | ||
| 23 | ** [[Token_Manipulation|Token Manipulation]] | ||
| 24 | ** [[Scripting Ini Files|INI Files]] | ||
| 25 | ** [[Scripting Files Folders|Files/Folders]] | ||
| 26 | ** [[Scripting Custom Windows|Custom Windows]] | ||
| 27 | ** [[Scripting Picture Windows|Picture Windows]] | ||
| 28 | ** [[Scripting Dialogs|Dialogs]] | ||
| 29 | ** [[Scripting Sockets|Sockets]] | ||
| 30 | ** [[Scripting Sysinfo|System Information]] | ||
| 31 | 225 | Per Amundsen | ** [[Scripting Now Playing|Now Playing]] | 
| 32 | 221 | Mr. BS | |
| 33 | 206 | Per Amundsen | h2. Example scripts | 
| 34 | 154 | Per Amundsen | |
| 35 | Simple kickcounter script: | ||
| 36 | |||
| 37 | <pre> | ||
| 38 | 166 | Per Amundsen | alias kick {  | 
| 39 | if (!%kickcount) %kickcount = 0 | ||
| 40 | 154 | Per Amundsen | |
| 41 | 166 | Per Amundsen | inc %kickcount | 
| 42 | 154 | Per Amundsen | |
| 43 | 166 | Per Amundsen | 	if (!$3) {  | 
| 44 | kick # $$2 Kick number %kickcount | ||
| 45 | 154 | Per Amundsen | halt | 
| 46 | } | ||
| 47 | } | ||
| 48 | </pre> | ||
| 49 | |||
| 50 | Kickban example | ||
| 51 | <pre> | ||
| 52 | 166 | Per Amundsen | alias kb { | 
| 53 | 175 | Per Amundsen |   if (!$1) { | 
| 54 | echo /kb - Nick missing | ||
| 55 | return | ||
| 56 | } | ||
| 57 | 154 | Per Amundsen | |
| 58 | 175 | Per Amundsen | var %msg = $iif(#, $2-, $3-) | 
| 59 | var %chan = $iif(#, #, $2) | ||
| 60 | 154 | Per Amundsen | |
| 61 | 175 | Per Amundsen | ; Set this for default ban reason, or remove for no default reason | 
| 62 | ; Can be shortened to %msg = $iif(%msg, %msg, GTFO) | ||
| 63 | if (!%msg) %msg = GTFO | ||
| 64 | 154 | Per Amundsen | |
| 65 | 175 | Per Amundsen |   if ($me isop %chan) { | 
| 66 | 177 | Per Amundsen | MODE %chan +b $wildsite | 
| 67 | KICK %chan $1 %msg | ||
| 68 | 175 | Per Amundsen | } | 
| 69 | else echo You are not oper on %chan | ||
| 70 | 154 | Per Amundsen | } | 
| 71 | </pre> | ||
| 72 | |||
| 73 | Simple calculator script: | ||
| 74 | <pre> | ||
| 75 | 166 | Per Amundsen | alias calc { | 
| 76 | 175 | Per Amundsen |   if (!$1) { | 
| 77 | echo /calc - Parameters missing | ||
| 78 | return | ||
| 79 | } | ||
| 80 | 154 | Per Amundsen | |
| 81 | 175 | Per Amundsen | ; typing /calc -p <expression> sends output to channel | 
| 82 |   if ($1 == -p) { | ||
| 83 | 176 | Per Amundsen | msg # Calculating : $2- | 
| 84 | msg # Result is : $calc($2-) | ||
| 85 | 199 | Per Amundsen | } | 
| 86 |   else { | ||
| 87 | 176 | Per Amundsen | echo Calculating : $1- | 
| 88 | echo Result is : $calc($1-) | ||
| 89 | 175 | Per Amundsen | } | 
| 90 | 154 | Per Amundsen | } | 
| 91 | </pre> | ||
| 92 | |||
| 93 | Colored version | ||
| 94 | <pre> | ||
| 95 | 166 | Per Amundsen | alias calc { | 
| 96 | 175 | Per Amundsen |   if (!$1) { | 
| 97 | echo /calc - Parameters missing | ||
| 98 | return | ||
| 99 | } | ||
| 100 | 156 | Per Amundsen | |
| 101 | 175 | Per Amundsen | # typing /calc -p <expression> sends output to channel | 
| 102 |   if ($1 == -p) { | ||
| 103 | 1 | Per Amundsen | msg # $chr(3)4Calculating : $2- | 
| 104 | msg # $chr(3)4Result is : $calc($2-) | ||
| 105 | 199 | Per Amundsen | } | 
| 106 |   else { | ||
| 107 | 175 | Per Amundsen | echo $chr(3)4Calculating : 4$1- | 
| 108 | echo $chr(3)4Result is : $calc($1-) | ||
| 109 | } | ||
| 110 | 166 | Per Amundsen | } | 
| 111 | 154 | Per Amundsen | </pre> | 
| 112 | |||
| 113 | CTCP flood detection example | ||
| 114 | |||
| 115 | <pre> | ||
| 116 | 166 | Per Amundsen | CTCP *:*:*:{ | 
| 117 | 175 | Per Amundsen | if (!%count) set -u10 %count 1 | 
| 118 | else inc -u10 %count 1 | ||
| 119 | 154 | Per Amundsen | |
| 120 | 175 | Per Amundsen | if (%count > 4) ignore -tu30 $wildsite | 
| 121 | 154 | Per Amundsen | } | 
| 122 | </pre> | ||
| 123 | |||
| 124 | Mass mode example | ||
| 125 | |||
| 126 | <pre> | ||
| 127 | 166 | Per Amundsen | alias mass { | 
| 128 | 175 | Per Amundsen |   if (!$2) { | 
| 129 | echo /mass - Parameters missing [+/-<mode> <nick> <nick> <nick>] | ||
| 130 | return | ||
| 131 | } | ||
| 132 | 154 | Per Amundsen | |
| 133 | 175 | Per Amundsen | %len = 2 | 
| 134 | 154 | Per Amundsen | |
| 135 | 175 | Per Amundsen | ; equal to while (%len <= $count(%1-, $chr(32))) | 
| 136 |   while (%len <= $0) { | ||
| 137 | if ($(%len) ison #) mode # $1 $($ $+ %len) | ||
| 138 | inc %len | ||
| 139 | } | ||
| 140 | 154 | Per Amundsen | } | 
| 141 | </pre> | ||
| 142 | |||
| 143 | Shows info about servers, channels and users | ||
| 144 | <pre> | ||
| 145 | 166 | Per Amundsen | on *:JOIN:#: { | 
| 146 | 175 | Per Amundsen | var %s = $scon(0), %c = 0, %u = 0, %t = 0, %c2 = 0; | 
| 147 | 154 | Per Amundsen | |
| 148 | 175 | Per Amundsen |   while (%t < %s) { | 
| 149 | inc %t | ||
| 150 | scon $scon(%t); | ||
| 151 | inc %c $chan(0) | ||
| 152 | 154 | Per Amundsen | |
| 153 | 175 | Per Amundsen | %c2 = 0 | 
| 154 |     while (%c2 < $chan(0)) { | ||
| 155 | inc %c2 | ||
| 156 | 193 | Per Amundsen | inc %u $nick($chan(%c2), 0) | 
| 157 | 175 | Per Amundsen | } | 
| 158 | } | ||
| 159 | 154 | Per Amundsen | |
| 160 | 175 | Per Amundsen | /echo You are on ( $+ %s $+ ) servers, ( $+ %c $+ ) channels with ( $+ %u $+ ) users | 
| 161 | 154 | Per Amundsen | } | 
| 162 | </pre> | ||
| 163 | |||
| 164 | It is possible to use scripts as functions. | ||
| 165 | These functions are fully nested like the client functions. | ||
| 166 | |||
| 167 | Lets say you make a /mycalc like this. | ||
| 168 | <pre> | ||
| 169 | 166 | Per Amundsen | alias mycalc { | 
| 170 | 175 | Per Amundsen | return $calc($$1 + $$2); | 
| 171 | 154 | Per Amundsen | } | 
| 172 | </pre> | ||
| 173 | |||
| 174 | Then you can call this function with eiter /mycalc <number> <number> the normal way or $mycalc(<number, <number>) | ||
| 175 | Typing /testcalc will show the result. | ||
| 176 | <pre> | ||
| 177 | 166 | Per Amundsen | alias testcalc { | 
| 178 | 175 | Per Amundsen | echo -a $1 + $2 is $mycalc($1, $2); | 
| 179 | echo -a 5 + 4 is $mycalc(5, 4); | ||
| 180 | 154 | Per Amundsen | } | 
| 181 | </pre> | ||
| 182 | |||
| 183 | Simple convert temperature C to F or F to C | ||
| 184 | /temp C 20 will print 68 F | ||
| 185 | |||
| 186 | <pre> | ||
| 187 | 166 | Per Amundsen | alias temp { | 
| 188 | 175 | Per Amundsen | if ($1 == C) echo $calc(($2 * 9/5) + 32) F | 
| 189 | else if ($1 == F) echo $round($calc(($2 - 32) * 5/9), 1) C | ||
| 190 | else echo Temp missing | ||
| 191 | 154 | Per Amundsen | } | 
| 192 | </pre> | ||
| 193 | |||
| 194 | 166 | Per Amundsen | Announce song changes in a channel or to a user | 
| 195 | 154 | Per Amundsen | <pre> | 
| 196 | 166 | Per Amundsen | On *:SONG:{  | 
| 197 | 175 | Per Amundsen | nmsg <network> <channel/Nick> $1- | 
| 198 | 154 | Per Amundsen | } | 
| 199 | 158 | Per Amundsen | </pre> | 
| 200 | |||
| 201 | 166 | Per Amundsen | Announce to several channels with: | 
| 202 | 158 | Per Amundsen | <pre> | 
| 203 | 166 | Per Amundsen | On *:SONG:{  | 
| 204 | 175 | Per Amundsen | nmsg <network> <channel1/Nick>,<channel2/Nick> $1- | 
| 205 | nmsg <network2> <channel3/Nick> $1- | ||
| 206 | 158 | Per Amundsen | } | 
| 207 | 166 | Per Amundsen | </pre> | 
| 208 | 158 | Per Amundsen | |
| 209 | 166 | Per Amundsen | Automatically find the summary of a imdb url | 
| 210 | <pre> | ||
| 211 | On *:TEXT:*:#k: { | ||
| 212 | 175 | Per Amundsen | var %reg = $regex($1-, http://www\.imdb\.com(/title/[a-z0-9]+/)) | 
| 213 |   if (!%reg) { return } | ||
| 214 | sockclose imdb | ||
| 215 | unset %data | ||
| 216 | %imdb = $regml(1) $+ plotsummary | ||
| 217 | %imdbchan = # | ||
| 218 | sockopen imdb www.imdb.com 80 | ||
| 219 | 1 | Per Amundsen | } | 
| 220 | |||
| 221 | 166 | Per Amundsen | on *:sockopen:imdb: { | 
| 222 | 175 | Per Amundsen | sockwrite -n imdb GET %imdb HTTP/1.1 | 
| 223 | sockwrite -n imdb Host: www.imdb.com | ||
| 224 | sockwrite -n imdb User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.24 Safari/536.5 | ||
| 225 | sockwrite -n imdb Referer: http://www.imdb.com | ||
| 226 | sockwrite -n imdb Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1 | ||
| 227 | sockwrite -n imdb Accept-Language: en-us, en;q=0.50 | ||
| 228 | sockwrite -n imdb Connection: Close $+ $crlf $+ $crlf | ||
| 229 | 1 | Per Amundsen | } | 
| 230 | |||
| 231 | 166 | Per Amundsen | on *:sockread:imdb:{ | 
| 232 | 175 | Per Amundsen | sockread %text | 
| 233 | %data = %data $+ %text | ||
| 234 | 1 | Per Amundsen | } | 
| 235 | |||
| 236 | 166 | Per Amundsen | on *:sockclose:imdb: { | 
| 237 | 198 | Per Amundsen |   if ($regex(%data, <p class="plotSummary">([\s\S]*?)</p>)) { | 
| 238 | 175 | Per Amundsen | msg %imdbchan $regml(1) | 
| 239 | } | ||
| 240 | 1 | Per Amundsen | |
| 241 | 175 | Per Amundsen | unset %data | 
| 242 | 1 | Per Amundsen | } | 
| 243 | </pre> | ||
| 244 | 170 | Per Amundsen | |
| 245 | 206 | Per Amundsen | h2. mIRC scripting compatibility | 
| 246 | 1 | Per Amundsen | |
| 247 | 206 | Per Amundsen | Although mostly compatible, AdiIRC scripting is not fully compatible, there are missing features, various bugs and differences. | 
| 248 | 1 | Per Amundsen | |
| 249 | 208 | Per Amundsen | As such, asking for AdIRC scripting help should not be done in mIRC specific channels or forums, unless it's a script developed for mIRC and the question is related to mIRC only. | 
| 250 | 206 | Per Amundsen | |
| 251 | 208 | Per Amundsen | You can ask for AdiIRC scripting help on the forum#5 forum or in the #adiirc channel on chat.freenode.net. | 
| 252 | 206 | Per Amundsen | |
| 253 | h2. Submitting scripting bug reports | ||
| 254 | |||
| 255 | First verify the script works correctly in mIRC unless it uses AdIRC specific features, then narrow down the bug to the smallest possible lines of code before submitting. | ||
| 256 | |||
| 257 | 1 | Per Amundsen | Include as much information about the problem as possible, such as observed behavior and what the expected behavior should be. | 
| 258 | |||
| 259 | h2. More information | ||
| 260 | |||
| 261 | 217 | Per Amundsen | You can find many AdiIRC scripts in the forum#5 forum or mIRC scripts in places such as http://hawkee.com. | 
| 262 | 1 | Per Amundsen | |
| 263 | 235 | Per Amundsen | Not everyone will work, if you find one that doesn't, see above on how to report a bug. | 
| 264 | 1 | Per Amundsen | |
| 265 | 234 | Per Amundsen | For more on mIRC scripting and how it works, check out http://en.wikichip.org/wiki/Introduction_-_mIRC and https://web.archive.org/web/20170322040538/http://www.mirc.org/mishbox/index.htm | 
| 266 | 212 | Per Amundsen | |
| 267 | h2. Known issues | ||
| 268 | 1 | Per Amundsen | |
| 269 | 235 | Per Amundsen | Scripts checking for [[$version]] will probably not work since $version returns the AdiIRC version, not mIRC version. (Removing the version check will fix that) | 
| 270 | 226 | Per Amundsen | [] brackets doesn't work inside identifiers and [[/if]] expressions without surrounding the brackets with spaces. | 
| 271 | 233 | Per Amundsen | DLL's designed to inject them self into mIRC's memory/internals doesn't work (and never will). | 
| 272 | 1 | Per Amundsen | DLL's designed for mIRC are 32 bit and will never work in 64 bit AdiIRC. | 
| 273 | 237 | Per Amundsen | Some identifiers/commands/features are not implemented (some never will be), check the [[Scripting Identifiers|Identifiers]] and [[Scripting Commands|Commands]] pages. | 
| 274 | 231 | Per Amundsen | Small number of identifiers/commands parameters are not implemented, usually with features not available in AdiIRC yet (or ever), search for TODO in the search box. | 
| 275 | 232 | Per Amundsen | Some identifiers/commands may have slightly different behavior/results in various places, but usually nothing to worry about. |