Documente Academic
Documente Profesional
Documente Cultură
T his is the bas ic...you j us t HAVE to know this , or you won't be able to
do much on I RC at all, beyond j oining a channel and talking : ). For
s cr ipting, knowing thes e commands well means being able to pull the
mos t out of your client, you can't do ANYthing in a s cr ipt without this .
I R C com m an ds
T hes e ar e gener al, s pecific for the I RC medium, and ar e mainly
focus ed on the inter action between you and the s er ver and other
us er s . T hes e commands ar e detailed in the mI RC help file, and I 'll
leave mos t of them alone for your s tudying, however ther e ar e a few
commands that ar e not mentioned in the helpfile (and that ar e not
common on all networ ks ), and I 'll mention them br iefly:
- S ilence:
T his is wor king bas ically j us t like /ignor e, but has a few
impor tant differ ences . Fir s t of all, while /ignor e is a clients ide pr otection, meaning that you will s till r eceive the
incoming r eques ts , your client will not pr oces s them,
/s ilence is a s er ver - s ide pr otection, meaning if an us er
matching your s ilence lis t tr ies to s end you a r eques t, it
will never be s ent to you. S econd, a /s ilence wor ks only on
CT CP's , nothing els e. T hir d, a /s ilence lis t is clear ed on
dis connect (s imilar to /watch) meaning you'll have to r es et it on each connect, if you have a lis t of 'per manent'
s ilences . U s age: /s ilence nick/hos t to add a nick/hos t to
your s ilence lis t, or /s ilence - nick/hos t to r emove, or j us t
/s ilence to view the cur r ent s ilence lis t.
- Watch:
T his is a mor e 'efficient' ver s ion of the notify s ys tem,
cur r ently only available on DALnet. T he watchlis t is clear ed
on dis connect fr om a s er ver , meaning that your
client/s cr ipt mus t r emember the lis t, and r es et it on
r econnect to DALnet (mI RC does this by defalt fr om v5.5).
T he watch lis t is limited to 128 entr ies (nicknames to
watch for ). U s age: /watch < + nick1> [+ nick2....+ nickN] to
add s ingle nicks to the watchlis t, /watch < # channelname>
to watch an entir e channel, /watch < - nick> [- nick2....-
- u300 % key $chan(# ).key, which would uns et the % key var iable after
5 minutes .
Popups 1
I n this ex ample, the title/menu is 'Connect til nettver k', and r ather
than tr igger ing a pr ogr am/command to r un, it is br anching to s o- called
s u b-m en u 's , and us ually, popups will have s ub- menu's , to cr eate a
mor e logical and eas y- to- us e inter face to the us er . T o cr eate the menu
above (which is located in the s tatus window);
menu s tatus {
Connect til nettver k
.Under net
..s er ver 1: { .s er ver s omes er ver .or g }
..s er ver 2: { s er ver s omes er ver 2.or g }
.DALnet
..s er ver 1: { .s er ver yet.another .s er ver .or g }
etc
}
As you s ee, you cr eate the br anching by adding one dot '. ' to each
s ub- level you want to cr eate, other wis e the way you add the
commands to be r un is ex actly the s ame as for alias es . T o cr eate the
divider (line), for ins tance between 'Andr e' and 'Om I RC nett', you add
a hyphen '- ' to the menu level...that is , on the 'upmos t (r oot)' level of
the popups , you do like this ;
Choice # 1: { s ome commands }
Choice # 2: { Mor e commands }
I f you want to cr eate the divider as above, it's like this ;
menu s tatus {
Connect til nettver k
. ( .... )
.Andr e
.. ( ... )
..Om I RC nett: { command to r un }
}
B r acket s :
Pay attention that when you 'open' a menu (s tar t a menu s ection of a
s cr ipt) (or a command) with a { br acket, that you als o clos e it, us ing a
} br acket. I f you don't, you will get all mes s ed up popups , like..
Popups 2
s o, if you s ee alot of gar ble in your popups when you tes t your new,
to- be- wor ld- famous s cr ipt, then you s hould mos t likely s can your
popups for a } that is n't ther e..; ).
U s in g iden t if ier s an d var iables w it h in you r popu ps :
You can als o us e identifier s and var iables ins ide the popups , to make
them eas ier to us e or pr ovide infor mation about what will happen
when you activate the menu, s uch as
Popups 3
Popups 4
On the fir s t pictur e, I 'm the lucky oper ator of a channel, and has
acces s to a few commands that ar e us able only if you ar e a channel op
(invite, s et ban). On the s econd pictur e, I have been deop'ed, and the
popup acces s to the menu's that r equir e op have been r emoved, to
avoid pr oblems , and pr ovide a cleaner look to the popups .
Mor e s pecifically, you cr eate dynamic popups by us ing
identifier s /cr eating conditionals that will be either on or off, $tr ue or
$fals e etc etc. T his adds the 's how/hide' featur e of popups , and may
s implify the ever yday us e of the s cr ipt you'r e making : ). An eas y way
to do the above popups would be like;
.......
$iif($me is op # ,Opkontr oller )
.I nviter til $chan{ invite $$?= " Who s hould we invite to
$chan $+ ?" $chan }
.S ett ban { ...... }
.S ett ban alle kan { ..... }
S end til $chan
......
T he above popup definition is us ing the identifier $iif which will r etur n
one out of two things , depending on the ex pr es s ion you make. I n this
cas e, the $iif checks to s ee if you'r e an op on the cur r ent channel, in
which cas e it r etur ns 'Opkontr oller '. T he s ubmenu's belonging to
'Opkontr oller ' will then be enabled. I f you'r e not an op, it r etur ns
nothing (which is als o a s tate), and hides the s ubmenu's fr om the
us er . You can us e mos t (all?) of the evaluator s available in r egular if
compar is ions , which enable you to do cons tr uctions s uch as
$iif($me is op # && $1 !is op # ,Kick): { .kick $chan $1
kickms g }
Remote 1
if it does n't, you can tur n them on by typing/ctcps on, /events on and
/r aw on.
will kick the per s on with the mes s age 'Pleas e watch your language
her e in # channelname', and then it will add the us er tou s er level 2.
Nex t time you kick this per s on, you will als o ban the us er fr om the
channel, with the ban m as k * !* us er @ * .domain. For mor e info on the
us e of r egular events , check the helpfile : )
CT CP E ven t s :
CT CP s tands for Client T o Client P r otocol, and CT CP events ar e events
being tr igger ed by the us e of this pr otocol. Whenever you r eceive a
CT CP r eques t, your client will ans wer to this if ther e is a s et ans wer
defined for the r eques ted CT CP type, els e it will not r es pond. T he
for mat of a typical CT CP event is s imilar to the 2nd type of r egular
event mentioned ear lier , like;
ctcp level: match: wher e/how: command(s )
T he differ ence her e is that the event par t of the definition, is actually
the match. You can s pecify a s pecific wor d the event s hould tr igger on,
or a wildcar d match..for ex ample:
ctcp 1: PI NG: * : {
ctcpr eply $nick PI NG Z z z z z z z z z z z z z z z z huh? = o I s
$r and(1,3000000) s econds ok?
}
T his ctcp is r eacting on a PI NG r eques t, and on ly a PI NG r eques t. I n
other wor ds , s end it a PI NGS r eques t and it has n't got a clue what
you'r e talking about, and will j us t ignor e you ; ). T he '
* ' indicates that
it will tr igger both on ctcp's s ent to the channel (# ), and to you
pr ivately ( ? ). I t is a level 1 ctcp, which means that on mos t default
configur ations , this r eques t will be ans wer ed fr om all s ites (unles s you
have them ignor ed, of cour s e. T he ct cpr eply is a s pecial command
that s ends your r eply back in CT CP for mat, you can als o us e ms g,
notice, or nothing at all, j us t echoing to you that s omebody ping'ed
you, etc. T his event s ends a ctcpr eply to the nick pinging you, with a
s illy mes s age as king wether x x x s econds is ok. Her e x x x will be a
number between 1 and 3000000, r andomly picked by us ing the $r and
identifier .
ctcp 3: * T I ME* : ?: {
notice $nick T I ME $as ctime($ctime) $+ . And you?
ctcp $nick T I ME
}
T his one is r eacting on CT CP's that contain the wor dT'I ME' in them,
s o, it will ans wer both a r eques t for CT I ME, T I MES , etc. Refer ing to
above, the '?' means that only ctcp's s ent dir ectly to you will be
ans wer ed, while r eques ts s ent to an entir e channel will be ignor ed.
T his is a level 3 ctcp, which means that it will only be ans wer ed when
coming fr om an us er in your us er lis t with a level that is 3 or above,
Remote 2
and the par ameter s fr om 1- 8 will be number ed, while par ameter 9 and
out (if ex is tant) will be j us t echo'ed in one bulk. While r egular events
and ctcp events tr igger by other people's actions , r aw events ar e
r es pons es the s er ver s ends back to you, tr igger ed by your own or your
I RC clients actions (in the above ex ample I was tr ying to take the nick
'I O'. ; ))
I den t if ier s # 1
Knowing identfier s is go/no go when wor king with r emotes , and you
will only be able to do ver y s imple s tuff in alias es /popups , if you don't
know how to us e identifier s . However , mos t idenfier s ar e fair ly s tr aight
for war d lear ning fr om the helpfile, and fr om mI RC 5.50, they ar e als o
clas s ified in s ubs ections , making it eas ier to locate the identifier you
need. T o get help on any identifier , us e /help $identifier name, for
ins tance /help $me. T o s how the valu e of an identifier , type (in any
window) //echo - a $identifier name. Let's move on..
T his s ection is s plit in four ;
Wor king with identifier s
B as ic identifier s
Mor e identifier s
I ntr oduction to T oken identifier s
W or kin g w it h iden t if ier s
T his is ways of combining identifier s , s mall tweaks and things you can
do
B as ic iden t if ier s
I den t if ier s # 2
Mor e u s ef u l iden t if ier s ..
T hes e ar e identifier s you will need to know in mos t any s cr ipting,
and/or gain you when wr iting alias es /popups as well.
$ m ir cdir : Retur ns the path fr om which your mI RC is
cur r ently r unning, ie
c: \pr ogr am files \mir c\ or the like. I f you need to indicate
s ubfolder s or files
within this path (for ins tance mir c.ini or download) us e it
like $mir cdir s ubpath
or $mir cdir filename, like $mir cdir mir c.ini, or
$mir cdir download. You will
typically us e this one to r efer to the mir cdir its elf, or
s ubfolder s of it.
$ s cr ipt dir : Retur ns the path to the cur r ent s cr ipt, ie
c: \pr ogr am files \mir c\addons etc. I t's par ticular ly handy if
your s cr ipt is
us ing mor e than one file for it's code, and you want to
r efer to the other files ,
or if you j us t want to make s ur e any s tor ed data will be
s tor ed with your s cr ipt,
and not in any other folder r andomly chos en by mI RC /
your o/s . Us age s imilar to
$mir cdir , ie $s cr iptdir alias es .mr c, to r efer to the file
'alias es .mr c' in the
s cr ipt's folder .
$ dir : T his identifier opens a r egular 'br ows ing' dialogue,
and allows the us er
to click his way to the folder he wants , and then s elect the
file he wants .
No typing of full path or the like, j us t click : ).
U s age: $dir [= " s om et ex t " ] [initpath][f ilen am e/ m as k].
For ins tance, us ed in popups :
Load an addon: { load - r s $$dir = " S elect f il e
t o load" $mir cdir Addons \* .m r c }
which then will open a 's elect file' dialogue in the 'Addons '
s ubfolder of
mI RC's main folder , us ing the filemas k* .mr c, which j us t
means it'll s how only
.mr c files by default. You can omit ever ything ex cept the
identifier its elf,
if you wis h, though s ome ex plaining tex t of what's
ex pected by the us er is
us ually a good thing : ).
$ f in df i le: T his is actually j us t a quite nice file locator ,
equal to the 'find'
option fr om your r egular windows ex plor er : ) You s pecify
the par ameter s , and
the identifier r etur ns the findings : ).
U s age:
$findfile(< dir ect or y> ,< m at ch > ,< occur r ence> ,[depth],[
@ window],[command])
Dir ector y is the 'r oot' of the s ear ch (the topmos t folder
that is being
s ear ched), match is the patter n you'r e s ear ching for , and
occur r ence is
which occur r ence that s how up (yes , only one will s how up,
meaning, if you
want mor e than one occur r ence to s how up, you will have
to loop the s ear ch).
Depth is the number of 'levels ' of s ubdir ector ies that will be
s canned,
@ window is wher e the output may be pr es ented, and
command is a command that
will be per for med on all found files . Depth, @ window and
command ar e optional
par ameter s , while the 3 fir s t ar e mandator y. T he identifier
$finddir is ex act
s imilar , but finds a folder /dir ector y.
$ r eadin i: I f your s cr ipt needs to s tor e data, var iables ar e
all well and good for
tempor ar y s tor age, but for mor e long- ter m bas ed s tor age,
an .ini file is us ually
pr efer r able. You s tor e the data us ing the / w r it ein i
command, and r etr ieve the
data us ing the $r eadini identifier .
U s age: $r eadini [- n] [path\]< filename> < s ection>
< item> , for ins tance
I dentify to nicks er v: { nicks er v identify
$r eadini pw.ini nicks $me }
which will then identify to nicks er v with the given
pas s wor d, pr ovided of cour s e
that you fir s t had cr eated a file containing thes e pas s wor ds
: ). T he -n s witch
is optional, when s pecified the r etur ned info won't be
evaluated, but tr eated as
plain tex t (For ins tance if the above r etur ned % tes t, it
wouldn't tr y to s how
the value of % tes t, but j us t r etur n % tes t). P at h is optional
as well.
$ ial: T he ial is mI RC'sI n t er n al Addr es s L is t , allowing
mI RC to wor k much fas ter
and convenient with us er 's addr es s es , than it would do
with having to look up each
addr es s each time you would need it (for ins tance with
bans , s cans etc). I t als o
allows you to r etr ieve infor mation that you els e would have
to us e r aw events for .
which then will notice the per s on you get the pingr eply
fr om, telling him/her
his pingtime in s econds . T he above ex ample is j us t a
s imple s ubs tr action, you
can us e much mor e advanced calculations if des ir ed, of
cour s e.
$ act ive: $active r etur ns the name of the cur r ently active
window in mI RC...thus ,
it als o r etur ns the name of chat/quer y windows , and the
s tatus window. T his is
us eful if you want to make anything that s hould r es pond
on the cur r ently open
window, r ather than a channel or the like.
$ w in dow : T his is an identifier s pecific to cus tom windows ,
and while it's got a
number of .pr oper ties , I will only mention it br iefly..in an
if- then- els e match
you can s pecify if ($window(@ windowname)) { commands
} to ver ify that the window
actually is opened etc. T his s hould help you avoid tons of
/aline: no s uch window er r or 's ..: )
$ even t : T his one r etur ns the name of the event that was
tr igger ed (thus , only
ver y us able when placed in a r emote event = P).
$ n u m er ic: S imilar to $event, r etur ns the number of the
tr igger ed in the numer ic
event, thus only us able when placed in a r aw event.
$ u l is t : Yet another r emote identifier , this one r etur ns the
addr es s in the
us er lis t matching the s pecified addr es s and level.
U s age: $ulis t($mas k,Level,# ).
For ins tance, if you want to lis t us er s in your us er lis t fr om
a par ticular
addr es s , on a level of your choice;
S how us er s {
s et - u0 % patter n $$?= " Enter patter n to s ear ch for ,
ie * !* @ * .com"
s et - u0 % level $$?= " Enter level to s how"
s et - u0 % max $ulis t(% patter n,% level,0)
: loop
inc % cnt 1
if (% cnt < = % max ) {
echo - a $chr (35) $+ % cnt is
$ulis t(% patter n,% level,% cnt)
goto loop
}
}
T his could be a s imple popup, which would lis t the us er s of
a s pecific
us er level, after the r eques ter s cr iter ia. Note that in this
one ther e is no
er r or checking, it j us t s hows how you could us e $ulis t, a
better ex ample might
be
on 1: KI CK: # : {
if ($addr es s ($knick,3) is wm
$ulis t($fulladdr es s ,pr otect,1)) {
lis t
halt }
E x am ple # 1
Let's wor k with an ex ample: You want to make a wor dkicker that kicks
on bad wor ds , s ay pu* * y, the only pr oblem with this is that if you do
this line (the r egular way);
ON @ * : T EXT : * : # : { if (badwor d is in $1- ) { kick $chan $nick
Wor dkick } }
it'll kick if ther e is an us er us ing a wor d that contains the badwor d, in
the above ex ample, pus s ycat for ins tance. S o how do we pr event this ?
We can us e the token identifier called $is tok ( -$ is t ok( T E XT ,T OK E N ,C) --) : $is tok r etur ns $tr ue if a token ex is ts in
tex t, and $fals e if it does n't. I n this cas e, theT OKEN is badw or d, and
T EXT is the complete s entence, but what is C? T he " char acter "
s epar ating the wor ds in a s entence, is a s pace. Yes , ther e is an as cii
value for a s pace, 32. S o what we tr y is this line..:
ON @ * : T EXT : * : # : { if ($is tok($1- ,badwor d,32) = = $tr ue) { kick
etc.. } }
T his line will ONLY kick if badwor d is an ex act wor d in the s entence, it
will not kick if badwor d is a par t of another wor d in the s entence.
E x am ple # 2
Let's take another ex ample while we'r e at this . We wants to count the
number of wor ds in a s entence, s o we finds the identifier $numtok ( -$ n u m t ok( T E XT ,C) --) and finds out that this is what we want (note:
you can als o us e $ get t ok( T E XT ,0 ,C) for this ):
ON * : T EXT : * : # : { echo $chan $nick us ed $numtok($1- ,32)
wor ds in his s entence }
T otally pointles s , but it illus tr ates the us e of $numtok.
E x am ple # 3
One las t ex ample.. We want to make a s cr ipt that automatically r uns a
tr acer oute with an ex ter nal pr ogr am on an us er 's hos t. Ok, we could
j us t do a dns and captur e the r es olved addr es s , but for this tutor ials
pur pos e we'll do it with tokens . T he identifier we'r e looking for is
$gettok ( -- $ get t ok( T E XT ,N ,C) --) , which r etur ns the N'th token in
the tex t enter ed. Let's look at a typical addr es s mas k, as we s ee them
on I RC.
B onz i!bleh@ mp- 217- 245- 170.dax net.no
I n this addr es s , B onz i is the nick, bleh is the us er 's identd, and the r es t
is the us er 's hos t, in other wor ds what we want to pas s on to the
ex ter nal pr ogr am. How do we r etr ieve it? T EXT will her e be the entir e
addr es s , for N and C let's look at the addr es s again. We s ee that the
hos t has the @ befor e it, s o the @ is the s epar ating char acter (C).
Now, if N was 1, we'd get the par t of the addr es s _ befor e_ the @ , but
we want the hos t, s o N mus t be 2. T he as cii value of @ is 64 ( -/ / ech o -a $ as c( @ ) --) , s o the line we end up with is s omething like
this ..:
//r un ex ter nalpr ogr am $gettok(B onz i!bleh@ mp- 217- 245170.dax net.no,2,64)
T his will ex ecute this command: /r un ex ter nalpr ogr am mp- 217- 245170.dax net.no.
B y now you hopefully have a better idea on what tokens ar e, and a
bas ic idea on how to us e them, check / h elp t oken iden t if ier s for a
lis t of all token identifier s , as well as s ome tips on how to us e.
A var iable is a t em por ar y s t or age s pace, an " item" that can s tor e a
number , a s tr ing, a char acter , or mos t anything you s et it to. Var iables
has to be as s ign ed a value to actually r etur n any value, an
unas s igned var iable will not have any value, thus it will not ex is t
(ther e's a few ex ceptions to this , which we'll come back to later on).
B eing tempor ar y s tor age holder s , var iables ar e us eful for s tor ing data
us ed in commands and functions s uch as loops , dialogs (tempor ar y
s tor ing input until the " Ok" button actually is pr es s ed), awayr eas ons ,
tempor ar y data in a calculation, etc. Many people us e var iables to
s tor e s ettings for files , which is a les s good idea, both due to the nonper manent natur e of var iables , and s ince many s cr ipts uns et var iables ,
and may unintendedly uns et var iables us ed for s tor ing s ettings .
S et t in g an d u n s et t in g var iables
T o as s ign a value to a var iable, we us e the /s et command. /s et % temp
tes ting will s tor e the s tr ing tes ting in the var iable % temp, which then
may be us ed for anything you pleas e...type //echo - a % temp to s ee
what's s tor ed in % temp. T o r emove the as s igned value and r emove
the var iable, us e the /uns et command. /uns et % temp will clear the
value of % temp, and r emove the var iable fr om the var iablelis t. B oth
/s et and /uns et has s witches which modify the way they per for m the
action, /s et - s will echo the value you'r e as s igning the var iable to, as
you ar e s etting it, wher eas /s et - uN will s et the var iable, and then
uns et it after N s econds . I f N is 0, the var iable will be uns et as s oon as
the cur r ent command/function has finis hed per for ming (this is ver y
us eful for loops and functions wher e the var iable only r eally is needed
while the function is per for ming. When uns etting a var iable, you may
us e wildcar ds to uns et mor e than one var iable at once, as well as
s pecifying two or mor e var iablenames in a s ingle line..f.ex /uns et
% temp* or /uns et % temp % tes t. A s pecial var iation of the /uns et
command is the /uns etall, which uns et'sall var iables fr om the var iable
lis t.
Modif yin g var iables
You may in cr eas e the value of a var iable by us ing the /inc command,
if you s pecify a value that value will be added to the var iable,
other wis e the var iable's value will be incr eas ed by 1. I f the var iable did
not ex is t befor e you us ed the /inc command, it will be cr eat ed with a
value equaling the /inc's value, if no value s pecified, it will have the
value 1. You may us e the - uN s witch with /inc as well, in a s imilar way
as with /s et. Likewis e, you may us e /dec to decr eas e the value of the
var iable. S imilar ly; if the var iable did not ex is t befor e the /dec, it will
be cr eated with a value equaling the /dec's value.
U s in g var iables
S o, what do we us e var iables for ? Well, as mentioned befor e we may
us e them for s tor ing data for us e in functions s uch as loops ,
awayr eas ons , tempor ar y data in calculations etc..let's look at an
ex ample: T his may be us ed in an aways cr ipt, wher e the we wis h to s ay
how long we've been away when we r etur n. We can us e theidentifier
$ctime for this . $ctime by its elf r etur ns the number of s econds s ince
Januar y 1s t, 1970 (don't as k me why 1970 = P), bas ed on your cur r ent
s ys tem time. T his we can us e in a s imple calculation like this ..:
T his s ection will concentr ate on a few les s categor iz e'able s ections
within s cr iptings that ar e often r eques ted, and r equir e a bit mor e indepth focus than the FAQ can pr ovide.As with any s ubj ect, if you've
got s ugges tions on what we s hould have her e, or comments , pleas e
email us : )
* I f- then- els e - T his is one of the mos t impor tant things to know for
any s cr ipter , as mos t ever ything you'll do will need to us e if- then- els e
techniques .
* Loops - T his ar ticle s hows you what loops ar e, how to us e them and
the differ ences between GOT O and WHI LE loops .
* Raw events - Ever wanted to do a kick bas ed on the channels other
us er s ar e on, or wr ite your own whois ? You'll us e r aw events for this ,
lear ning r aw events is a ver y r ewar ding effor t : )
* Cus tom windows - While les s us eful now than befor e, thanks to
dialogs , s till a power ful featur e.
* Has h tables - mI RC's newes t, and for many pur pos es , bes t, way of
s tor ing data.
And this is but a few topics , give us input on what you want an ar ticle
on, and we'll add it : )
I f -t h en -els e
Welcome to this little ar ticle wher e we'll look at one of the keyelements in mI RC s cr ipting, and for that matter , in any pr ogr amming
language; the if- then- els e s tatement.
Requir ed knowledge for this ar ticle is identifier s and alias es .
W h at is if -t h en -els e?
I f- then- els e, or j us t if -s t at em en t s is s hor t ter ms for I F this is tr ue,
T H E N do this , E L S E do s omething els e. I t's a tool that allows us to
cr eate code that is dynamically changing depending on s ever al factor s
s uch as us er input, mI RC ver s ion etc, ins tead of doing one thing and
only this one thing. Knowing if- then- els e is cr ucial if you want to
become a good coder .
T h e s yn t ax
I F ( v1 OP E R AT OR v2 ) T H E N { ex ecu t e t h is code } E L S E {
ex ecu t e t h is code }
We've als o got a var iation of this ;
I F ( v1 OP E R AT OR v2 ) T H E N { ex ecu t e t h is code } E L S E I F ( v1
OP E R AT OR v2 ) T H E N { ex ecu t e t h is code } E L S E { ex ecu t e t h is
code }
Oper at or s
An oper ator is a function or s ymbol that deter mines how v1 is
compar ed to v2. Mos t common is = = , which means is equal to, <
meaning is s maller than, > meaning is lar ger than. Other commonly
us ed oper ator s ar e = = = (Cas e S enS iT ive is equal to), != (is not), > =
(lar ger or equal to), < = (s maller or equal to), is in (v1 is in v2), is wm
(v1 is a wildcar d s tr ing in v2), is on (v1 is on channel v2), is op (v1 is an
op on channel v2), is chan (v1 is a channel which you ar e on). T her e
ar e other s , cons ult the mI RC helpfile (/help if- then- els e) for mor e info
on the s ubj ect. You can als o do multiple I F s tatements in one line by
us ing && or || to combine them, && meaning AND (if ( s t at em en t 1 )
AN D ( s t at em en t 2 ) ), || meaning OR (if ( s t at em en t ) OR
( s t at em en t ) ). Finally, you can negate an oper ator with placing a ! in
fr ont of the oper ator , thus !is op would mean (v1 is NOT an op on
channel v2).
An ex am ple
alias hug {
if ($1 = = $me) { des cr ibe $active gives hims elf a nice hug }
els e { des cr ibe $active gives $$1 a nice hug }
}
T his code bas ically s ays ; I F wor d1 is your own nick, then do a /me
gives hims elf a nice hug), ELS E do a /me gives wor d1 a nice hug.
/des cr ibe is a command that does a /me to the tar get, in this cas e the
tar get is $active, the active window.
$ i if
T his identifier is good for tes ting what an if s tatement would r etur n,
the s yntax is :
$ i if ( s t at em en t is t r u e,do t h is ,els e do t h is )
ar ound the ex ecute code is not needed, but it's s till however gener ally
r ecommended, as it's s uppos ed to s peed up the par s ing of s uch
s tatements and als o pr oduces eas ier - to- r ead code.
Als o note that each code s nippet needs the s ame number of opening {
and clos ing } br ackets , mis s ing opening or clos ing br ackets may r es ult
in code that's not ex ecuted in the cor r ect or der , is ex ecuted at the
wr ong time or j us t wr ongfully ex ecuted in gener al. You can often s pot
this in your r emotes if the beginning of an alias , r emote or popup
definition is indented (not quite to the left of the editor window). T o
check for br acket mis matches , you may als o pr es s the
button, this
will us ually take you to the ar ea wher e a br acket mis match er r or
occur s .
I hope you now have a little clear er under s tanding of what if- then- els e
is and how to us e it, feel fr ee to email us and tell us what's s till unclear
:)
L oops
Welcome to this little ar ticle on one of mI RC s cr ipting's mos t us eful
featur es , the ability to loop.
Pr er equir ements for this ar ticle is knowledge of I F- T HEN- ELS E, alias es ,
identifier s and var iables .
W h at ar e loops ?
A loop is a piece of code that r epeats its elf for as long as we decide,
the end or the beginning of the loop has ins tr uctions that caus es the
loop to know when it s hould j ump to the beginning of the loop's code,
and r epeat once mor e.
Without loops , it's unlikely that computer s and pr ogr amming would
have come ver y far . Let's look at a s imple alias that lis ts all channels
you'r e on. Fir s t without the us e of loops :
alias chlis t {
echo - a I 'm on $chan(0) channels :
if ($chan(1) != $null) { echo - a Channel 1 is $chan(1) }
if ($chan(2) != $null) { echo - a Channel 2 is $chan(2) }
if ($chan(3) != $null) { echo - a Channel 3 is $chan(3) }
if ($chan(4) != $null) { echo - a Channel 4 is $chan(4) }
if ($chan(5) != $null) { echo - a Channel 5 is $chan(5) }
if ($chan(6) != $null) { echo - a Channel 6 is $chan(6) }
if ($chan(7) != $null) { echo - a Channel 7 is $chan(7) }
echo - a End of channel lis ting
}
T hen the s ame command with a W H I L E loop:
alias chlis t2 {
var % max = $chan(0), % c = 1
echo - a I 'm on % max channels :
while (% c < = % max ) { echo - a Channel % c is $chan(% c) | inc % c }
echo - a End of channel lis ting
}
I f you've gotmI RC 5.70 or above, you can us e the WHI LE loop'd code
in chlis t2 ins tead of chlis t, which har dcodes ever ything. Even if you us e
an ear lier ver s ion than 5.70, you can s till loop, us ing GOT O loops . I 'll
get back to this later on, for now let's quickly obs er ve the main
advantage with loops : FAR s maller code.
S o h ow does it w or k?
T he technique of looping takes advantage of dynamic elements in code
s uch as var iables and identifier s , looking at the ear lier ex amples , all
the lines in the lis ting was equal ex cept for the number s 1 - 7. Loops
ar e ideal for pur pos es like lis ting or per for ming a line of functions that
ar e almos t ex actly s imilar .
Wether you us e WHI LE loops or the older for m, GOT O loops , t h e
s t ar t in g poin t of a loop is an I F s t at em en t that deter mines how
long the loop will r un. Let's look at both for ms of loops a little clos er .
GOT O loops
For year s this was the only option for mI RC s cr ipter s to cr eate loops ,
and becaus e mI RC s cr ipting is what it is , GOT O loops ar e s till us ed by
s ome people. T he s yntax of a GOT O loop is as follows :
header {
< s ome code>
: tar get
I F (if s tatement) {
commands to per for m per r e- iter ation
inc % counter
GOT O tar get
}
< s ome code>
}
T he key elements her e is the : tar get, the I F s tatement, the inc
% counter and the GOT O tar get. T he : tar get is liter ally a tar get in the
code that can be r eached by us ing the GOT O command, the I F
s tatement is what will eventually s top the loop fr om r eiter ating, and
the inc % counter is the command that gives dynamic to the loop. Let's
s ee how the ex ample fr om above would look us ing a GOT O loop.
alias chlis t3 {
var % max = $chan(0), % c = 1
echo - a I 'm on % max channels :
: top
if (% c < = % max ) { echo - a Channel % c is $chan(% c) | inc % c |
goto top }
echo - a End of channel lis ting
}
As we s ee, not that differ ent. T he : top tar get is the s tar ting point of
the loop (note that the line above only is s howed once, thus it's not in
the loop), as ide fr om s pecifying the tar get and us ing goto top at the
end of the loop, all the lines ar e s imilar to a WHI LE loop. Each : tar get
mus t be unique for the alias /popup/r emote that called it, meaning if
we wanted another loop within the loop in chlis t3, we would need to
call the tar get s omething els e, for ins tance : top2. Als o note that while
we s pecify the tar get's location in the code with : tar getname, we us e
only goto tar getname when us ing goto to j ump to that tar get.
Goto loops is what you have to s ettle for if you'r e us ing mI RC 5.61 or
ear lier , but for mI RC 5.70 and newer we have a better tool, the WHI LE
loop:
W H I L E loops
We have alr eady s een the WHI LE loop in action, in our channel lis ting
alias , chlis t2. T he s yntax for a WHI LE loop is as follows :
header {
< s ome code>
WHI LE (if s tatement) {
commands to per for m per r e- iter ation
inc % counter
}
< s ome code>
}
T he key elements in a WHI LE loop is the WHI LE s tatement its elf and
the inc % counter . T he WHI LE s tatement is a r egular if- then- els e
s tatement and indicates the s tar t of the loop, as well as deter mines
when the loop s hould end. I nc % counter incr eas es the contr ol var iable
and allows us to meas ur e the pr ogr es s of the loop.
Let's look at an ex ample again, this time we'll look at an alias that
color s nicknames in a channel accor ding to their s tatus .
alias ncol {
var % max = $nick(# ,0), % c = 1
WHI LE (% c < = % max ) {
if ($nick(# ,% c) is op # ) { cline 4 # $nick(# ,% c) }
els eif ($nick(# ,% c) is vo # ) { cline 5 $nick(# ,% c) }
if ($nick(# ,% c) = = $me) { cline 3 $me }
I NC % c
}
}
T he fir s t line initializ es the var iables we'll us e in the alias , the WHI LE is
a s imple if s tatement that s tops the loop when the counter var iable % c
becomes lar ger than % max , which is the number of nicks in the
channel. T he body of the loop cons is ts of 4 lines , line 1 color s the
cur r ent nickname r ed if he/s he is an op in the channel, line 2 color s
the nick br own/dar k r ed if he/s he is a voice, line 3 color s your own
nick gr een, and line 4 incr eas es the counter var iable % c.
S imple, is n't it? = ) I f we wanted to do this without loops , we would
have to wr ite an alias that would be s omewher e ar ound 50- 100 lines
long, j us t to ens ur e we had mids iz ed channels accounted for , many
channels have mor e than 100 us er s and our mas s ive alias wouldn't
wor k fully for thes e channels . With a loop, you don't have to wor r y
about how many us er s ar e in a channel, but only about wr iting an
effective loop to per for m the tas ks you need as quickly as pos s ibly.
L ocku ps
T her e's a few things to note when us ing loops . Fir s t, things will go
wr ong. You will always encounter pr oblems wher e a var iable does n't
evaluate as you think it s hould, and the loop will never know when to
s top, you've got a s o- calledI nfinite loop. I f this happens , your mI RC
will lock up, but fear not! For s ee, pr es s ct r l+ br eak (the br eak key is
us ually located at the top r ight of mos t keyboar ds , as ide the s cr oll lock
key), and mI RC will br eak out of the endles s loop.
T he mos t common r eas on for an infinite loop is that you for get to inc
the counter , which means the if s tatement always will be tr ue. I f you
s hould get an infinite loop, your bes t tip is to look at the if- then- els e
s tatement and ens ur e that you ar e modifying the counter var iable.
Another thing r egar ding loops ; s ometimes they j us t plainly take a long
time to finis h ex ecuting. I n s ome cas es , s ever al minutes . And while the
loop is ex ecuting, mI RC may lock up. T his is not a pr oblem if the loop
takes only a few milis econds to finis h, but if it takes minutes , you r is k
that your mI RC s es s ion is bus y doing the loop and won't r eply to the
s er ver 's PI NG, with a r es ult that you get dis connected becaus e the I RC
s er ver thinks you'r e no longer connected.
T o pr event this , you can either tr y to us e fas ter r outines , or you may
r un an ex tr a mI RC s es s ion j us t for the pur pos e of per for ming the loop,
and clos e it once the loop finis hes . T his way the mI RC s es s ion that's
connected to I RC will be fr ee to do it's nor mal tas ks .
S peed
I 've tes ted the s peed of both GOT O and WHI LE loops with 2 s imple
alias es as follows :
alias gs peed {
var % s = $ticks , % c = 1, % max = $1
: top
if (% c < = % max ) { inc % c | goto top }
echo - a Ended GOT O loop after % max r uns , in $calc($ticks - % s )
ticks
}
alias ws peed {
var % s = $ticks , % c = 1, % max = $1
while (% c < = % max ) { inc % c }
echo - a Ended WHI LE loop after % max r uns , in $calc($ticks - % s )
ticks
}
Us age is /gs peed N or /ws peed N wher e N is the amount of loops to
per for m. Note that this tes t only tes ts the s peed of incr eas ing the
counter and continuing the loop, the loop does not per for m any
commands as given her e. With 3 tes t values , 1,000, 10,000 and
100,000 r eiter ations , the r es ults wer e as follows (aver age of 3 r uns ,
amount is in ticks (1,000 ticks is 1 s ec)):
1 ,0 0 0
1 0 ,0 0 0
1 0 0 ,0 0 0
GOT O
140
1545
15649
WHI LE
126
1348
13681
T he r es ults s ugges t that for thes e r ather us eles s loops , WHI LE loops
ar e fas ter than GOT O loops , as much as 2 s econds fas ter on 100,000
r eiter ations . T her e ar e many facts to cons ider when deter mining
s peed, s o r es ults for loops that actually per for ms any commands may
var y fr om this tes t, however WHI LE loops will s till be the fas ter way.
Con clu s ion
I n this ar ticle we've been ex plor ing the advantages to us ing loops , as
well as looking clos er at the var ious types of loops , what can we r ead
fr om all this ?
Fir s t off; us ing loops is nex t to always the eas ies t and fas tes t way to
per for m lis tings or multiple s imilar commands at, as the r es ults above
s how, ar ound 1- 2 s econds for 10,000 r uns of a loop, that's not bad ; )
S econd; WHI LE loops ar e fas ter and s maller in code than GOT O loops .
T hus , WHI LE loops s hould always be us ed if your mI RC ver s ion is
newer than 5.70 and you ar e not wor r ied about backwar ds
compatibility in your s cr ipt. I f you need your s cr ipt to be compatible
with ear lier ver s ions of mI RC, you will need to us e GOT O loops .
T he r eal tr ick to mI RC s cr ipting and pr ogr amming in gener al is as
much to be able to s ee what tool is the r ight at what place, hopefully
with this ar ticle you have gotten a mor e intimate knowledge of loops
and can s tar t applying this knowledge to s cr ipting pr oblems you face : )
R aw even t s
Welcome to this little ar ticle on r aw events . When talking about " r aw" ,
we either mean r aw commands s ent to the s er ver (ie, /r aw pr ivms g
nickname : mes s age goes her e ins tead of /ms g nickname mes s age
goes her e), or r aw events . I n bot h cas es w e' r e t alkin g abou t t h e
n at ive f or m at of t h e I R C s er ver , r ather than the way mI RC or your
client of choice pr es ents or us es the infor mation. I n this ar ticle, we'll
be talking about r aw events , not r aw commands .
Pr e- r equir ements for this ar ticle is knowledge of r emotes , identifier s ,
if- then- els e, and var iables .
W h at ar e r aw even t s ?
Raw events ar e r egular mI RC s cr ipting events that tr igger when the
s er ver s ends you a mes s age as a r es ult of s omething you do, for
ins tance j oining a channel. When you do this , the s er ver will a) s end
you the names on the channel (s imilar to /names ), b) cur r ent topic of
the channel as well as c) the channel's cr eationtime.
Raw events r eceive the infor mation fr om the s er ver in it's native for m,
and gives you max imum flex ibility in r egar ds to how you choos e to us e
it or pr es ent it to the us er of your s cr ipt.
H ow do I u s e r aw even t s ?
Let's fir s t look at the s yntax of r aw events :
r aw N U MB E R : MAT CH T E XT : { com m an ds }
NUMB ER her e is the number of the numer ic event you wis h to define,
thes e ar e s et down in RFC1459 which is the I RC pr otocol, and ar e als o
lis ted mor e conveniently in Jeeps ter 's numer ic helpfile
. I f a r aw event
does not have a numer ic, you can s pecify it's name ins tead.
MAT CHT EXT is which tex t s hould tr igger the event, much like the
MAT CHT EXT par ameter in an on tex t event. Fr om /help r aw events ;
r aw 322: * mir c* : { echo 5 $1- }
will filter out all channels matching " mir c" in a /lis t, and echo them to
the s tatus window.
T o actually * us e* r aw events , you need to have a fir m knowledge of
r aw events , or be able to look up infor mation and again, for this
pur pos e, Jeeps ter 's numer ic helpfile is gr eat = ) I n addition, as s o
many other things in s cr ipting and pr ogr amming, mos t of the tr ick with
r aw events is s imply s eeing wher e they can be us eful.
A clos er look
Let's look at the r aw output of a/who:
r aw 352: * : { echo - a Raw $numer ic $+ : $1- }
mI RC will by default s how this output (after /who # B 0P's) :
# B 0P's B 0T H@ bop@ playing.with.my.pet.I RCop.com : 5 B 0P's B 0T http: //mir c- egg.net
# B 0P's B 0P- away G@ bop@ r ad- pc- 57.cablenet- va.com : 0 B 0P
(http: //mir c- egg.net)
but as alr eady s aid, this r eply has been for matted by mI RC, the
mes s age the s er ver s ends mI RC is actually the one below:
$1
$2
$3
$4
$5
$6
$7
$8
B 0Paway
# B0
bop
P's
playing.with.my.pet lineone.uk.eu
B 0T H@
.I RCop.com
.dal.net
$9B 0P's
B 0T http: //m
ir cegg.net
B 0Paway
# B0
bop
P's
B 0P
r ad- pc- 57.cablenet- liber ty.nj .us . G@
va.com
dal.net
awa
y
B 0P
(http: //
mir cegg.net)
T his
is the
T his
T his is T his T his
numb
r epr es
the
is
is the
T his
er of
ents
nick of the cur r e
is
hops
T his is the
s tatus
T his is
the
tar g ntly T his is the hos t of
the
(s er v
s er ver the
in the
the
us er
et
r etur the cur r ently
us e
er s
us er is
chann
r ealnam
r eques for ned r etur ned us er .
r 's
betw
connected to.
el as
e entr y
ting
the us er 's
nick
een
well as
the
/wh ident
.
you
away/
/who. o
d
and
not.
tar ge
t)
Let's make a channel s tats s cr ipt and s ee if an ex ample makes it
clear er : )
Ch an n el s t at s ex am ple
/who output, r aw 315 is the r aw for " end of /who lis t" , we us e r aw 352
to gather infor mation about each us er , and when we r eceive r aw 315,
we know that ther e's no mor e us er s to gain infor mation about, s o we
can pr es ent the output to the us er . T his s cr iplet als o s hows how we
can us e haltdef (or even halt) to pr event the default output fr om
s howing up, if we didn't do this , the us er would s ee the output of the
/who as well as the nice channel s tats .
T he mor e you s cr ipt with r aw events , the mor e you'll r ealiz e both how
s imple it is , as well as how much it means to be able to s ee that this or
that can be done by us ing r aw events . For ins tance, a common
mis take in s cr ipting is when the s cr ipter wants the s cr ipt to take action
bas ed on what channels a differ ent us er is on (a s o called per vs can ),
he us es the if- then- els e oper ator I S ON to deter mine if the us er is on a
cer tain channel or not. I S ON is fine if the us er r unning the s cr ipt is on
that channel too, but in mos t cas es , he won't be, and that's wher e r aw
events come in again.
An ot h er ex am ple, t h e B ad Ch an n els kicker
Cur r ently the only way to know what channels a s pecific nickname on
I RC is on, is doing a /whois on them. I S ON won't do it, becaus e as
alr eady s tated; I S ON r eacts only on channels you ar e on your s elf. S o
we have to us e /whois s omehow to deter mine the channels the us er is
on. T her e's s ever al pr oblems that ar is es her e, let's tr y to nar r ow it
down a little:
Fir s t, let's find outw h ich r aw even t s t r igger s on a w h ois (ther e's a
lot!). I s tated pr evious ly that two maj or s our ces for mor e info on r aw
events was the RFC, as well as Jeeps ter 's numer ic helpfile
. For mos t
s cr ipting pur pos es , Jeeps ter 's helpfile is by far the eas ier choice, s o
download it if you haven't and s tar t looking..: )
Double clicking numer ic.hlp opens up a dialog s howing the help topics
available, choos e " Contents " . Now click on " Numer ic Code" (Fas t
r efer ence). T his opens up the ver y handy quicklis t for fr equently us ed
r aw's , under T opical Numer ics we s eeWHOI S lis ted. B ingo! Click
WHOI S . T his opens up the helpfile on S er ies 300 Command r eplies , on
r aw 311. Raw 311 is the r aw containing our " r eal name" entr y, and
her e indicates the s tar t of the WHOI S r eplies . Without any mor e
cer emony; r aw 311, 312, 317, 318, 319. I n addition you may als o s ee
r aw 301 (away), 307 (dalnet - r egis ter ed nick), 313 (is an ir cop).
Looking over the events , we quickly s ee that r aw 319 is
R P L _ W H OI S CH AN N E L S ; it r etur ns the channels the us er s pecified is
on. We als o s ee that r aw 318 is en d of w h ois , us eful to know for
when we will be taking action bas ed on the channels in r aw 319.
We do not need to us e any infor mation r etur ned by any of the other
r aw's fr om the WHOI S , s o we will j us t s ilence thes e us ing/haltdef, to
halt the default output fr om the event and in s ome cas es pr es ent our
own. Finally the alias does a /whois on the nick enter ed.
Raw 319 matches the channels in $3- agains t the wor ds " war ez " and
" s ex " , and if found, it s ets a var iable that is car r ied into r aw 318 (end
of whois ). When r aw 318 tr igger s , it checks to s ee if the var iable is
s et, if it is , it kicks the us er s pecified, els e it lets you know that the
us er was not in any bad channels .
Con clu s ion
While not among the mos t obvious featur es of mI RC s cr ipting, lear ning
how to us e r aw events is one of the mos t valuable things you can do,
it's eas y, allows you to do many things you other wis e wouldn't be able
to (s uch as the channels canner ), and is als o an inter es ting tool for
modifying the look and feel of mI RC. T o effectively us e it; a decent
knowledge of r aw events in gener al and being able to look up which
event does what, will s ur ely come handy, and I hope this ar ticle have
got you s tar ted on the tas k of mas ter ing r aw events . Good luck : )
Cu s t om W in dow s
B efor e dialogs was intr oduced in mI RC 5.50, the main way to make a
gr aphical us er inter face GUI for your us er s was cus tom windows , and
their cous ins , pictur e windows (which j us t is a kind of cus tom window).
T hey wer e not as s imple and intuitive to us e as dialogs , but the good
s cr ipter s could make good inter faces that would outs hine any dialog,
and even today ther e's s ever al things a cus tom window can do that a
dialog cannot. T his ar ticle in s pecific won't teach you window wiz 's
anything s ens ational, it's a mer e intr oduction to the wor ld of cus tom
windows , take it as that. Let's move on to the good s tuff : )
Open in g a cu s t om w in dow
T o open a cus tom window, us e the /window command. You'll find
your s elf us ing that command a whole lot, almos t ever ything that
modifies , cr eates or clos es a cus tom window is done with that
command and it's var ious s witches . T ype/window @ tes t to open up a
window called @ t es t . Whee! T o add tex t to it, /aline @ tes t tes ting or
/echo @ tes t tes ting = )
We've now opened a cus tom window, and we've added tex t to it. B ut if
that was all, cus tom windows would be bor ing quite fr ankly. Let's look
at a few ways to modify the look of your cus tom window : )
Let's look at what this command does . T he- d s witch fir s t s pecifies that
this will be a des ktop window. While you cannot s ee this at the
s cr eens hot, this window is indeed a des ktop window. - h hides the
window fr om the mI RC tas kbar , - k r emoves the @ pr efix in the
windowname (as we've alr eady mentioned), and- l s pecifies that we'r e
opening a lis tbox window. T he r eas ons for opening a window as a
lis tbox window can be var ious , in this s pecific ins tance it is to enable
the us e of tabs in the window, which is what the - t7,23 etc par t is
about, it s ets the tabs tops for the window.
@ RawCaptur e is of cour s e the window's name, and1 90 s pecifies X
coor dinate 1 (to the far left of the mI RC window), Y coor dinate 90,
which in this ex ample quite unelegantly makes the window cover the
mI RC tas kbar . 600 200 s pecifies 600 in width for the window, and 200
in height. We s ee that r elatively to the main mI RC window, 200 does
not mean a ver y huge window. @ Rc after this means " us e the cus tom
window menu with name @ Rc" , we'll come back to this in a little while,
and finally, Ar ial 9 s pecifies the fonttype and s iz e for our window = )
Makin g a m en u f or a cu s t om w in dow
You have two ways of making menu's for a cus tom window, either by
making a plain tex tfile which contains the menu's you wis h to add, or
by s pecifying the menu's dir ectly in the r emote file
. T he method
s pecified in the above ex ample was the latter , s pecifying the menu's
dir ectly in the r emote file. I f you would do it the other way, you would
need to s pecify filename.tx t ins tead of the @ Rc (or the name of the
menu to us e). T o s pecify the menu in the r emote file dir ectly, you'll
make a menu definition like this ..:
menu @ Rc {
Clos e: { window - c $active }
dclick: { echo - a Hi ther e $me $+ ! }
}
T his would then cr eate a menu in the cus tom window that allowed you
to clos e the window if you r ight clicked and chos e Clos e, or that would
echo a s illy mes s age if you doubleclicked the window.
I f you chos e to ins tead make a tex tfile with the popups , the s yntax
would be almos t s imilar , ex cept that you would not include the menu {
} s pecifications in the tex tfile:
Clos e: { window - c $active }
dclick: { echo - a Hi ther e $me $+ ! }
Addin g, r em ovin g an d m odif yin g t ex t
As alr eady s aid, to add tex t to a cus tom window, /aline or /echo it.
T her e ar e a number of s witches that can be us ed together with both,
let's take a quick peek at the s yntax of s ome commands to add/modify
the content of a cus tom window:
/aline [c] < @ name> < tex t> adds tex t to window. I t will add it to the
bottom par t of the window, with color C. For ins tance, /aline 4 @ tes t
Whatever will add Whatever to the cus tom window @ tes t, with r ed
tex t.
/cline [c] < @ name> < N> changes the colour of line N to colour C. N is
counted fr om the top. For ins tance, /cline 2 @ tes t 3 will color the 2nd
line fr om the top in the cus tom window @ tes t gr een
/dline < @ name> < N[- N2]> will delete the N'thline fr om the window,
optionally it will delete N- N2 if N2 is s pecified. /dline @ tes t 2 will delete
the 2nd line fr om the top in @ tes t, wher eas /dline @ tes t 2- 4 will delete
line 2 thr ough 4 in @ tes t.
/iline [c] < @ name> < N> < tex t> will ins er t tex t at line N (again
counted fr om the top) with color C in @ tes t. For ins tance /iline 3 @ tes t
5 bleh will ins er t bleh in gr een on line 5 in @ tes t. I f you s pecify a
higher linenumber than the number of lines in the window, the tex t will
be added to the bottom of the ex is ting tex t, as if you us ed /aline.
/r line [c] < @ name> < N> < tex t> r eplaces N'th line./r line 10 @ tes t 3
hehe will r eplace line 3 in the cus tom window @ tes t with hehe in teal.
/s line < @ name> < N> s elects the N'th line, thus/s line @ tes t 2 will
s elect the 2nd line in @ tes t.
With all thes e, you als o have s witches to modify the ex ecution of the
command... the - s s witch s elects the line that was j us t added by ili n e,
al in e or r l in e, and clear s the cur r ent s elections (per for ms a s line on
the r ecently added line). T he - a s witch s elects a line without clear ing
fonts iz e us ed in the window. fontbold als o wor ks in this par t, r etur ning
$tr ue if the window is us ing a bold font, other wis e $fals e.
Ot h er iden t if ier s in clu de
$line(@ name,N,T ) which r etur ns the N'th (fr om above) line of tex t in
the window s pecified, if you choos e 0 for N, it will r etur n the number of
lines in the window (us eful for loops : )) T is ther e s o you can have the
identifier wor king on the s ide lis tbox (if one ex is ts ), if T is 0, it will us e
the r egular dis play ar ea, if T is 1 it will us e the s ide- lis tbox . T is
optional.
$fline(@ name,wildtex t,N,T ) Retur ns the N'th line wher e wildtex t is
found, again counted fr om the top. Wildtex t is liter ally wildcar d tex t,
$fline(@ tes t,bleh* ,0) will r etur n the number of lines that s tar t with
bleh, wher eas $fline(@ tes t,* what* ,2) will r etur n the 2nd line fr om the
top that has what in it s omewher e (s tar ting with, ending with or
containing what). Again, T is optional and wor ks s imilar ly as for $line.
$s line(@ name,N) Retur ns the N'th s elected line in a lis tbox window
($s line only wor ks in lis tbox windows ). I f N is 0, $s line will r etur n the
total number of s elected lines in the window. $s line als o has a
pr oper ty, the ln pr oper ty, which r etur ns the number of the N'th
s elected line.
T hat concludes the ar ticle for now, if r eques ted I 'll als o add s ome
s cr ipting ex amples to the ar ticle to s how pr actical us e of cus tom
windows . Pictur e windows is a too big topic to touch her e, s o we'll
come back to thes e in a later ar ticle : )
I n t r odu ct ion t o H as h T ables
I n t r o:
With the intr oduction of has h tables in mI RC v5.80, mir c s cr ipter s
finally got acces s to one of the mos t us eful as pects in coding; the us e
of ar r ays . Ar r ays ar e multi- dimens ional var iables that can s tor e
multiple values that each can be r efer enced uniquely.
mI RC's has h tables ar e s imilar , yet not entir ely the s ame as ar r ays . I n
this ar ticle we will look at what they ar e, and how to us e them.
P ar t 1 :
Cr eat in g t h e h as h t able
While has h tables ar e tempor ar y s tor age s pace in much the s ame way
as var iables ar e, they differ fr om var iables in many ways , the way you
cr eate them not the leas t s ignificant.
A nor mal var iable will be cr eated the moment you as s ign a value to it
(ie; /s et % bleh blah). A has h table however , mus t be cr eated with a
s epar ate command, befor e you can add data to it. T o do this , we us e
the / h m ake command.
S yntax :
T he - s s witch is optional and will make the command dis play the r es ult
s imilar to how the s witch wor ks for 'nor mal' var iables .
Name is effectively the name of the var iable, you'll us e this to
r efer ence to the var iable later .
N is a s iz e indicator . S pecifying an N that is ar ound 1/10 of the
number of items you wis h to s tor e in the table is s ufficient for optimal
s peed. However , a has h table can s tor e a vir tually unlimited number of
items , r egar dles s .
P ar t 2 :
R em ovin g ( delet in g) a h as h t able
T he natur e of has h tables is fluctuos , the data s tor ed in a has h table
(and indeed the table its elf) is deleted when you clos e mI RC. We will
come back to how to s tor e data in has h tables mor e per manently
below. I f you wis h to delete a has h table manually (to us e it for
another pur pos e or to fr ee the memor y us ed by the table), you will
us e the / h f r ee command.
S yntax :
S imilar to .ini files , item is the " label" of the data you'r e s tor ing, and
data (of cour s e) is the data to s tor e (note that data is optional).
T o r emove an item fr om a table, us e the / h del command:
S yntax :
S imilar ly as for /hs ave, the - b s witch indicates that the file s pecified is
a binar y file, and $cr /$lf char acter s s hould be r etained. T he - n s witch
als o wor k s imilar ly as for /hs ave, meaning that the table loaded will
not have the s aved labels , but us e numer ic labels wher e the 1s t item
is is labeled " 1" and s o on..
All thes e commands ar e well and good, but they do not pr ovide any
means to r ead the data fr om the has h table. T hat is wher e the
identifier s come into play...
P ar t 5 :
$ h get
$hget is the mos t ver s atile has h table identifier , functioning both as a
gener ic table identifier s howing infor mation about a s pecific has h
table, as well as being a data- r etr iever , fetching data fr om the given
item name.
S yntax :
$hget(name/N)
Us ed this way, the identifier r etur ns the name of a given has h table if
it ex is ts , or r etur ns the name of the Nth has h table. As for mos t other
s imilar s tyle identifier s in mI RC, a N of 0 will r etur n the number of
open has h tables . Us ed with the .s iz e pr oper ty, $hget will r etur n the
s iz e of the table in N (as you s pecified in /hmake name N).
S yntax :
$hget(name/N,item)
T his way, $hget will allow you to fetch the infor mation s tor ed in item
nr N, or the item label named in it em .
S yntax :
$hget(name/N,N).item
$hget will this way allow you to r efer ence a table as an index fr om 0
to N, in or der to look up the Nth item in the table. I f you s et N as 0,
it'll r etur n the total number of items .
P ar t 6 :
$ h f in d an d $ h m at ch
T hes e ar e the two s ear ch methods you may us e to locate infor mation
in the has h table.
S yntax :
$hfind/$hmatch(name/N,tex t,N)
T he identifier s will r etur n the Nth item name matching tex t. $hfind
s ear ches for an ex act match of tex t, while $hmatch cons ider s tex t to
be wildcar ded. B oth identifier s can us e the .dat a pr oper ty, in which
cas e they r etur n the data ins tead of the item name.
P ar t 7 :
An ex am ple - ! S een addon
A s een s cr ipt is a s cr ipt that will s tor e people j oining a channel you'r e
in, and upon an us er 's r eques t (us ing s ome kind of tr igger wor d,
typically !s een < nick> ), will tell the per s on when, if at all, the us er
was las t s een.
T his addon will be s imple, and not account for many of the commonly
r eques ted featur es of a s een addon, as the pur pos e is to s how the
pr actical us e of has h tables : ) T he below code r equir e mI RC v5.9 to
r un.
T h e code
inter vals .
alias - l bkup {
; T his is an alias we'll us e to back up the data at fr equent
I F ($s cr ipt(bs een.mr c)) {
; I f the s cr ipt is loaded, per for m backup as nor mal
hs ave - o b- s een $s cr iptdir b- s een.htb
echo 10 - s * * * S aved !s een databas e
}
ELS E {
; T he s cr ipt has been unloaded, tur n off the timer to back
up and
!s een): {
!s een command.
I F ($gr oup(# b- s een) = = off) {
.enable # b- s een
echo 10 - s * * * B - s een enabled
.timer s eenbkup 0 900 bkup
}
ELS E {
.dis able # b- s een
echo 10 - s * * * B - s een dis abled
bkup
.timer s eenbkup off
}
}
}
bkup }
to make it
s hould be
ear lier ,
and if he did, r egis ter s the old nick as par ting as well.
hadd b- s een $nick $ctime par t $chan
; r egis ter s the cur r ent nickname only as par ting
ON !* : QUI T : {
var % t = $hfind(b- s een,$nick)
I F (% t) { hadd b- s een % t $ctime quit new $nick }
hadd b- s een $nick $ctime quit
; as for the par t event
}
# b- s een on
; allows us to dis able the public !s een command with a
s imple command
ON * : T EXT : !s een * : # : {
var % tar get = $s tr ip($2)
; s tr ips contr ol codes in cas e the us er s hould be us ing an
nc
inc - u15 % b- s een
I F (% b- s een > 4) { r etur n }
; the two above lines pr ovides a cr ude flood pr otection,
pr eventing any output if mor e than 4 !s een's wer e typed
within the las t 15 s econds .
ELS E {
I F (% tar get = = $nick) { var % t = Looking for yer s elf,
eh $nick $+ ? }
ELS EI F (% tar get = = $me) { var % t = Duh, I 'm r ight
her e s illy : ) }
ELS EI F (% tar get is on $active) { var % t = $2 is in
$active $+ ! }
ELS EI F ($comchan(% tar get,0) > 0) { var % t = $2 is
on $comchan(% tar get,1) $+ ! }
; the above is in cas e the r eques ted !s een tar get is s till
on one or mor e channels we'r e in.
ELS E {
var % t = $hget(b- s een,% tar get)
; s tor es the infor mation about the r eques ted !s een
tar get in a
tempor ar y var iable for our us e.
I F (% t) {
the
}
ELS E {
var % t = $2 was las t s een as $gettok(% t,4,32)
on $as ctime(% ts ,hh: nnt - mm/dd/yy) $+ , $&
$dur ation($calc($ctime - % ts )) ago, s igning off
I RC.
}
}
ELS EI F (% a = = new) {
I F ($comchan($gettok(% t,3,32),0) > 0) {
var % t = $2 was las t s een on
$as ctime(% ts ,hh: nnt - mm/dd/yy) $+ , $&
$dur ation($calc($ctime - % ts )) ago, changing
nick to $gettok(% t,3,32) $+ . $&
$gettok(% t,3,32) is s till on
$comchan($gettok(% t,3,32),1) $+ !
}
; this one tr igger s if the us er was las t s een
changing nick,
and he s till is on a channel we'r e on.
ELS E {
var % t = $2 was las t s een on
$as ctime(% ts ,hh: nnt - mm/dd/yy) $+ , $&
$dur ation($calc($ctime - % ts )) ago, changing
nick to $gettok(% t,3,32) $+ . $&
Can't s eem to s ee $gettok(% t,3,32) in any
channel at the moment though.
}
; as above, but this one tr igger s if the us er is not a
channel we'r e on anymor e.
}
}
ELS E {
% t = $2 is not on any channel I 'm on, and I can't
r ecall ever s eeing $2 $+ , s or r y!
}
}
ms g $tar get % t
; this is the las t event, s ends the s een mes s age to the
channel
wher e the !s een command was us ed.
}
}
# b- s een end