Aliases
As I mentioned in the commands
section, aliases can be considered as shortcuts, and/or as the equivalent of
procedures, from the command line they are typically shortcuts, made to greatly
simplify your everyday
IRC session, used in a script, they are also used to create more complex
structures including multiple
commands and alternate actions taken, based on what additional parameters you
enter/in what kind of
window the alias is entered, etc.
A simple alias entered on the command line could be
like this: /alias par
part # $1- which would then part
the current channel, with an optional message. Much easier than typing /part
#channelname message, now
you could just type /par [message]
to do the same :) Also, you've got a few channels you join often, such as
#Kuwait2 and #Q8scripting, better than typing /join
#Kuwait2 and /join
#Q8scripting, you could make two aliases to join
them, ie /alias jk
join #Kuwait2 and /alias
jq join #Q8scripting,
and you could even make an alias to join both; /alias
ja
{ jc |
jm }.
More complex structures could be used within your
script, to build a procedure you could call from many
places in your script, while only need to write it once, which would save space
and make the editing of it
much easier..
alias
unlock {
if
(k isin $chan(#).mode) {
.set
%key $chan(#).key
mode
# -k %key
}
else
{ echo $chan No key set in # $+ ! }
}
alias
lock { mode # +k %key
| .unset %key }
This is but a simple example on how you can use an alias,
and while it doesn't really show the more
advanced usage of aliases, it shows the basic principles in using a multiline
alias in your script. All this alias
does is enable you to 'unset' the channel key on a channel (if it's set), and
then allows you to reset it at a
later point. This is more towards the 'command line alias' though, than a
'procedure', but the way you do it
is equal. If you include your aliases in the main script file (and not in an
alias-file of it's own), you prefix the
alias itself with alias,
then you add the desired commands, if you place the aliases in the alias file,
you skip
the 'alias' prefix.
Good scripting practice is also to clean up (remove)
variables that haven't got any use once your script
finishes processing. This can be done with /unset
%variablename, or
automatically by the use of a timer,
with /set -u[time in seconds]
%variablename. In the
example above, an as good (/better) solution would
have been to use .set -u300 %key $chan(#).key,
which would unset the %key variable after 5 minutes.