Project

General

Profile

Scripting » History » Version 215

Per Amundsen, 08/28/2016 03:10 AM

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