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