Project

General

Profile

Scripting » History » Version 190

Per Amundsen, 03/13/2014 03:42 AM

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