Scripting » History » Version 110
Per Amundsen, 03/21/2012 06:57 AM
1 | 42 | Per Amundsen | h1. Notice: this is info for 1.8.8 and higher. |
---|---|---|---|
2 | 39 | Per Amundsen | |
3 | 1 | Per Amundsen | h1. Scripting |
4 | |||
5 | In the latest beta's, I am experimenting with a little more advanced scripting features and I will use this wiki to track progress and features. |
||
6 | |||
7 | 8 | Per Amundsen | Syntax, variables and functions will probably change a lot, so don't except previous scripts to still work in the next beta and so forth. |
8 | 1 | Per Amundsen | |
9 | 30 | Per Amundsen | There are 2 types of scripting at the moment, one that have been here for a long time, and a new system. |
10 | 16 | Per Amundsen | |
11 | 38 | Per Amundsen | All scripting is done in Commands -> Edit Commands where one line represent a script or a custom command and its trigger is one of 3 ways: |
12 | |||
13 | /something<whitespace> |
||
14 | 37 | Per Amundsen | keys<whitespace> |
15 | OnEvent<whitespace> |
||
16 | 16 | Per Amundsen | |
17 | 1 | Per Amundsen | Please note that variables and functions are *different* for these 2 types of scripts. |
18 | 37 | Per Amundsen | |
19 | You can comment out a command by putting a # in front of it. |
||
20 | 17 | Per Amundsen | |
21 | 1 | Per Amundsen | h1. Normal custom commands: |
22 | 26 | Per Amundsen | |
23 | 25 | Per Amundsen | <pre>Syntax = /something<whitespace>/somethingelse</pre> |
24 | 16 | Per Amundsen | |
25 | 23 | Per Amundsen | Here are some variables which can be used in Custom Commands, its like creating aliases of already available commands, e.g <pre>/hi /me says hi to $chan</pre> will show <pre>* kr0n says hi to #adiirc</pre> when typing <pre>/hi</pre> |
26 | 16 | Per Amundsen | |
27 | 32 | Per Amundsen | Current variables are $1 to $9, $params, $chan and $me. $1 to $9 represents what you type after /yourcommand e.g <pre>/sup /say whats up $1</pre> when typing <pre>/sup kr0n</pre> it will show like this <pre>User: whats up kr0n</pre> |
28 | 16 | Per Amundsen | |
29 | 29 | Per Amundsen | $params represents everything written after /yourcommand, $chan replaces itself with current channel and $me replaces itself with your current usernick. |
30 | 16 | Per Amundsen | |
31 | 19 | Per Amundsen | You can make combo commands by using | as a seperator, e.g <pre>/hi /me says hi to $chan|/me says hi again to $chan</pre> |
32 | 16 | Per Amundsen | |
33 | 1 | Per Amundsen | $file[path] returns data from a file, $frand[path] fetchs a random line from a file and $floop[path] gets one line increasingly (line1, then line2, then line3 etc). |
34 | 23 | Per Amundsen | |
35 | 27 | Per Amundsen | h1. Custom Commands by hotkeys |
36 | 1 | Per Amundsen | |
37 | 25 | Per Amundsen | <pre>Syntax = key&key<whitespace>/something</pre> |
38 | 1 | Per Amundsen | |
39 | 27 | Per Amundsen | In addition to making a custom command trigger by typing a /slash command, you make it trigger with a hotkey instead (note, these commmands will not be useable from the new scripting engine) |
40 | |||
41 | 23 | Per Amundsen | Useable modifies are ctrl, alt and shift and any character or number or F key. |
42 | |||
43 | An example |
||
44 | |||
45 | 24 | Per Amundsen | <pre>ctrl&o /msg $chan ohai i just pressed ctrl and o</pre> |
46 | 23 | Per Amundsen | |
47 | 1 | Per Amundsen | Everytime you press ctrl and 'o' now, this command will be fired off. |
48 | 24 | Per Amundsen | |
49 | <pre>ctrl&alt&o /msg $chan ohai i just pressed ctrl and alt and o</pre> |
||
50 | |||
51 | 1 | Per Amundsen | Everytime you press ctrl and alt and 'o' now, this command will be fired off. |
52 | 16 | Per Amundsen | |
53 | 27 | Per Amundsen | h1. Unified Scripting |
54 | 1 | Per Amundsen | |
55 | 27 | Per Amundsen | <pre>Syntax = OnEvent<whitespace>code</pre> |
56 | |||
57 | 1 | Per Amundsen | The new scripting tries to combine normal client commands, your custom commands, functions and events into one scripting language. |
58 | |||
59 | 25 | Per Amundsen | In Commands -> Edit Commands you can enter a scripting line with the following syntax: |
60 | 1 | Per Amundsen | |
61 | Followed by either an expression like this (works recursivly) |
||
62 | |||
63 | <pre> |
||
64 | if (SOMETING == SOMETHINGELSE) { EXECUTE HERE } |
||
65 | if (SOMETING != SOMETHINGELSE) { EXECUTE HERE } |
||
66 | 13 | Per Amundsen | if (SOMETING ismatch SOMETHINGELSE) { EXECUTE HERE }</pre> |
67 | 1 | Per Amundsen | or by an executed command or function |
68 | |||
69 | 2 | Per Amundsen | You can now combine expressions with && (AND) and || (OR) like this |
70 | 1 | Per Amundsen | <pre> |
71 | 2 | Per Amundsen | if (SOMETHING == SOMETHING && SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE } |
72 | 13 | Per Amundsen | if (SOMETHING == SOMETHING || SOMETHINGELSE != SOMETHINGELSE) { EXECUTE HERE }</pre> |
73 | 1 | Per Amundsen | The logic behind these expressions is not fully tested, id love any feedback on this. |
74 | 33 | Per Amundsen | |
75 | It is also possible to use else if like this |
||
76 | <pre>if (SOMETHING == SOMETHING) { EXECUTE HERE } else if (SOMETHINGELSE == SOMETHINGELSE) { EXECUTE HERE }</pre> |
||
77 | In the future just "else" will be possible to. |
||
78 | 12 | Per Amundsen | |
79 | (note: ismatch will check if SOMETHING exist inside SOMETHINGELSE e.g if something is "hello" and something else is "hello world" it would return True because "hello" exist) |
||
80 | 2 | Per Amundsen | |
81 | 1 | Per Amundsen | Executed commands are /slash commands already in the client e.g /msg #channel hello world. |
82 | Executed functions are predefined functions in the client, only two exists for now. |
||
83 | |||
84 | An execution block can consist of both commands and functions if seperated by | (pipe) character like this <pre>/msg #channel hello world|.function bla bla|/msg #channel2 hello world</pre> |
||
85 | |||
86 | Furthermore there is a lot of predefined variables for use with these functions, for now they are: |
||
87 | |||
88 | $event / current event, e.g PRIVMSG 001 MODE and so forth |
||
89 | $channel / the channel the event occurred on, if any |
||
90 | $msg / the message to the channel/user or the message in a raw irc line e.g whois [kr0n] is a registered nick |
||
91 | $nick / the nick the event was sent from, can be a irc.server.com, a nick or null |
||
92 | $me / my current nick |
||
93 | $network / the network the event occured on e.g Quakenet |
||
94 | $ident / the from user ident if any |
||
95 | $host / the from user hostname if any |
||
96 | $myident / my ident |
||
97 | $myhost / my host |
||
98 | 14 | Per Amundsen | $server / host from the server e.g irc.server.com |
99 | 1 | Per Amundsen | |
100 | Currently predefined functions are: |
||
101 | <pre> |
||
102 | 36 | Per Amundsen | .insert <nick (use null for nonick)> |
103 | <where (a channel or $channel, a nick or $nick, or status)> |
||
104 | <MsgType (MsgServer/MsgUser/MsgEmote/MsgCTCP/MsgNotice/MsgClient/MsgLog)> |
||
105 | <$msg or message></pre> |
||
106 | 1 | Per Amundsen | |
107 | <pre> |
||
108 | 13 | Per Amundsen | .eat <what (text or all)></pre> |
109 | 1 | Per Amundsen | .insert is used for inserting a specific message type into a chat window, its intended for use in cases where you want to override how adiirc shows a given event, but can also be used for adding additional messages. |
110 | |||
111 | .eat is used to tell adiirc to either "eat" the text output from an event or "eat" everything and don't act on this event at all. |
||
112 | |||
113 | Putting it all togheter, here are a few examples: |
||
114 | |||
115 | <pre> |
||
116 | 13 | Per Amundsen | OnEvent if ($event == NOTICE) { if ($msg ismatch hi there) { .insert $nick status MsgNotice $msg|.eat text } }</pre> |
117 | 1 | Per Amundsen | |
118 | insert the notice into the server window and tells adiirc to "eat" its own text output from this notice |
||
119 | |||
120 | <pre> |
||
121 | 41 | Per Amundsen | OnEvent if ($event == PRIVMSG && $msg == herp) { /msg $channel derp }</pre> |
122 | 7 | Per Amundsen | |
123 | 1 | Per Amundsen | if the event is a PRIVMSG AND the $msg equals "herp", then show "derp" in the channel |
124 | |||
125 | 6 | Per Amundsen | <pre> |
126 | 13 | Per Amundsen | OnEvent if ($event == PRIVMSG) { if ($nick == Q || $nick == $me) { /msg $channel Q or $me is speaking! } }</pre> |
127 | 1 | Per Amundsen | |
128 | if the event is a PRIVMSG and the $nick equals "Q" OR $me then show "Q or $me is speaking" in the channel |
||
129 | 9 | Per Amundsen | |
130 | 34 | Per Amundsen | <pre>OnEvent if ($event == OnOp && $nick == $me) { /msg $channel Thx for op! }</pre> |
131 | |||
132 | 35 | Per Amundsen | if the event is OnOp and the target nick is me, then show "Thx for op!" in the channel |
133 | |||
134 | 3 | Per Amundsen | A list of custom events that is also usable as $event == |
135 | 4 | Per Amundsen | <pre> |
136 | 3 | Per Amundsen | OnOwner |
137 | OnDeOwner |
||
138 | OnSpecialOp |
||
139 | OnSpecialDeOp |
||
140 | OnOp |
||
141 | OnDeOp |
||
142 | OnHop |
||
143 | OnDeHop |
||
144 | 1 | Per Amundsen | OnVoice |
145 | 42 | Per Amundsen | OnDeVoice |
146 | 46 | Per Amundsen | </pre> |
147 | 1 | Per Amundsen | |
148 | 46 | Per Amundsen | h1. Scripting changes in latest beta |
149 | This does not apply to the latest stable release! |
||
150 | 1 | Per Amundsen | |
151 | 60 | Per Amundsen | *OnEvent* is now executed *AFTER* the event, use *OnBeforeEvent* for events where you want to .eat or in other ways manipulate the event. |
152 | |||
153 | 50 | Per Amundsen | New command /nmsg added for cross network output, and a new event OnSongChanged. |
154 | 1 | Per Amundsen | |
155 | 50 | Per Amundsen | Combine them and you can automatically announce song changes in a channel or to a user with: |
156 | |||
157 | 42 | Per Amundsen | <pre> |
158 | 45 | Per Amundsen | OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $msg } |
159 | 42 | Per Amundsen | </pre> |
160 | 62 | Per Amundsen | |
161 | 42 | Per Amundsen | Announce to several channels with: |
162 | 62 | Per Amundsen | |
163 | 42 | Per Amundsen | <pre> |
164 | 45 | Per Amundsen | OnEvent if ($event == OnSongChanged) { /nmsg <network> <channel/Nick> $msg|/nmsg <network> <channel/Nick> $msg } |
165 | 42 | Per Amundsen | </pre> |
166 | 1 | Per Amundsen | |
167 | 61 | Per Amundsen | Network is the network name where the channel is, e.g NordicIRC, freenode, Quakenet, look at the name of the server window you are connected on to find it. |
168 | 46 | Per Amundsen | |
169 | Also added is better escaping, variables and a "null" variable, e.g |
||
170 | |||
171 | <pre> |
||
172 | 47 | Per Amundsen | OnEvent if ($event == PRIVMSG) { if (%test == null) { %test = SOMETHING|/msg $channel test is %test } } |
173 | 46 | Per Amundsen | </pre> |
174 | |||
175 | 95 | Per Amundsen | New variable $now returns unixtime/ctime from current time. |
176 | 97 | Per Amundsen | New variable $active returns the current window Status/#channel/Nick. |
177 | 104 | Per Amundsen | New variable $! returns how many $0 $1 etc variables are filled (not sure if final name of it) |
178 | 95 | Per Amundsen | |
179 | 89 | Per Amundsen | These variables are saved into vars.ini unless removed (%var == null) and reloaded when adiirc starts. |
180 | You can change/use them in any script. |
||
181 | 48 | Per Amundsen | |
182 | 49 | Per Amundsen | Note also that all user set variables starts with % and client variables starts with $. |
183 | |||
184 | 91 | Per Amundsen | Some commands for manipulate variables: |
185 | |||
186 | <pre> |
||
187 | 93 | Per Amundsen | /set {-u seconds/-d] [%var] [value] / create or update a variable with value -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it |
188 | 92 | Per Amundsen | |
189 | 91 | Per Amundsen | /unset [var] / deletes a variable |
190 | 92 | Per Amundsen | |
191 | 93 | Per Amundsen | /inc {-u seconds/-d] [%var] [value] / increases a variable with value (only if value and var is ints) -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it |
192 | 92 | Per Amundsen | |
193 | 93 | Per Amundsen | /dec {-u seconds/-d] [%var] [value] / decreases a variable with value (only if value and var is ints) -u seconds, will delete the variable after X seconds, -d will decrease its value by 1 every second, then remove it |
194 | 92 | Per Amundsen | |
195 | /vars shows a list of all variables and their values |
||
196 | 91 | Per Amundsen | </pre> |
197 | |||
198 | 1 | Per Amundsen | Variables is still work in progress, id love some feedback/ideas of what it can be used for. |
199 | 50 | Per Amundsen | |
200 | 99 | Per Amundsen | halt can now be used instead of .eat all, it will halt immediately, ignoring rest of the script. |
201 | return will halt immediately, ignoring rest of the script, but not eat anything. |
||
202 | |||
203 | 51 | Per Amundsen | <pre> |
204 | 73 | Per Amundsen | OnLoad / Called when the script is loaded |
205 | OnUnload / Called when the script is unloaded |
||
206 | OnReload / Called when the script is reloaded |
||
207 | OnConnecting / Called when a server is connecting |
||
208 | OnLookingUp / Called when a server is looking up the hostname |
||
209 | OnConnected / Called when a server is connected |
||
210 | OnDisconnect / Called when a server gets disconnected |
||
211 | OnCommand / Called whenever a user types a /slash command in the client ($msg will hold the full command, $0 will be the first word, $1 the second and so on) |
||
212 | 99 | Per Amundsen | OnCTCPRequest / Called when a user recives a CTCP request |
213 | OnCTCPReply / Called when a user recives a CTCP reply |
||
214 | 100 | Per Amundsen | ACTION / Called when a user recives a ACTION (/me) message |
215 | 110 | Per Amundsen | OnNickChanged / Called when a user's nick changes, will only trigger on the user unlike NICK who triggers for everyone |
216 | 51 | Per Amundsen | </pre> |
217 | |||
218 | A few examples using these. |
||
219 | 1 | Per Amundsen | |
220 | <pre> |
||
221 | OnEvent if ($event == OnLoad) { %myvariable = This was set at startup } |
||
222 | OnEvent if ($event == OnUnLoad) { .msgbox varible set at startup was %myvariable } |
||
223 | OnEvent if ($event == OnReLoad) { .msgbox Script reloaded } |
||
224 | 99 | Per Amundsen | OnEvent if ($event == OnConnecting) { /echo i r conecting } |
225 | OnEvent if ($event == OnLookingUp ) { /echo i r looking up hostname } |
||
226 | OnEvent if ($event == OnConnected ) { /echo i r connected } |
||
227 | OnEvent if ($event == OnDisconnect) { /echo i r disconnected } |
||
228 | OnEvent if ($event == OnCommand) { if ($0 == /me) { /echo i typed /me } } |
||
229 | OnEvent if ($event == OnCommand) { /echo i typed $0, full command was $0- } |
||
230 | 100 | Per Amundsen | OnEvent if ($event == OnCTCPRequest) { /echo CTCP Request $0- from $nick } |
231 | OnEvent if ($event == OnCTCPReply) { /echo CTCP Reply $0- from $nick } |
||
232 | OnEvent if ($event == ACTION) { /echo ACTION $0- from $nick } |
||
233 | 110 | Per Amundsen | OnEvent if ($event == OnNickChanged) { /echo My nick is now $0 } |
234 | 52 | Per Amundsen | </pre> |
235 | 53 | Per Amundsen | |
236 | 99 | Per Amundsen | New Operators, all operators can now use ! to reverse the logic e.g !ison. If no operators are added it will test if remaining text is not null if (%test), if ($channel) etc. |
237 | 65 | Per Amundsen | |
238 | <pre> |
||
239 | 101 | Per Amundsen | > / Will try and cast left and right variable to int and try "int1 greater than int2" |
240 | < / Will try and cast left and right variable to int and try "int1 lower than int2" |
||
241 | >= / Will try and cast left and right variable to int and try "int1 greater than or equal to int2" |
||
242 | <= / Will try and cast left and right variable to int and try "int1 lower than or equal to int2" |
||
243 | isbetween / Will try and cast left variable to int and right variable have to be int-int, e.g "40 isbetween 30-50" |
||
244 | ison / check if ($nick ison $channel) nick is the channel |
||
245 | isop / check if ($nick isop $channel) is operator on the channel |
||
246 | ishop / check if ($nick ishop $channel) is half operator on the channel |
||
247 | issop / check if ($nick issop $channel) is special operator on the channel |
||
248 | isowner / check if ($nick isowner $channel) is channel owner |
||
249 | hasvoice / check if ($nick hasvoice $channel) have voice on the channel |
||
250 | inchan / check if i am in chan (#channel inchan) (#channel !inchan) |
||
251 | isnum / check something is a number (5 isnum) (5 !isnum) |
||
252 | 65 | Per Amundsen | </pre> |
253 | |||
254 | 53 | Per Amundsen | A complete rewrite of the parser logic is done, introducing the "else" keyword, and you can now use any nested length of "if" "else if" and "else" e.g: |
255 | |||
256 | <pre> |
||
257 | 54 | Per Amundsen | OnEvent if ($event == PRIVMSG) |
258 | { |
||
259 | 55 | Per Amundsen | if (%test == null) { |
260 | /msg Hello world; |
||
261 | if (%test == null) |
||
262 | { |
||
263 | 56 | Per Amundsen | /msg Hello world; |
264 | } |
||
265 | 1 | Per Amundsen | } |
266 | else if (%test == null) |
||
267 | { |
||
268 | 59 | Per Amundsen | /msg Hello world |
269 | 1 | Per Amundsen | } |
270 | 55 | Per Amundsen | else (%test == null) |
271 | 54 | Per Amundsen | { |
272 | 59 | Per Amundsen | /msg Hello world |
273 | 55 | Per Amundsen | } |
274 | if (%test == null) |
||
275 | { |
||
276 | /msg Hello world |
||
277 | 54 | Per Amundsen | } |
278 | } |
||
279 | 53 | Per Amundsen | </pre> |
280 | |||
281 | 1 | Per Amundsen | also ; is now useable like | for line ending. |
282 | 54 | Per Amundsen | |
283 | 57 | Per Amundsen | Simple kickcounter script: |
284 | <pre> |
||
285 | 64 | Per Amundsen | OnBeforeEvent if ($event == OnCommand) |
286 | 57 | Per Amundsen | { |
287 | if ($0 == /kick) |
||
288 | { |
||
289 | if (%kickcount == null) |
||
290 | { |
||
291 | 1 | Per Amundsen | %kickcount = 0; |
292 | 88 | Per Amundsen | } |
293 | |||
294 | %kickcount++; |
||
295 | 57 | Per Amundsen | |
296 | 1 | Per Amundsen | if ($2 == null) |
297 | 58 | Per Amundsen | { |
298 | /kick $channel $1 Kick number %kickcount; |
||
299 | 99 | Per Amundsen | halt; |
300 | 57 | Per Amundsen | } |
301 | } |
||
302 | } |
||
303 | </pre> |
||
304 | |||
305 | 68 | Per Amundsen | Added following variables for alias commands also: |
306 | |||
307 | <pre> |
||
308 | $network / the network the event occured on e.g Quakenet |
||
309 | $myident / my ident |
||
310 | $myhost / my host |
||
311 | $server / host from the server e.g irc.server.com |
||
312 | </pre> |
||
313 | 69 | Per Amundsen | |
314 | You can now use "-" on $<number> variables to get all words from $<number> and after. |
||
315 | |||
316 | <pre> |
||
317 | 85 | Per Amundsen | OnEvent if ($event == OnCommand) { /echo $2- } |
318 | 69 | Per Amundsen | </pre> |
319 | |||
320 | When you type "/msg $me this is a test" you will get only "this is a test" |
||
321 | |||
322 | <pre> |
||
323 | 85 | Per Amundsen | OnEvent if ($event == OnCommand) { /echo $3- } |
324 | 69 | Per Amundsen | </pre> |
325 | |||
326 | When you type "/msg $me this is a test" you will get only "is a test" |
||
327 | |||
328 | <pre> |
||
329 | 85 | Per Amundsen | OnEvent if ($event == OnCommand) { /echo $0- } |
330 | 1 | Per Amundsen | </pre> |
331 | |||
332 | When you type "/msg $me this is a test" you will get "/msg $me this is a test" |
||
333 | |||
334 | 100 | Per Amundsen | $0- is now equal to $params and $msg, and $0 will return the first part e.g the command "/msg" |
335 | 1 | Per Amundsen | |
336 | Also you can use $raw<number> like $raw0 $raw1 $raw0- to get parts of the raw irc message. This will likely be the default way when better parsing functions are added. |
||
337 | 73 | Per Amundsen | |
338 | 76 | Per Amundsen | Several functions are added, they are all recursive and you can use any %variable or $variable as parameters: |
339 | 79 | Per Amundsen | They are also usable inside if () statements. |
340 | 73 | Per Amundsen | <pre> |
341 | 74 | Per Amundsen | $replace(text, text2, text3) / replace all occurrences of text2 in text with text3 |
342 | $upper(text) / return text uppercase |
||
343 | $lower(text) return text lowercase |
||
344 | $mid(text, startpos, endpos) / return part of text from startpos to endpos |
||
345 | $substr(text, startpos, endpos) / return part of text from startpos to endpos |
||
346 | $left(text, pos) / return pos characters starting from left of the text |
||
347 | $right(text, pos) / return pos characters starting from right of the text |
||
348 | $remove(text, text2) / replace all occurrences of text2 from text |
||
349 | $len(text) / return length of text |
||
350 | $count(text, text2) / counts all occurrences of text2 in text |
||
351 | $pos(text, text2) / returns first occurrences position of text2 in text |
||
352 | $lastpos(text, text2) / returns last occurrences position of text2 in text |
||
353 | $strip(text) / removes all color and font tags |
||
354 | $repeat(text, times) / repeats text X times |
||
355 | $insert(text, text2, pos) / inserts text2 into pos of text |
||
356 | 77 | Per Amundsen | $calc(formula) / calculate any variation of +-*/ |
357 | $formatdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc |
||
358 | 96 | Per Amundsen | $fdate(date, text) / formats a unix timestamp into date using date variables %d %m %y etc |
359 | 78 | Per Amundsen | $char(num) / returns ascii character from the number num |
360 | 87 | Per Amundsen | $chr(num) / returns ascii character from the number num |
361 | 81 | Per Amundsen | $host(nick) / returns the hostmask of nick |
362 | $ident(nick) / returns the ident of nick |
||
363 | 104 | Per Amundsen | $(number) / dynamically gets a $0 $1 $2 variable e.g $(1) is same as $1 (not sure if final function name) |
364 | 73 | Per Amundsen | </pre> |
365 | 75 | Per Amundsen | |
366 | <pre> |
||
367 | OnEvent if ($event == JOIN) { /msg $channel $replace(this is a test, test, replaced test) } |
||
368 | </pre> |
||
369 | |||
370 | Shows "this is a replaced test" |
||
371 | |||
372 | <pre> |
||
373 | OnEvent if ($event == JOIN) { /msg $channel $replace($replace(this is a test, test, replaced test), replaced test, replaced again test) } |
||
374 | </pre> |
||
375 | |||
376 | 82 | Per Amundsen | Shows "this is a replaced again test" |
377 | 83 | Per Amundsen | |
378 | 1 | Per Amundsen | Here is an fullblown kickban example script using the script editor |
379 | <pre> |
||
380 | 82 | Per Amundsen | OnBeforeEvent if ($event == OnCommand) { |
381 | 106 | Per Amundsen | if ($0 != /kb) { |
382 | return; |
||
383 | } |
||
384 | |||
385 | if ($1 == null) { |
||
386 | /echo /kb - Nick missing; |
||
387 | } |
||
388 | else |
||
389 | { |
||
390 | # equal to if ($channel != null) |
||
391 | if ($channel) |
||
392 | 82 | Per Amundsen | { |
393 | 106 | Per Amundsen | %msg = $2-; |
394 | %chan = $channel; |
||
395 | } |
||
396 | else |
||
397 | { |
||
398 | %msg = $3-; |
||
399 | %chan = $2; |
||
400 | } |
||
401 | |||
402 | # Set this for default ban reason, or remove for no default reason |
||
403 | if (%msg == null) { |
||
404 | %msg = GTFO; |
||
405 | } |
||
406 | 1 | Per Amundsen | |
407 | 106 | Per Amundsen | if ($me isop %chan) { |
408 | /raw MODE %chan +b *!$ident($1)@$host($1); |
||
409 | /raw KICK %chan $1 %msg; |
||
410 | } else { |
||
411 | /echo You are not oper on %chan; |
||
412 | 1 | Per Amundsen | } |
413 | |||
414 | 106 | Per Amundsen | %msg = null; |
415 | %chan = null; |
||
416 | 1 | Per Amundsen | } |
417 | 106 | Per Amundsen | |
418 | halt; |
||
419 | 86 | Per Amundsen | } |
420 | </pre> |
||
421 | |||
422 | 1 | Per Amundsen | Simple calculator script: |
423 | <pre> |
||
424 | OnBeforeEvent if ($event == OnCommand) { |
||
425 | 106 | Per Amundsen | if ($0 != /calc) { |
426 | return; |
||
427 | } |
||
428 | 99 | Per Amundsen | |
429 | 106 | Per Amundsen | if ($1 == null) { |
430 | /echo /calc - Parameters missing; |
||
431 | 99 | Per Amundsen | halt; |
432 | } |
||
433 | 106 | Per Amundsen | |
434 | # typing /calc -p <expression> sends output to channel |
||
435 | if ($1 == -p) { |
||
436 | /msg $channel Calculating : $2-; |
||
437 | /msg $channel Result is : $calc($2-); |
||
438 | } else { |
||
439 | /echo Calculating : $1-; |
||
440 | /echo Result is : $calc($1-); |
||
441 | } |
||
442 | |||
443 | halt; |
||
444 | 87 | Per Amundsen | } |
445 | </pre> |
||
446 | |||
447 | Colored version |
||
448 | 102 | Per Amundsen | <pre> |
449 | 87 | Per Amundsen | OnBeforeEvent if ($event == OnCommand) { |
450 | 106 | Per Amundsen | if ($0 != /calc) { |
451 | return; |
||
452 | } |
||
453 | |||
454 | if ($1 == null) { |
||
455 | /echo /calc - Parameters missing; |
||
456 | 99 | Per Amundsen | halt; |
457 | } |
||
458 | 106 | Per Amundsen | |
459 | # typing /calc -p <expression> sends output to channel |
||
460 | if ($1 == -p) { |
||
461 | /msg $channel $chr(3)4Calculating : $2-; |
||
462 | /msg $channel $chr(3)4Result is : $calc($2-); |
||
463 | } else { |
||
464 | /echo $chr(3)4Calculating : 4$1-; |
||
465 | /echo $chr(3)4Result is : $calc($1-); |
||
466 | } |
||
467 | |||
468 | halt; |
||
469 | 98 | Per Amundsen | } |
470 | </pre> |
||
471 | |||
472 | CTCP flood detection example |
||
473 | |||
474 | <pre> |
||
475 | OnEvent if ($event == OnCTCPRequest) { |
||
476 | 106 | Per Amundsen | if (%count == null) { |
477 | /set -u 10 %count 1; |
||
478 | } else { |
||
479 | /inc -u 10 %count 1; |
||
480 | } |
||
481 | 104 | Per Amundsen | |
482 | 106 | Per Amundsen | if (%count > 4) { |
483 | /ignore -u 30 -t $nick!$ident@$host; |
||
484 | } |
||
485 | 103 | Per Amundsen | } |
486 | </pre> |
||
487 | |||
488 | while (CONDITION) { EXECUTE } is now useable for a loop |
||
489 | |||
490 | Mass mode example |
||
491 | |||
492 | 105 | Per Amundsen | <pre> |
493 | 103 | Per Amundsen | OnBeforeEvent if ($event == OnCommand) { |
494 | if ($0 != /mass) { |
||
495 | return; |
||
496 | } |
||
497 | |||
498 | if ($2 == null) { |
||
499 | /echo /mass - Parameters missing [+/-<mode> <nick> <nick> <nick>]; |
||
500 | halt; |
||
501 | } |
||
502 | |||
503 | %len = 2; |
||
504 | 107 | Per Amundsen | |
505 | 109 | Per Amundsen | # equal to while (%len <= $count($0-, $chr(32))) |
506 | 103 | Per Amundsen | while (%len <= $!) { |
507 | if ($(%len) ison $channel) { |
||
508 | /mode $channel $1 $(%len); |
||
509 | } |
||
510 | 1 | Per Amundsen | |
511 | /inc %len; |
||
512 | } |
||
513 | |||
514 | halt; |
||
515 | } |
||
516 | </pre> |