Sunteți pe pagina 1din 62

I r c/ m I R C com m an ds

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....-

nickN] to r emove nicks fr om the watch lis t, or j us t /watch


to s how your watch lis t. While notify only takes in account
the nick of the notify- entr y, watch als o takes in account
the hos t of the watch- entr y, when notifying you of us er s in
your lis t s igning on.
m I R C com m an ds
T hes e commands ar e s pecific to mI RC, and while many of them can be
us ed dir ectly to affect your I RC s es s ion immediately, a good many of
them ar e dir ected at s cr ipter s , and will have only limited / no meaning
for many r egular I RC'er s . T hes e ar e ex plained well in the mI RC help
file, s o I will only comment on a ver y few commands her e:
- Al ias : ( /alias [filename (optional)] < n am e of ali as
(what you type to ex ecute it)> < com m an d(s )> )
T his command allows you to add or modify alias es fr om
the command line. T his allow you to make s mall s hor tcuts
to make your ever yday I RC s es s ion eas ier , and while you
can't us e this to cr eate ver y advanced alias es for us e in
your s cr ipt, many people find it handy to s ave them typing
and time. T o add mor e than one command to be
per for med by the alias , us e a '| ' to s epar ate the
commands , ie;
/alias hop par t # | j oin # $1
Now you would j us t type /hop # mI RC to leave your
cur r ent channel and j oin # mI RC.
- H elp: ( /help [keywor d] )
T he helpfile does have it's weaknes s es . B ut r eading it,
often and thor oughly, can help you s olve pr oblems you
have, or j us t lear ning s cr ipting. I f you'r e making s omething
that s hould r eact to a ban being made, type /help on ban
and get help on the ban event, tes t it out, s ee how it
wor ks , r ead s ome mor e, until you've got it r ight. I f you'r e
s tuck, as k, for ins tance in a helping channel like
# HelpDes k, but be s ur e you've r ead the help befor e you do
: ) Of cour s e, never be afr aid to as k, the helpfile is far fr om
per fect, but it's actually quite good : )./help j us t opens the
helpfile in the contents lis ting, while /help < keywor d>
gives help on keywor d.
- R u n : ( /r un [- n (optional)] < f ile t o r u n (including path, if
neces s ar y)> [par ameter s (optional)] )
T his command r uns a pr ogr am, or a file (in which cas e it
will effectively ex ecute the pr ogr am as s ociated with the

file, us ing the filename as pr imar y par ameter s ), with


optional par ameter s as well. T he - n s witch minimiz es the
pr ogr am/file being r un, in mos t cas es . T he only r eas on
why I mention this command s pecifically is a little thing
I 've noticed; many s cr ipts s eem to tend to us e/r un
pr ogr am.ex e filename, in other wor ds , r unning a pr ogr am
with an additional filename as the file to open. While this is
all fine and ok, it is in mos t cas es ver y unneces s ar y. I f you
want to open a .tx t file in notepad, and .tx t files ar e
as s ociated with notepad (which they ar e on mos t winXX
computer s ), then j us t us ing /r un filename.tx t is a mor e
effecient way of doing this . T his als o s aves you fr om the
tr ouble of locating the pr ogr am you want to r un the file
with, but ins tead letting the O/S choos e the appr opr iate
way to s tar t it. Of cour s e, nothing s tops you fr om adding a
pr ogr am if you want to for ce a file to be opened by a
s pecific pr ogr am..
- E ch o: ( /echo [colour (optional)] [par ameter s (optional)]
< T ex t > )
Echo is par ticular ly handy for one thing, namely evaluating
identifier s and ex pr es s ions you us e in your s cr ipt. For
ins tance, you want to know what the $s er ver identifier
does , s imple, us e //echo $s er ver , and voil, you can s ee
that it r etur ns the name of the s er ver you'r e cur r ently
connected to. While this was a s imple ex ample, you can
put together complex cons tr uctions of identifier s for us e in
your s cr ipt, and to evaluate them without having to r un
your s cr ipt, you may us e the echo command. I f you'r e
online, you can of cour s e us e //s ay, but //echo s hows the
r es ult to you only, and wor ks while offline (note though
that s ome identifier s only will evaluate while online, s uch
as $s er ver for ins tance : )), //s ay r equir es you to be online
and s hows the r es ult to ever ybody in the s ame channel as
you or to the nick of the us er you'r e having a quer y
window open with. Us e echo : ). Pleas e note that yes , you
will have to us e // ins tead of j us t /, the double s las hes
for ces mI RC to evaluate your input, if you us ed a s ingle
s las h, you would get r etur ned j us t $s er ver , ins tead of the
s er ver you cur r ently wer e connected to.
Alias es
As I mentioned in the commands s ection, alias es can be cons ider ed as
s h or t cu t s , and/or as the equivalent of pr ocedu r es , fr om the

command line they ar e typically s hor tcuts , made to gr eatly s implify


your ever yday I RC s es s ion, us ed in a s cr ipt, they ar e als o us ed to
cr eate mor e complex s tr uctur es including multiple commands and
alter nate actions taken, bas ed on what additional par ameter s you
enter /in what kind of window the alias is enter ed, etc.
A s imple alias enter ed on the command line could be like this : /alias
par par t # $1- which would then par t the cur r ent channel, with an
optional mes s age. Much eas ier than typing /par t # channelname
mes s age, now you could j us t type /par [mes s age] to do the s ame : )
Als o, you've got a few channels you j oin often, s uch as # mI RC and
# Chat, better than typing /j oin # mI RC and /j oin # Chat, you could
make two alias es to j oin them, ie /alias j m j oin # mir c and /alias j c j oin
# chat, and you could even make an alias to j oin both; /alias j a { j c |
jm } .
Mor e complex s tr uctur es could be us ed within your s cr ipt, to build a
pr ocedur e you could call fr om many places in your s cr ipt, while only
need to wr ite it once, which would s ave s pace and make the editing of
it much eas ier ..
alias unlock {
if (k is in $chan(# ).mode) {
.s et % key $chan(# ).key
mode # - k % key
}
els e { echo $chan No key s et in # $+ ! }
}
alias lock { mode # + k % key | .uns et % key }
T his is but a s imple ex ample on how you can us e an alias , and while it
does n't r eally s how the mor e advanced us age of alias es , it s hows the
bas ic pr inciples in us ing a multiline alias in your s cr ipt. All this alias
does is enable you to 'uns et' the channel key on a channel (if it's s et),
and then allows you to r es et it at a later point. T his is mor e towar ds
the 'command line alias ' though, than a 'pr ocedur e', but the way you
do it is equal. I f you include your alias es in the main s cr ipt file (and not
in an alias - file of it's own), you pr efix the alias its elf withalias , then
you add the des ir ed commands , if you place the alias es in the alias file,
you s kip the 'alias ' pr efix .
Good s cr ipting pr actice is als o to clean up (r emove) var iables that
haven't got any us e once your s cr ipt finis hes pr oces s ing. T his can be
done with /uns et % var iablename, or automatically by the us e of a
timer , with /s et - u[time in s econds ] % var iablename. I n the ex ample
above, an as good (/better ) s olution would have been to us e .s et

- u300 % key $chan(# ).key, which would uns et the % key var iable after
5 minutes .

I n t r odu ct ion t o P opu ps


Popups ar e the menu's in your s cr ipt. Right click pulldown menu's , and
menu's acces s ible fr om the menubar . You cr eate a popup in much the
s ame for mat as an alias , with a few additional 'tweaks ' to make a
popup look like you want. T he bas ic look of a popup is like this :
T itle/menu option: { commands to r un }

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

Dis connect fr om $s er ver : {


.s et % las ts er v $s er ver
.s et % las tpor t $por t
.quit Leaving
}
Connect to las t - % las ts er v: { .s er ver % las ts er v % las tpor t
}
I n which cas e the s er ver name would s how up in the popup, s o if you
wer e connected to dallas .tx .us .under net.or g, the menu would s how:
Dis connect fr om dallas .tx .us .under net.or g
and the Connect to las t, would likewis e s how the s ame. T he 'connect
to las t' menu option is r ather us eles s though, as this is what happens if
you pr es s the 'connect' button, but...; )
D yn am ic P opu ps :
A final note (for now) on popups ; making dynamic popups enables the
end- us er to only s ee featur es that is r elevant for the us e he will put
them to, and hide ir r elevant featur es . Dynamic popups ar e GOOD. : )
Ok, s o what do I mean ex actly? Well, s omething like this :

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 }

Which would r es ult in a popup that will ONLY s how if you ar e an op in


a channel, AND (becaus e of the &&) the s elected nickname in that
channel is not another op : ) (by us ing the ! pr efix to the condition
ex pr es s ion).

I n t r odu ct ion t o R em ot e E ven t s


Remotes is per haps the mos t ex citing par t of r egular mI RC s cr ipting;
while popups and alias es both r equir e input fr om you, r emotes ar e
r eacting on things entir ely without your inter action. I s n't that
cooooool?? ; ) Remote events can be s plit into 3 main types ; 'regular '
events , r aw events , and ctcp events . A little knowledge of identfier s
and bas ic I RC/mI RC commands , alias es and identifier s will make this
s ection eas ier to under s tand. Als o make s ur e r emotes ar e tur ned on, if
you type /r emote, it s hould s how this :

Remote 1
if it does n't, you can tur n them on by typing/ctcps on, /events on and
/r aw on.

R egu lar even t s :


T his is s hor tly put events that is neither r aw, nor ctcp : ) T his can be an
us er j oining a channel you'r e on, par ting it, s omebody typing s ome
tex t in a channel or quer y window with you, s omebody s ending you a
file, an op, deop, kick or ban event, or a s oundfile being played (by
you or other s ) etc etc etc. T he helpfile has a lis t of all events , together
with ex amples on how to us e them and tips . Events ar e gener ally in
the for mat:
on level: event: command(s )

Level is her e an us er level, by default, all us er s have us er level 1, and


all 'on 1 ' events will tr igger for thes e people, unles s you have
configur ed it not to. Event is the name of the event that s hould be
defined, and command(s ) is /ar e the command(s ) to per for m if an us er
of the r equir ed us er level tr igger s the event defined. S ome events als o
have ways to r eact differ ently depending on wether the event takes
place in a s pecific channel, a s pecific window, etc, s uch as
on level: event: matching: wher e/how: commands
in which cas e the 'matching' par t is r equir ing the event to not only be
tr igger ed by an us er of the cor r ect level, but als o that the matching
ex pr es s ion is filled (the tex t event is a good ex ample of this ). T he
wher e/how par t of the definition s ets r equir ements to in which cas es
input is accepted, for ins tance '# ' which will be fulfilled on any
channel, '# mI RC' which will only be fulfilled if the event is being
tr igger ed in # mI RC, '? ' which will be fulfilled if tr igger ed fr om any
pr ivate mes s age (iow, not in a channel), and '* ' which is fulfilled
r egar dles s of wher e/how the event was tr igger ed.
A cou ple of ex am ples :
on 1: DNS : { if ($r addr es s ) { clipboar d $r addr es s } }
T his event will tr igger whenever you per for m a /dns , be it on a
nickname or on a hos t / an ip addr es s (or r ather , when the dns has
either s ucceeded or failed), and if the addr es s got r es olved, it will copy
this addr es s to the clipboar d, els e it will not do anything. Her e the
level is '1', theeven t is 'DNS ', and thecom m an d is 'clipboar d
$r addr es s ' ($r addr es s is anidentifier holding the r es olved addr es s ).
An ex ample of the s econd kind of event, might be;
on @ 1: T EXT : * s uck* : # : {
kick $chan $nick Pleas e watch your language her e in
$chan
gus er 2 $nick 3
}
on @ 2: KI CK: # : { mode $chan + b $addr es s ($nick,3) }
Okok, I know, this is two events , and I s aid one, but puleeeeaz e, bear
with me? = ). T he @ befor e the level her e, means that it will only
tr igger if you ar e an op on the channel (for mor e info on pr efix es and
s uffix es in events , check the s ection on us er levels ). T he even t is her e
of cour s e 'T EXT ' in the fir s t par t, and 'KI CK' in the s econd par t, and the
m at ch in g is '* s uck* '. T hew h er e/ h ow in this cas e is the '# ' which
means it will tr igger on all channels (again, with the @ befor e the
level, only on the channels you ar e an op), and the com m an ds ar e
the 'kick etc', and the 'gus er 2 $nick'.
What thes e two events do is that whenever an us er type a wor d or
s entence containing 's uck' in it, in a channel wher e you ar e an op, it

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,

and again, on mos t configur ations , level 1 is 'all r egular us er s ', s o


unles s you have s omebody added to your us er lis t, that ctcp won't be
ans wer ed : ). T his ctcp s ends a notice to the nick r eques ting your time,
with your date and time in a tex t for mat, and then the ques tion 'And
you?'. I t will als o s end a ctcp r eques t back to the nick, r eques ting
his /her time.
CT CP events has got this nice thing about them, you can define your
own ctcp's to r es pond to, not j us t the default ones P( I NG, T I ME,
VERS I ON (and s ometimes als o CLI ENT I NFO and FI NGER), and of late;
S OUND), and ex cept fr om r eacting on T EXT and NOT I CE (and s imilar )
events , this is the only way you can s et your own events to r eact to : ).
A s pecial ver s ion of the ctcp event is the CT CPREPLY event, which will
tr igger when an us er r es ponds to a ctcp r eques t you s ent him/her .
CT CPREPLY events ar e of the for mat
on level: CT CPREPLY: match: command(s )
in other wor ds , this is r eally j us t a r egular event of the 2nd type
mentioned above, the only r eas on why I mention it her e is that it is
r eacting on ctcp's .
R AW :
T his is the one kind of events that the helpfile is not cover ing ver y
well, per haps becaus e it is a r ather big 'field' to cover . Raw events is
events that tr igger on mes s ages the s er ver s ends you, for ins tance
when you connect to a s er ver , when you is s ue a /whois , when
s omebody invites you, etc. What makes Raw differ ent fr om r egular
events ? Well, while r egular events ar e mI RC s pecific, and the for mat of
them ar e s pecified by mI RC, Raw events ar e defined in the RFC (z ip'ed
her e) r egar ding I RC networ ks , and the for mat is ver y var iable. Raw
events ar e als o called 'numer ics ', or 'numer ic events ', as they'r e
defined by number s , and you indicate them by number s when
s cr ipting. T he for mat of r aw/numer ic events is
r aw numer ic(number ): filter : command(s )
Wher e r aw is the s ame as 'on', j us t an wor d identifying this as an
event, r aw event in this cas e. N u m er ic is the numer ic to tr igger on,
f i lt er is a r ule for when the numer ic s hould tr igger the commands ,
s ame as the match in on tex t events . Mos t commonly you will want to
us e s ome kind of wildcar d filter , or j us t a ' * ' to catch all events . You
can look up the numer ics in the RFC, or you can us e an alter nate
s our ce, ther e ar e a good number of web bas ed lis ts of the numer ics , as
well as hints on how to us e them etc. One of the better /mor e
convenient s our ces , is Jeeps ter 's numer ic r efer ence, found in both the
r egular web bas ed for mat, as well as in a r egular windows helpfile, you
can find the helpfile her e. An ex ample of a r aw event may be
r aw 433: * : {

echo - a S omebody is alr eady us ing $2 $+ ! Automatic


r etr y? (F3)
halt }
Raw 433 is the numer ic for 'nickname alr eady in us e', in other wor ds ,
when you is s ue a /nick < newnick> command, and the nick is taken,
the s er ver s ends you a 433, and in this cas e, the event will be
tr igger ed. What this ex ample does is to echo to your active s cr een that
s omebody's us ing the des ir ed nick, and then it as ks you wether you
want to automatically r etr y the nick change, until you s ucceed (note
that this mus t then be s cr ipted s o that ther e actually is an alias that
s tar ts when you pr es s F3 = P), then it h alt s the r egular output to the
s cr een (which is ; < nickname> Nickname is alr eady in us e.).
B ut why $2? T he for mat of r aw events is typically (not always ) that $1
is the r eques ter , and $2 is the r eques ted item. I n this cas e, that
means the r eques ted nickname. You s ee the pr oblem? T he for mats of
numer ic r eplies is ver y changeable, s o you will have to lear n the
for mat of the s pecific numer ic event you intend to r eact on/modify,
always . You can us e Jeeps ter 's numer ic par s er s( cr ipt), or a s imilar
(but s lightly mor e advanced) s cr ipt I wr ote to catch the numer ic when
it appear s , or you can us e a mor e s imple method (als o cour tes y of
Jeeps ter ):
r aw * : * : {
echo 12 - s Raw $numer ic $+ :
echo 12 - s 1: $1 2: $2 3: $3 4: $4 5: $5 6: $6 7: $7 8:
$8 and 9+ : $9halt
}
Place that line in your r emotes , and ever y s ingle r aw will be echo'ed in
blue in your s tatus s cr een. T he $numer ic identifier holds the number of
the numer ic event being tr igger ed, in the ex ample above it will be like;
Raw 433:
1: Your nick 2: Newnick 3: Nickname 4: is 5: alr eady 6: in
7: us e 8: and 9+
like this :

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

Fir s t: Par ameter s ar e 'wor ds ', s epar ated by s paces ,


us ually. T his means that in
a line like: I am s leepy, 'I ' would be par ameter one, 'am'
par ameter 2, and
's leepy' par ameter 3. : )

$ 1 : Par ameter one, ie /alias s leepy s ay $1 looks s leepy,


would enable you to
type /s leepy B 0P and you would then s ay 'B 0P looks
s leepy' in the channel.
$2 is par ameter two and s o on. T his is valid for many
cas es , not j us t like her e,
in alias es , but als o in popups and r emotes . I f you s pecify
$1- it means
par ameter one and out, if you s pecify $1- 5 it means
par ameter one thr ough five.
$ $ vs $ . I f you s pecify an identifier with $$ ins tead of $,
this means ; r equir e
the par ameter to be ther e, els e halt. I f you s pecify j us t $,
it means ; us e it
if ex is tent, els e ignor e. For ins tance
/alias mop mode # + oooo $$1 $2 $3 $4
would gener ally allow you to type /mop < nick1> < nick2>
etc to op the given
nicks , in this cas e it would r equir e nick1 to be ther e, if not
it would halt.
I f you had s pecified j us t $1 ins tead of $$1, you could s till
have typed
/mop all by its elf, and the alias would have attempted to
per for m the command,
and you would have r eceived an er r or mes s age. When you
s pecify $$1, it means
that if ther e is no par ameter one, it won't even tr y to do
anything, and
thus r educes the likelihood of pr oblems .

$ ? an d $ $ ?. T he ques tionmar k pops up a dialogue, with


an optional ex plaining
tex t, for ins tance
/alias q quit $?= " Enter your quit mes s age her e
(optionally)"
now you could type /q and it'd pop up the dialog as king
you for your quit
mes s age, and if given it would dis connect you us ing the
quit mes s age, els e
it would j us t quit us ing mI RC's s tandar d quit mes s age.
# $ 1 an d # $ ?. T he # pr efix means that the par ameter
enter ed s hould be pr efix ed
with a # char acter if one is n't given, meaning that an alias
like
/alias j j oin # $$1
would enable you to type /j mir c or /j # mir c alike, to j oin
# mI RC.
$ ! . T his identifier is filled with whatever was typed in a
dialog- box , r ight
befor e the us age of $!. For ins tance in an away alias
/alias a away $$?= " Why ar e you going away?" | ame
is away $!
Now you'd type/a, and a dialog would pop up as king why
you wer e going away,
after which it would s et you away and tell all channels you
wer e away, with
the away mes s age you j us t enter ed. Als o note that s ince
we us ed $$? this alias
would not do anything if you pr es s ed cancel or didn't give
any away mes s age.
T he '|'
is ex plained mor e in the alias s ection, but gener ally
it allows you to
make alias es that per for ms mor e than one command, you
us e a '|'
between each
command to per for m.

$ + . A ver y us eful identifier for the many cas es wher e you


can't dir ectly
type a wor d fully, or wher e you need to put together two
's epar ate' par ts
of a wor d. T his can be for ins tance when you need to add
one or mor e ex tr a
char acter s to an identifier , s uch as
Kick: { .kick # $s nick(# ,1) $?= " Why ar e you kicking
$s nick(# ,1) $+ ?" }
as you can't us e mos t identifier s like $identifier? or
$identifier ' s etc, you
will gener ally us e $+ to achieve this effect. T his will als o be
the cas e if
you want to colour the evaluated identifier , like
ctr l+ k12$identifier , this
will lead to the identifier not being evaluated, you will need
to put s paces
between the colour code and the identifier , like ctr l+ k12 $+
$identifier .
$ & . T his identifier is mor e of an 'acces s or ies ' identifier , it
allows you to
br eak long lines up into s hor ter pieces that will be 'put
together ' when r un,
for ins tance:
s how {
echo - a T his line is long, and what mor e is , it's
VERY VERY $&
long, however , us ing this identifier we can br eak it
up, $&
while mI RC s till will evaluate it as a s ingle, long
line.
}
a ver y s imple, ver y s illy ex ample : ).

B as ic iden t if ier s

T hes e identifier s ar e es s ential to know..: )


$ m e: Your nickname
$ ip: Your ip addr es s (numer ic)
$ ch an : T he channel you'r e cur r ently on (als o, the channel
an event was tr igger ed
on, if us ed in r emotes ). You can als o us e $chan(0) to
r etur n the number of
channel you'r e cur r ently on, or $chan
( number /# ).pr oper ty
(wher e pr oper ty can be
t opic, key, l im it , ial or m ode). $chan(3) will r etur n the
name of the 3r d channel
you j oined, out of your cur r ently j oined channels (of
cour s e, pr ovided you r eally
have j oined mor e than 3 channels = P). $chan(# ).key
r etur ns the key that is s et in
the cur r ent channel (if any, of cour s e), and $chan(2).mode
r etur ns the mode that
is s et on the s econd channel you j oined.
Nex t

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 .

U s age: $ial(mas k,# )[.pr oper ty] wher e mas k is the


addr es s mas k you want to match,
and # is the addr es s number to r etur n. Pr oper ty can be
n ick, u s er , h os t and addr .
I f you s et # t o 0 , it will r etur n the number of t ot al
m at ch es , which you then can
us e in a loop to s how matching addr es s es , for ins tance
(this is us ing the
pr oper ty .nick and .addr , r etur ning the matching us er 's
nick and addr es s ):
alias s canadd {
; s ets the max number of nicks to s can.
s et - u0 % max $ial($$1,0)
: loop
inc - u0 % c
; checks that we ar en't counting mor e than
ther e ar e nicks
if (% c < = % max ) {
echo - a Match nr % c found is
$ial($$1,% c).nick on $ial($$1,% c).addr
goto loop
}
; % c is lar ger than % max ; no mor e nicks to
s can, we'r e done!
els e { echo - a End of s can! }
}
Which will then r etur n the nicks (and their addr es s es )
matching the hos tmas k
you enter (like /s canadd * !* @ * .com) (note that this
ex ample does n't check for
er r or s , s o it would be up to the us er to enter a valid mas k
to s can for ). For
help on the var ious kinds of addr es s mas ks , look up on
$mas k (/help $mas k).
$ n ick: T his identifier can, s imilar to $chan, be us ed alone,
in which cas e it
r efer s to the nickname of a per s on tr igger ing an event, or
it can be us ed with
additional pr oper ties ;
U s age: $nick(# channelname,# /nick). $nick(# ,0 ) will
r etur n the t ot al n u m ber of
nicks on the cur r ent channel, while $nick(# ,2) is the
s econd nickname in the

nickname lis t on the cur r ent channel. As noted, you can


als o us e $nick(# mI RC,0)
or $nick($chan(1),5) to r etur n the total number of nicks on
# mI RC (pr ovided that
you ar e in that channel), or to r etur n the fifth nickname on
the fir s t channel
you j oined. For ins tance, us ed with the titlebar command:
//timer tb 0 5 titlebar Channel count cur r ently
$!nick(# ,0) us er s
which will update the titlebar ever y 5th s econd, s aying how
many people ar e in
the cur r ent channel. Note the us age of $! nick her e, iow;
$!identifier . T his
for ces the identifier to be updated each time it is
per for med
$ as c: I dentifier that r etur ns the as cii number of a given
char acter .
U s age $as c(char acter ), ie $as c(# ) which will r etur n 35,
which is the
as cii number for the char acter # .
$ ch r : T his is the 'oppos ite' of
$as c, it r etur ns the char acter
with the number
you s pecify. U s age $chr (number ), ie $chr (35) will r etur n
# , while $chr (37)
r etur ns % .
$ calc: T his is a calculator = P. T he identifier r etur ns the
r es ult of calculations
you per for m, u s age: $calc(oper ations ). For ins tance, us ed
in a ping r eply:
on 1: CT CPREPLY: * PI NG* : {
.notice $nick You'r e$dur ation($calc($ctime - $2))
lagged.
}

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

; if the us er that got kicked is a us er in your 'pr otect'


; deop kicker and invite the kicked us er back in
mode # - o $nick | invite $knick $chan
}
}

Might be a pos s ible way to us e it.


$ aw ay: T oggles on the bas is of your away s tatus , if you'r e
away, this one
r etur ns $tr ue, if you'r e not, it r etur ns $fals e. S o you could
do
on 1: DCCS ERVER: CHAT : {

halt }

if ($away) { .notice $nick Hey s or r y, I 'm away |


}

halting incoming chat's if you wer e away.


$ cb: Retur ns the clipboar d content (or the fir s t 256
char acter s of it, anyway).
Wor ks together with the /clipboar d command. U s age
$cb(# ), with pr oper ties
.len . $cb(0) r etur ns the total number of lines in clipboar d,
while $cb(0).len
r etur ns the total length of all lines in clipboar d.
$ i if : T his is a cutie. I f you want to make dynamic popups ,
$iif is a good way
to achieve j us t that. U s age: $iif(condition,tr uer es ult,fals e- r es ult(optional)).
S ay you want to make a popup that s hows up only when
you'r e op'ed, and when the
channel you'r e on is not r egis ter ed, you can do s omething
like;
$iif($me is op # && r !is in $chan(# ).mode,Regis ter
channel) { etc }
would make a popup that enabled channel r egis tr ation only
when you could do
it, els e it would hide the popup totally. You don't have to
do the double
compar is ion as above, us ually you'll only have one
condition to be met. Als o
note that while I her e didn't s pecify the 'fals e' s tatement
(to get the on/off
function, you can of cour s e s pecify one, s uch as :
$iif($away,Retur n,Go away) { if ($away) { away }
els e { away $$?= " Why?" } }
which would then s how 'go away' if you wer e not away, or
'r etur n' if you wer e
away : ).

$ ver s ion : T his r etur ns the ver s ion of mI RC you'r e us ing,


you can us e it in the
on load command of your s cr ipt, to ver ify that your tar get
us er will be able to
r un the s cr ipt, ie:
on 1: LOAD: {
if ($ver s ion < 5.5) {
echo - a T his s cr ipt will only r un on mI RC 5.5 or
better , you ar e
echo - a adviced to upgr ade your client, which can
be done at
echo - a $chr (160)
echo - a http: //www.mir c.co.uk
echo - a $chr (160)
echo - a Halting ins tallation due to incor r ect mI RC
ver s ion!
halt
}
els e { blah }
}
T his line will then check the mI RC ver s ion for being lower
than 5.50, if
this is the cas e, it will halt the loading and advice the us er
to upgr ade
his client : ), els e it will pr oceed the loading.

I n t r odu ct ion t o T oken I den t if ier s


by B 0 P @ # H elpD es k
Welcome to this intr oduction to tokens , as us ed in mI RC s cr ipting : )
Many people hes itate to lear n tokens due to the helpfile's s omewhat
lacking ex planation on what tokens actually ar e, however , once you
tr y, you'll find that tokens ar e eas y to lear n and ver y us eful in your
ever yday s cr ipting.
Let's fir s t s tar t with what tokens r eally ar e: T okens ar e " par ts " of a
lar ger whole, be it wor ds in a s entence, par ts of a wor d, par ts of an
addr es s and s o on. Pictur e a piece of land. T his is the " whole" we'r e

talking about. T her e ar e s ever al people owning s maller pieces of land


on this lar ger piece, thes e s maller pieces ar e tokens . T he s maller
pieces of land ar e s epar ated by fences , this is the mys ter ious " C"
char acter , the " thing" that cons titutes the bor der s of the tokens
(r eally; s epar ates the tokens ).
T he mI RC helpfile r efer to tokens and the us e of token identifier s in
the way T E XT , T OK E N , C, N . T EXT is the " whole" that we want to
wor k with, T OKEN is the ex act tex t that is the token, C is the AS CI I
value of the char acter that s epar ates the tokens (s ince a token is a
par t of a lar ger whole, ther e mus t be s omething that indicates what
makes up the par ts ), and N is a number . Confus ed? Don't wor r y, it
gets wor s e ; )

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.

I n t r odu ct ion t o Var iables

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 ..:

Go away: { s et % atime $ctime | ame is away $$?= " Why


ar e you going away?" | .away $! }
Retur n: { ame is back, was away for
$dur ation($calc($ctime - % atime)) | .away }
T hat's a bas icpopup for going away/r etur ning. T he Go away popup
as s igns the var iable % atime to the value of $ctime, then s ends a
mes s age to the channel in the for m of an action (/me) s tating that
you'r e away, and why, then s ets you away with that r eas on. T he
r etur n popup s ets you back, and announces this to the channel. $ctime
- % atime finds the number of s econds you've been away, while
$dur ation conver ts this number to weeks /days /hour s /minutes /s ec's .
Another ex ample, we want to lis t the files in c: \temp, and echo this
into the s tatus window.
alias lis tfiles {
s et - u0 % max $findfile(c: \temp,* .* ,0)
echo - s Lis ting files in c: \temp..
: loop
inc - u0 % c
if (% c < = % max ) { echo - s $findfile(c: \temp,* .* ,% c) |
goto loop }
echo - s Finis hed lis ting files in c: \temp!
}
Her e the var iables % max and % c contr ol the loop, what this alias does
is that it fir s t as s igns % max to the number of files in c: \temp, then it
s ets up a loop that las ts as long as % c is s maller or equal to % max ,
thus lis ting file 1 thr ough % max in the loop. B y us ing the - u0 s witch
with the inc and s et command, we ens ur e that the var iables ar e gone
as s oon as the loop is done with, by far the cleanes t way of making a
s cr ipt.

L ocal var iables


With mI RC 5.6 came a new kind of var iables , local var iables . T hes e
var iables ar e " local" to a s cr iptline and ar e uns et once the s cr ipt
finis hes per for ming, and can only be us ed by the s cr ipt its elf (thus not
called fr om the commandline), much s imilar to local alias es . A local
var iable is as s igned a value with the /var command, and can be
modified us ing /inc and /dec as us ual. T o as s ign a local var iable, us e
/var % var iablename = value.
Var iou s s cr ipt in g is s u es

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 )

T r y for ins tance //echo - a $iif($chan(0) > 0,You'r e on one or mor e


channels ,You'r e not on any channels )$chan(0) will r etur n the number
of channels you'r e on, the if s tatement thus s ays ; if you'r e on one or
mor e channels , then echo " You'r e on one or mor e channels " , els e echo
" You'r e not on any channels " .
As ide fr om tes ting pur pos es , $iif is good for cr eating dynamic popups
becaus e j us t as with r egular I F s tatements , you can omit the ELS E
par t, meaning you can do s omething like this ..: $iif($me is op
$chan,Change topic): { topic $chan $$?= " Enter the new topic in # $+
" } T his popup would only be available when you'r e op'd in a channel,
allowing you to change the topic of the channel. $iif is als o good for
pr oducing mes s ages wher e mos t of the wor ds ar e s imilar , changing
only a wor d or two depending on the us er 's input or other conditions
s uch as channel modes or aways tatus ...
An ot h er ex am ple
alias bdeg {
if ($2 = = c) { r etur n $r ound($calc(($1 * 1.818) + 32),1) }
els eif ($2 = = f) { r etur n $r ound($calc(($1 - 32) * 0.55),1) }
els e { r etur n I nvalid input }
}
T his is a cus tom identifier that conver ts Cels ius degr ees to Fahr enheit,
and vice ver s a. Us age is $bdeg(N,C/F), N is the number of degr ees to
conver t, C means that this number is degr ees Cels ius and s hould be
conver ted to Fahr enheit, wher eas F.... well, you know : )
Looking at line one, the if s tatement ($2 = = c) s ays that I F wor d2 is c,
T HEN r etur n the number in wor d1 fir s t multiplied with 1.818, then
added to 32, then r ounded to 1 decimal. T his will be the degr ees in
Fahr enheit.
Line two s ays ELS E I F wor d2 is f, T HEN r etur n the number in wor d one
s ubs tr acted with 32, then multiplied with 0.55, then r ounded to 1
decimal. With thes e two lines , we've got our s elves functions that can
conver t the temper atur e, the thir d line s ays I F NONE of the above is
tr ue, T HEN r etur n I nvalid input, as an er r or mes s age.
T es t this your s elf, //echo - a $bdeg(32,F) s hould r etur n 0.0,
$bdeg(0,C) s hould r etur n 32.0, and $bdeg(88,F) s hould r etur n 30.8.
Con clu s ion
We've in this little ar ticle gone thr ough one of the mos t impor tant
featur es of any coding, the I F- T HEN- ELS E s tatement, and s een how it
allows us to cr eate code that r eacts conditionally on the envir onment
and the us er 's input. Note that in the cas e of s ingle line if s tatements
or ex ecute s ections , the ( )'s ar ound the I F s tatement and the{ }

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

alias cs tat { s et - u20 % bcs .tar get $active | s et - u20


% bcs .352 1 | .who % bcs .tar get }
r aw 352: * : {
if (% bcs .352) {
haltdef
inc % bcs .total
if (G is in $7) { inc % bcs .gone | s et % bcs .anicks
% bcs .anicks $6 }
if ($chr (64) is in $7) { inc % bcs .ops }
els eif ($chr (43) is in $7) { inc % bcs .voice }
if ($chr (42) is in $7) { inc % bcs .ir cop | s et
% bcs .nicks % bcs .nicks $6 }
inc % bcs .hops $8
}
}
r aw 315: * : {
if (% bcs .352) {
haltdef
var % r egs = $calc(% bcs .total - (% bcs .ops +
% bcs .voice))
echo - ea Channel s tats for % bcs .tar get $+ :
echo - a T otal us er s : % bcs .total
echo - a Away us er s : % bcs .gone ( $+
$r ound($calc((% bcs .gone * 100) / % bcs .total),1) $+
% $+ ) $iif(% bcs .anicks ,- [ % bcs .anicks ] )
echo - a Op's : % bcs .ops ( $+
$r ound($calc((% bcs .ops * 100) / % bcs .total),1) $+ %
$+ )
echo - a Voices : % bcs .voice ( $+
$r ound($calc((% bcs .voice * 100) / % bcs .total),1) $+
% $+ )
echo - a Regular s : % r egs ( $+ $r ound($calc((% r egs
* 100) / % bcs .total),1) $+ % $+ )
echo - a I r cop's : % bcs .ir cop ( $+
$r ound($calc((% bcs .ir cop * 100) / % bcs .total),1) $+
% $+ ) $iif(% bcs .nicks ,- [ % bcs .nicks ] )
echo - a Aver age hops : $r ound($calc(% bcs .hops /
(% bcs .total - 1)),1)
.timer 1 2 uns et % bcs .*
}
}
T his is a pr etty s imple and unfor matted s cr iplet but it s hows you how
you can us e r aw's for pr actical pur pos es . Raw 352 is the r aw for each

/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

make s ur e our s cr ipt is looking neat. For s implicity her e, we will j us t


kick the us er fr om the channel we s pecify if his channels matches any
of the keywor ds we will look for . We will als o wr ite the keywor ds to
match the channels agains t in the code its elf, ins tead of leaving this up
to the us er , this can be modified us ing $r ead or s tor ing keywor ds in an
.ini file or in var iables . Fir s t, let's look at a typical output of r aw 319:
r aw 3 1 9 : * : { ech o -a $ 1 - }
I typed /whois B 0T and got this output back...:
B 0P B 0T @ # mys tr o @ # B 0P's @ # s cr iptech @ # hdtes t @ # HD- Helper s
@ # Kor s far er @ # Mir c_ Res our ces @ # B 0Ptes t
Again, $1 is the nick of the r eques ter (you), $2 is the tar get, B 0T , and
$3- contains the channels the tar get is on.
Us ing this , let's move on to cr eating this kicker .

alias chans can {


if ($active is chan) { s et - u15 % bps .chan $active }
els eif ($2 is chan) { s et - u15 % bps .chan $2 }
; s tor es the channel to kick the us er fr om in a var iable
s et - u15 % bps .319 1
.whois $1
}
r aw 311: * : { if (% bps .319) { haltdef } }
r aw 312: * : { if (% bps .319) { haltdef } }
r aw 317: * : { if (% bps .319) { haltdef } }
r aw 301: * : { if (% bps .319) { haltdef } }
r aw 307: * : { if (% bps .319) { haltdef } }
r aw 313: * : { if (% bps .319) { haltdef } }
; pr events the nor mal output fr om the /whois being s hown
r aw 319: * : {
if (% bps .319) {
haltdef
if (* war ez * is wm $3- ) || (* s ex * is wm $3- ) {
s et - u10 % bps .found 1
; one of the channels the us er is on is containing the wor d
war ez or the wor d s ex
}
}
}
r aw 318: * : {
if (% bps .319) {
haltdef
if (% bps .found) { kick % bps .chan $2 I don't like your
channels ! }
; if the var iable was s et in r aw 319, the us er is in one or mor e
bad channels , kick him.
els e { echo - s $2 was not in any bad channels }
}
.timer 1 5 uns et % bps .*
; this s hould be mor e common in s cr ipts . Clean up var iables after
us e.
}
Now type /chans can B 0P in any channel to kick B 0P fr om that channel
if he's in any channels containing the wor ds " s ex " or " war ez " . T he alias
s ets the channel to kick the us er fr om, and s ets the con t r olvar iable
% bps .319 to us e later in the r aw events , if this var iable is s et, we will

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 : )

Add tex t to the titlebar : /titlebar @ tes t T his is a tes t : )


Remove @ in fr ont of the windowname /window - k @ tes t (can als o be
us ed when opening)
Cr eate an editbox for window /window - e @ tes t (on ly wor ks when
opening window)
Open window on the des ktop (not a par t of mI RC), /window - d @ tes t
Place des ktop window on top of other windows , /window - o @ tes t
Rename a cus tom window, /r enwin @ oldname @ newname [topic]
(topic optional)
Clos e a cus tom window, /window - c @ tes t
Adj u s t in g s iz e an d pos it it on of a cu s t om w in dow
/window [- abcdeEfg[N]hkl[N]nopr s wx ] [- tN,..,N] [+ bdeflLmns tx ]
< @ name> [x y [w h]] [/command] [popup.tx t] [font [s iz e]] is what
the mI RC helpfile s pecifies for the /window command's s yntax . T o
modify s iz e and pos ition of the cus tom window, we'll us e thex y w h
par ameter s = )
X and Y is the window's pos ition in the mI RC main window, 1 1 would
s pecify that you wis h to open the window in the upper left cor ner of
the main mI RC window. B y incr eas ing the s iz es , you'll move the
window fur ther to the r ight and down. W and H is the width and height
of the window, be awar e that s mall s iz es may not give any differ ent
output than no s iz es at all, you may wis h to s pecify s iz es above 50 for
width and height each.
An ex ample
/window - dhlk - t7,23,39,55,71 @ RawCaptur e 1 90 600 200 @ Rc Ar ial
9
T his command will open a window much like the one her e..:

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

out other s elections , s imilar to pr es s ing ctr l when s electing files in


Windows Ex plor er . - h will highlight the window's icon if it's minimiz ed,
us eful for us e in s cr ipting when you wis h to have s ome way of telling
that a window has been modified when minimiz ed. Finally, the - p
s witch will for ce tex t that is added us ing ili n e, alin e or r li n e to be
wr apped to the nex t line, if it's too long to fit the window (other wis e
the tex t will s imply dis appear to the r ight end of the window).
I den t if ier s an d s u ch
I f you wis h to for ins tance s ave the pos ition of a window, to ens ur e
that the window will r eappear in the s ame pos ition and with the s ame
s iz e as when you s aved it las t, you can take advantage of the cus tom
window s pecific identifier s , for this pur pos e, $ w in dow . $window has
s ever al additional pr oper ties , but the bas ic s yntax is
$window(N/@ name). N will be the N'th window, or els e you can s pecify
a windowname to r etur n the pr oper ties for that window in s pecific. You
can us e $window to for ins tance check if a cus tom window ex is ts or
not; $window(@ tes t) will r etur n @ tes t if the window ex is ts , and $null if
it does n't.
You would think that $window(0) would r etur n the number of open
cus tom windows , but actually that will r etur n the number of open
windows (including chats and channels ) in mI RC. T o r etur n the number
of open cus tom windows , we'll take advantage of the ability to s pecify
a wildcar d for the windowname, and us e $window(@ * ,0). You can als o
us e this as $window(@ t* ,0) to r etur n the number of cus tom windows
with a name s tar ting with t open.
Pr oper ties of $window ar e many, and I won't go into detail of all, but
her e's a few of them..:
x ,y,w,h X and y coor dinates of the upper left cor ner of the window,
while w and h is the width and height of the window. Us age would be
$window(@ tes t).x to get the x coor dinate of @ tes t, or
$window(@ bleh).w to get the width of @ bleh.
s tate will r etur n the s tate of the window, can be us ed to ens ur e that a
window opens up ins tead of s taying minimiz ed if s omething s hould
happen that you wis h to make the us er awar e of. s tate will r etur n
either m in im iz ed, m ax im iz ed, n or m al or h idden . S o to activate a
minimiz ed window if s omething happens , you could do if
($window(@ tes t).s tate = = minimiz ed) { window - a @ tes t }
title will r etur n the tex t in the titlebar of a window (ie,
$window(@ tes t).title).
font r etur ns the font us ed in the window, us eful if you wis h to make for
ins tance a s etup dialog that allows the us er to s elect font for your
s cr ipt. Wor ks together with the fonts iz e pr oper ty, which r etur ns the

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 :

/hmake [- s ] < tablename> < N>

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 :

/hfr ee [- s w] < tablename>

T he optional - s s witch wor ks as for /hmake, while the - w s witch (als o


optional) indicates that the name you s pecified in t ablen am e is a
wildcar d and all tables matching this name s hould be r emoved.
P ar t 3 :
Addin g or r em ovin g dat a
T o actually s tor e infor mation in a table, you will us e the / h add
command.
S yntax :

/hadd [- s ] < name> < item> [data]

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 :

/hadd [- s w] < name> < item>

As for the / h f r ee command, the - w s witch is optional and indicates


that the item name s pecified is a wildcar ded name, and all matching
items will be r emoved.
P ar t 4 :
S avin g/ r es t or in g a h as h t able
As mentioned, data s tor ed in a has h table will be deleted when you
s hut down mI RC. T o r etain data acr os s s es s ions , us e the / h s ave
command to s tor e your data to dis k, and / h load to r etr ieve the data
again at a later time.
S yntax :

/hs ave [- s tnoa] < name> < filename>

T he - o and - a s witches (optional) will over wr ite, or append to, the


ex is ting file. T he - b s witch indicates that the data s hould be s tor ed as
a binar y file. When s tor ing as a binar y file, $cr and $lf (car r iage r etur n
& line feed - " enter " ) char acter s ar e r etained in , without this s witch,
thes e char acter s will be s tr ipped fr om the s aved data. Finally, the - n
s witch effectively ignor es the data labels (item names ), and s aves data
with new labels , as s igned numer ically (s tar ting at 1, and incr eas ing).
S yntax :

/hload [- s bn] < name> < filename>

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): {

r emove the has h table fr om memor y.


.timer s eenbkup off
hfr ee b- s een
}

menu s tatus ,channel {


B - s een
.$iif($gr oup(# b- s een) = = off,Enable !s een,Dis able
; A s imple dynamic popup to enable/dis able the public

!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

ON * : LOAD: { hmake b- s een 500 | .timer s eenbkup 0 900


; Cr eate the has h table befor e we can us e it
ON * : S T ART : {
I F (!$hget(b- s een)) { hmake b- s een 500 }
; makes s ur e the table is n't alr eady cr eated befor e we tr y

I F ($is file($s cr iptdir b- s een.htb)) { hload b- s een


$s cr iptdir b- s een.htb }
; this one als o cr eates the has h table, and in addition,
if a pr evious s aved copy was found, it r es tor es it.
}
ON * : EXI T : { hs ave - o b- s een $s cr iptdir b- s een.htb }
; this is the las t line of backup, backs up whenever we ex it

s hould be

ON * : CONNECT : { .timer s eenbkup 0 900 bkup }


; r uns the backup command ever y 15 minutes , which
s ufficient for mos t pur pos es .
ON * : DI S CONNECT : { .timer s eenbkup off }
ON !* : NI CK: { hadd b- s een $nick $ctime new $newnick }
; enables us to tr ack nicks thr ough nick changes
ON !* : JOI N: # : { hadd b- s een $nick $ctime j oin $chan }
; adds us er s j oining a channel we'r e on to the databas e.
ON !* : PART : # : {

var % t = $hfind(b- s een,$nick)


I F (% t) { hadd b- s een % t $ctime par t }
; checks to s ee if the us er par ting had changed nick

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

; this means , tr igger if we did have infor mation about

!s een tar get s tor ed.


var % a = $gettok(% t,2,32), % ts =
$gettok(% t,1,32)
; % a will contain the action that was r egis ter ed in the
events
above (j oin/par t/quit/nick), and % ts is the
times tamp.
I F (% a = = j oin) {
var % t = $2 was las t s een on $as ctime(% ts ,hh: nnt
- mm/dd/yy) $+ , $&
$dur ation($calc($ctime - % ts )) ago, j oining
$gettok(% t,3,32) $+ .
}
; the $as ctime for mats the time the us er j oined
nicely,
/help $as ctime will s how all par ameter s . $dur ation()
calculates the time s ince
the us er was s een, in r eadable time. T he las t par t
r etr ieves the channel that
was j oined.
ELS EI F (% a = = par t) {
I F ($numtok(% t,32) = = 3) {
var % t = $2 was las t s een on
$as ctime(% ts ,hh: nnt - mm/dd/yy) $+ , $&
$dur ation($calc($ctime - % ts )) ago, par ting
$gettok(% t,3,32) $+ .
}
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, par ting
$gettok(% t,3,32) $+ .
}
; the latter tr igger s if the us er was s een under
another nick
befor e, other wis e this event is s imilar to the j oin.
}
ELS EI F (% a = = quit) {
I F ($numtok(% t,32) = = 3) {
var % t = $2 was las t s een on
$as ctime(% ts ,hh: nnt - mm/dd/yy) $&
$+ , $dur ation($calc($ctime - % ts )) ago, s igning
off I RC.

}
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

You can download an uncommented copy of this addon her e.


T his has been an intr oduction to mI RC's newes t s tor age method, the
has h table. Has h tables ar e ver y fas t, can hold lar ge amounts of
infor mation and ar e ver y ver s atile in us e.
I hope you'll be able to s ee how to utiliz e has h tables in your s cr ipting
fr om now on... good luck! : )
bop

S-ar putea să vă placă și