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