Project

General

Profile

Scripting » History » Version 202

Per Amundsen, 02/11/2015 12:54 AM

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