Project

General

Profile

Scripting » History » Version 223

Per Amundsen, 02/26/2017 04:08 PM

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 221 Mr. BS
32 206 Per Amundsen
h2. Example scripts
33 154 Per Amundsen
34
Simple kickcounter script:
35
36
<pre>
37 166 Per Amundsen
alias kick { 
38
	if (!%kickcount) %kickcount = 0
39 154 Per Amundsen
40 166 Per Amundsen
	inc %kickcount
41 154 Per Amundsen
		 
42 166 Per Amundsen
	if (!$3) { 
43
		kick # $$2 Kick number %kickcount
44 154 Per Amundsen
		halt
45
	} 
46
}
47
</pre>
48
49
Kickban example
50
<pre>
51 166 Per Amundsen
alias kb {
52 175 Per Amundsen
  if (!$1) {
53
    echo /kb - Nick missing
54
    return
55
  }
56 154 Per Amundsen
57 175 Per Amundsen
  var %msg = $iif(#, $2-, $3-)
58
  var %chan = $iif(#, #, $2)
59 154 Per Amundsen
		
60 175 Per Amundsen
  ; Set this for default ban reason, or remove for no default reason
61
  ; Can be shortened to %msg = $iif(%msg, %msg, GTFO)
62
  if (!%msg) %msg = GTFO
63 154 Per Amundsen
64 175 Per Amundsen
  if ($me isop %chan) {
65 177 Per Amundsen
    MODE %chan +b $wildsite
66
    KICK %chan $1 %msg
67 175 Per Amundsen
  } 
68
  else echo You are not oper on %chan
69 154 Per Amundsen
}
70
</pre>
71
72
Simple calculator script:
73
<pre>
74 166 Per Amundsen
alias calc {
75 175 Per Amundsen
  if (!$1) {
76
    echo /calc - Parameters missing
77
    return
78
  }
79 154 Per Amundsen
		
80 175 Per Amundsen
  ; typing /calc -p <expression> sends output to channel
81
  if ($1 == -p) {
82 176 Per Amundsen
    msg # Calculating : $2-
83
    msg # Result is : $calc($2-)
84 199 Per Amundsen
  } 
85
  else {
86 176 Per Amundsen
    echo Calculating : $1-
87
    echo Result is : $calc($1-)
88 175 Per Amundsen
  }
89 154 Per Amundsen
}
90
</pre>
91
92
Colored version
93
<pre>
94 166 Per Amundsen
alias calc {
95 175 Per Amundsen
  if (!$1) {
96
    echo /calc - Parameters missing
97
    return
98
  }
99 156 Per Amundsen
	
100 175 Per Amundsen
  # typing /calc -p <expression> sends output to channel
101
  if ($1 == -p) {
102 1 Per Amundsen
    msg # $chr(3)4Calculating : $2-
103
    msg # $chr(3)4Result is : $calc($2-)
104 199 Per Amundsen
  } 
105
  else {
106 175 Per Amundsen
    echo $chr(3)4Calculating : 4$1-
107
    echo $chr(3)4Result is : $calc($1-)
108
  }
109 166 Per Amundsen
}
110 154 Per Amundsen
</pre>
111
112
CTCP flood detection example
113
114
<pre>
115 166 Per Amundsen
CTCP *:*:*:{
116 175 Per Amundsen
  if (!%count) set -u10 %count 1
117
  else inc -u10 %count 1
118 154 Per Amundsen
119 175 Per Amundsen
  if (%count > 4) ignore -tu30 $wildsite
120 154 Per Amundsen
}
121
</pre>
122
123
Mass mode example
124
125
<pre>
126 166 Per Amundsen
alias mass {
127 175 Per Amundsen
  if (!$2) {
128
    echo /mass - Parameters missing [+/-<mode> <nick> <nick> <nick>]
129
    return
130
  }
131 154 Per Amundsen
132 175 Per Amundsen
  %len = 2
133 154 Per Amundsen
	
134 175 Per Amundsen
  ; equal to while (%len <= $count(%1-, $chr(32)))
135
  while (%len <= $0) {
136
    if ($(%len) ison #) mode # $1 $($ $+ %len)
137
    inc %len
138
  }
139 154 Per Amundsen
}
140
</pre>
141
142
Shows info about servers, channels and users
143
<pre>
144 166 Per Amundsen
on *:JOIN:#: {
145 175 Per Amundsen
  var %s = $scon(0), %c = 0, %u = 0, %t = 0, %c2 = 0;
146 154 Per Amundsen
	
147 175 Per Amundsen
  while (%t < %s) {
148
    inc %t
149
    scon $scon(%t);
150
    inc %c $chan(0)
151 154 Per Amundsen
	
152 175 Per Amundsen
    %c2 = 0
153
    while (%c2 < $chan(0)) {
154
      inc %c2
155 193 Per Amundsen
      inc %u $nick($chan(%c2), 0)
156 175 Per Amundsen
    }
157
  }
158 154 Per Amundsen
159 175 Per Amundsen
  /echo You are on ( $+ %s $+ ) servers, ( $+ %c $+ ) channels with ( $+ %u $+ ) users
160 154 Per Amundsen
}
161
</pre>
162
163
It is possible to use scripts as functions.
164
These functions are fully nested like the client functions.
165
166
Lets say you make a /mycalc like this.
167
<pre>
168 166 Per Amundsen
alias mycalc {
169 175 Per Amundsen
  return $calc($$1 + $$2);
170 154 Per Amundsen
}
171
</pre>
172
173
Then you can call this function with eiter /mycalc <number> <number> the normal way or $mycalc(<number, <number>)
174
Typing /testcalc will show the result.
175
<pre>
176 166 Per Amundsen
alias testcalc {
177 175 Per Amundsen
  echo -a $1 + $2 is $mycalc($1, $2);
178
  echo -a 5 + 4 is $mycalc(5, 4);
179 154 Per Amundsen
}
180
</pre>
181
182
Simple convert temperature C to F or F to C
183
/temp C 20 will print 68 F
184
185
<pre>
186 166 Per Amundsen
alias temp {
187 175 Per Amundsen
  if ($1 == C) echo $calc(($2 * 9/5) + 32) F
188
  else if ($1 == F) echo $round($calc(($2 - 32) * 5/9), 1) C
189
  else echo Temp missing
190 154 Per Amundsen
}
191
</pre>
192
193 166 Per Amundsen
Announce song changes in a channel or to a user
194 154 Per Amundsen
<pre>
195 166 Per Amundsen
On *:SONG:{ 
196 175 Per Amundsen
  nmsg <network> <channel/Nick> $1-
197 154 Per Amundsen
}
198 158 Per Amundsen
</pre>
199
200 166 Per Amundsen
Announce to several channels with:
201 158 Per Amundsen
<pre>
202 166 Per Amundsen
On *:SONG:{ 
203 175 Per Amundsen
  nmsg <network> <channel1/Nick>,<channel2/Nick> $1-
204
  nmsg <network2> <channel3/Nick> $1- 
205 158 Per Amundsen
}
206 166 Per Amundsen
</pre>
207 158 Per Amundsen
208 166 Per Amundsen
Automatically find the summary of a imdb url
209
<pre>
210
On *:TEXT:*:#k: {
211 175 Per Amundsen
  var %reg = $regex($1-, http://www\.imdb\.com(/title/[a-z0-9]+/))
212
  if (!%reg) { return }
213
  sockclose imdb
214
  unset %data
215
  %imdb = $regml(1) $+ plotsummary
216
  %imdbchan = #
217
  sockopen imdb www.imdb.com 80
218 1 Per Amundsen
}
219
220 166 Per Amundsen
on *:sockopen:imdb: {
221 175 Per Amundsen
  sockwrite -n imdb GET %imdb HTTP/1.1
222
  sockwrite -n imdb Host: www.imdb.com
223
  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
224
  sockwrite -n imdb Referer: http://www.imdb.com
225
  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
226
  sockwrite -n imdb Accept-Language: en-us, en;q=0.50
227
  sockwrite -n imdb Connection: Close $+ $crlf $+ $crlf
228 1 Per Amundsen
}
229
230 166 Per Amundsen
on *:sockread:imdb:{
231 175 Per Amundsen
  sockread %text
232
  %data = %data $+ %text 
233 1 Per Amundsen
}
234
235 166 Per Amundsen
on *:sockclose:imdb: {
236 198 Per Amundsen
  if ($regex(%data, <p class="plotSummary">([\s\S]*?)</p>)) {
237 175 Per Amundsen
    msg %imdbchan $regml(1)
238
  }
239 1 Per Amundsen
240 175 Per Amundsen
  unset %data
241 1 Per Amundsen
}
242
</pre>
243 170 Per Amundsen
244 206 Per Amundsen
h2. mIRC scripting compatibility
245 1 Per Amundsen
246 206 Per Amundsen
Although mostly compatible, AdiIRC scripting is not fully compatible, there are missing features, various bugs and differences.
247 1 Per Amundsen
248 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.
249 206 Per Amundsen
250 208 Per Amundsen
You can ask for AdiIRC scripting help on the forum#5 forum or in the #adiirc channel on chat.freenode.net.
251 206 Per Amundsen
252
h2. Submitting scripting bug reports
253
254
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.
255
256 1 Per Amundsen
Include as much information about the problem as possible, such as observed behavior and what the expected behavior should be.
257
258
h2. More information
259
260 217 Per Amundsen
You can find many AdiIRC scripts in the forum#5 forum or mIRC scripts in places such as http://hawkee.com.
261 1 Per Amundsen
262
Not everyone will work, if you find one that dosen't, see above on how to report a bug.
263
264
For more on mIRC scripting and how it works, check out http://en.wikichip.org/wiki/Introduction_-_mIRC and http://www.mirc.org/mishbox/index.htm
265 212 Per Amundsen
266
h2. Known issues
267
268 216 Per Amundsen
Some [[$regex]]/[[$regsub]]/[[$regsubex]] regular expression features are missing since AdiIRC uses the [[Scripting_Regex|.NET regular expression engine]].
269 214 Per Amundsen
[[$calc]] parentheses are not always parsed correctly, adding spaces around them helps.
270 215 Per Amundsen
[] brackets doesn't work inside identifiers and [[/if]] expressions and sometimes adds extra spaces in the result, adding spacing around them helps fix the inside identifiers issue.
271 213 Per Amundsen
DLL's designed to inject them self into mIRC's memory doesn't work (And never will).
272 214 Per Amundsen
Various parsing issues/differences in [[$calc]].