Project

General

Profile

Scripting » History » Version 208

Per Amundsen, 08/28/2016 02:41 AM

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