Saturday, December 09, 2006

mIRC Scripting

IRC (Internet Relay Chat) is a great medium for sharing ideas and collaborating with peers. Its one of the oldest forms of chat over the Internet (1988) and came before AIM, MSN, or even ICQ was even conceived. Since its so old, there are many programs (clients) out there for using the IRC networks. A few examples are listed below:
  1. BitchX (*nix)
  2. XChat (multiplatform)
  3. Ircle (MacOS)
  4. mIRC (Windows, *nix under wine)
I personally use mIRC partly because its what I started with (somethings I have a hard time changing) and also because its stable and just plain works. The real power of any IRC client is the ability to support scripting in one fashion or another. mIRC has implemented their own scripting language that shares some similarities to javascript however in many ways the syntax is quite frustrating. There are also lots of wierd limitations especially in variable sizes. I suppose one could argue that its just a scripting language and real programs should be implemented as plugins written in C++ or the like. Anyways, you can read more about mIRC scripting [here].

Often there is a need to perform administrative functions within an IRC channel such as changing users' status, adding bans, or kicking users. Normally, you would accomplish this with certian commands sent to the IRC server, however, some tasks are quite repetitive. For example, what if you want to op someone whenever they joined the channel. Well, there are two ways to accomplish this: first is with the built-in auto op list in mIRC, or second, is scripting. We will take a look at an example using the latter.

on *:JOIN:#electronic-mp3: {
%autoAwpList = *!~hi@cpe-75-180-172-215.indy.res.rr.com,*!Deviant@dynamic-216-211-49-42.tbaytel.net
if ($nick == $me) { halt }
if ($me isop $chan) {
if ($address($nick, 0) isin %autoAwpList) {
mode $chan +o $nick
}
}
}

All relatively simple. First we need to define the specifics of the event. For any user (on *), when a user joins a channel (JOIN), called #electronic-mp3 (self explanatory), do the following. First, we define a comma seperated list of hostmasks to match. Second, we want to ensure that we don't try opping ourselves. Then we need to ensure that we have the appropriate operator privileges. Next we check if the hostmask of the user that just joined exists in the variable %autoAwpList and if so, run the next line that ops them.

We also could have done this with an user access list but that is a touch more complicated but would be the preferred method if you had a lot of users that you always wanted to op. In addition you probably noticed my curly brace syntax. mIRC syntax seems to demand that you use the opening brace has to be on the same line as the block definition or conditional. I hate that rule but then again, mIRC is not a true programming language.

No comments: