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