Project

General

Profile

Scripting » History » Version 222

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