Project

General

Profile

Scripting » History » Version 182

Per Amundsen, 02/07/2014 10:42 AM

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