IRC for Coders

IRC Raw Numerics

last updated: Thursday, 28 April 2022 473 _Yeti_ #mIRC :Sorry, cannot join channel.

The first section is the server that is replying to you. This can come in handy, as you will sometimes receive a reply from a server your not on. The next portion, 473, is the actual numeric. The message the server sends us tells us we can't get into the channel, but why? 473 is the reply for "Channel is invite only". There are other similar error codes, such as 471 for "Channel is full", or 474 for "You're banned"

The rest of the string will contain information pertaining to the reply. The rest of the string in the above example is telling us what channel we tried to join that was invite only.

Raw Events

raw :matchtext: { commands }

In the example above, we could echo that error by doing this:

raw 473:*: echo -a I tried to join $2 but its invite only! | halt

To fully understand how to use raw events, you must first understand the parameters. You use $1, $2, $3, etc, just like you do in an alias. $1 would be the first 'word' in the servers reply, $2 would be the second, and $1- would be the full reply. One thing to note is that EVERY reply from the server will always contain your nickname, so $1 is always your nickname.

On other thing to note is that you must use the /halt command if you don't want mIRC to print out its normal text in relation to a raw event. I've added the halt command on my example so that only my message is displays, and mIRC hides its own standard error reply.

A very useful technique for learning raw events is to add this to your remote section:

raw *:*: echo -s $numeric $1-

This will trigger any time a raw event goes off, and will print out all the information to your status window for you to study. If you plan to customize the way mIRC looks, this will also let you catch any of the raw events that you didn't script for. One other magic identifier that you can use in raw events is $nick, which will tell you the server that sent the reply.

Before we get into some full fledged examples, you may want to start by downloading the Numeric Help File. This will detail all of the codes that are out there, so you can look it over to see what your capable of doing with raw. The information there is designed primary for the EFnet network, and has not been updated for a while. If you normally use another network, or are trying to take advantage of new server features, you may not find the information in the help.

Whois Example

raw *:*: echo -s $numeric $1- | halt

Now, whois yourself. You should get a display similar to this in your status window:

311 Yeti`` _Yeti_ yeti * Sasquatch
319 Yeti`` _Yeti_ @#Yeti @#mIRC
312 Yeti`` _Yeti_ The Marklar for Marklars on Marklar.
317 Yeti`` _Yeti_ 529 955689355 seconds idle, signon time
318 Yeti`` _Yeti_ End of /WHOIS list.

I get 5 separate replies from my /whois. Some may not be present at all times. For instance, if I part all channels, raw 319 will not trigger. If the server doesn't care to share my idle time, raw 317 would be missing. If I suddenly became an IRC oper, raw 313 would show up.

We'll start with the first line. it tells me that my hostname and real name are contained in raw 311. As I mentioned, $1 is the first word, and is ALWAYS your nickname. As you can see, i used a second client to /whois the first one. $2 in this example would be _Yeti_, as was the target of the whois. $3 contains my ident, yeti. $4 is my hostname. That * is a 'word' by itself, so $5 would contain a single *. $6 and on would be whatever was in my real name field. The get it all, you would use $6-

You may have noticed that this is slightly different from way mIRC would print out whois information. For instance, you get in a regular whois. Your script would have to do a bit of work here to combine the ident and the host. If you wanted to customize this info, you could do something like this:

raw 311:*: { echo -a Whois Info for $2 - Hostname: $3 $+ @ $+ $4 - RealName: $6- | halt }

You can do whatever you want with the information contained in raw events. I could store the information in variables, write it to a file, or just stop it from printing completely. You can add colors to the echoes, flip and bend it however you want basically.

I'll skip to the idle information now, as the way the server send it may seem rather odd. The first number there, 529, is the number of seconds idle. You can use $duration to convert this to something readable. The second number is a timestamp of when I logged on. That can also be converted to something more readable with $asctime. Heres an example:

raw 317:*: { echo -a $2 logged on $asctime($4) and has been idle for $duration($2) | halt }

In my case, it would print out:

Yeti_ logged on Fri Apr 14 00:15:55 2000 and has been idle for 8mins 49secs

raw 318 is somewhat common among many events as well. This is just the server telling you its done sending information. For instance, when you join a channel, the servers send you all the users nicknames. When its done, it send an extra raw to say "Thats everyone, I'm done now". You can use this is a way to ensure that you have received all the information you need.

Banlist Example

367 Yeti`` #Yeti *!*@* _Yeti_! 955710688
367 Yeti`` #Yeti *!*@* _Yeti_! 955710688
367 Yeti`` #Yeti *!*@* _Yeti_! 955710688
368 Yeti`` #Yeti End of Channel Ban List

In this example, you see that the server sends multiple replies for the same number. Many events will do this, like /who, /names, etc. There is also an extra event indicating that the list is complete.

Again, $1 is going to be your current nickname. $2 is going to be the channel that you requested the list for. $3 is the hostname that is currently banned. $4 tells you who set the ban, and $5 contains a timestamp of when it was set. You can use $asctime again to convert this to something readable.

A simple way to clear all the bans would be to do this:

raw 367:*: mode $2 -b $3

As the information on each ban was received, you could grab the hostname and remove the ban. However, if there are 10 or 15 bans, this can get quite messy! Here's a more complicated version that would allow you to do 4 at a time.

raw 367:*: {
%bans = $addtok(%bans,$3,32)
if ($numtok(%bans,32) == 4) { mode $2 -bbbb %bans | unset %bans }
raw 368: { if (%bans) mode $2 - $+ $str(b,$numtok(%bans,32) %bans | unset %bans | halt }

So.. how does it work? As we receive each ban, we are adding the hostname to a variable called %bans. After we add the host, we see how many we have stored. If there are 4, we clear out 4 at once, then delete the variable. The next time around, we have an empty variable and try and add 4 more again.

In case you have an odd number of bans, we also have to check one last time as the ban list is finished. Since we only wipe bans every time we get 4, the above script would never unset them if there were only 3 bans. Once the server tells us that we have the ban list, we verify if %bans exists. if it does, we still have one last batch to get rid of. To avoid errors from the server, I used $str to repeat the b enough times to cover each unban. We could specify -bbbb, but the server might complain if you tell it your going to do 4 unbans and then only specify one hostname. The last thing we do is unset out %bans variable, and we're done!

000 series