Beginner's Guide to IRC Scripting and Botmaking

Ever been blown away by a ping-script, or a bot that tells jokes? The first time I saw a funbot, I just thought, "Wow, these guys are good...". And yes, some to most of them are good, either in one specific area or overall. All it takes to go from a newbie to a Scripter is a combination of will, patience, practice, and help (from users, sites, manuals, etc...). The four major parts of scripting are:

  • Aliases
  • Popups
  • Remotes (we'll do this one last)
  • Variables

Now that we know what we'll be learning, let's start, shall we?

Aliases:

Aliases are, imo, the most useful skill to learn (at first, anyway...). They can save alot of time when you need it. Let's start with something simple. Ever just get pissed from those "please identify your nick" messages? I do too! Let's do something about that right now. This will not only save time, but will conceal your password from prying eyes. Open up your aliases (Alt-A, or click the Aliases button on your main screen (Note: I'm using mIRC for this. To get it, go here.)) and put this in the text field, on a new line:

/id /msg nickserv identify mypass (Where mypass is your NickServ password.)  

Did you follow that one? The first word on a line in aliases is always treated as a new command. Anything after that is what the command does. So, /id is the new command, and /msg nickserv identify mypass is what it does. You've just taken your first steps towards becoming a scripter.

Pretty cool, huh?

Popups:

Let me state right here that popups are not my specialty, as I've just now started on them myself. Popup menu definitions use the format:

menu item:commands, so Help Me!:/join #help would take you to #help the same as if you had typed /join #help. To start a menu, put whatver you want the menu to say at the top of the page. This is the easiest, you can rearrange it later as you please. To create a submenu, use a "." fullstop. To make more submenus, use "..", "...", etc until you get it how you want it. So, a channel list would look something like this(yes, you can find most of this stuff in the manual):

Channels

Help

irchelp:/join #irchelp

mIRC:/join #mirc

helpdesk:/join #helpdesk

Other Channels

Visit #cyberarmy:/join #cyberarmy

Say hi to bluesoul88:/join #7357

.Join?:/join #$$?="Enter a channel name:"

Most of that is pretty straightforward, but the last on might have you scratching your head, so let me explain. When you put $$?="something" in your popup, a small textfied will *gasp* POP UP. So:
.Join?:/join #$$?="Enter a channel name:" would show a textfield, with 'Enter a channel name:' above it. Remember, when you use this, don't put the # before the channelname (#$$? took care of it). To create a menu all by itself, use a "-" on a line by itself. The result is a thin grey line separating two menus. The best way to learn your popups is just to mess around with them, and check your menus frequently.

Variables:

Variables are what keeps your mIRC running. When it says not to delete the variables, listen to them, unless you'd rather reinstall mIRC. All variables start with the % prefix. Variables cannot be used by themselves. Rather, they link all your scripts together through them. You can set a variable from any window. Simply type in /set %variable commands. You unset the variables in the same way, but with no commands, simply /unset %variable. You can use /unsetall to remove all variables, but I really wouldn't. If you try to use a variable that doesn't exist, it returns the value $null(we'll get into the $ identifiers later on). Try making a variable called %ping.reply.time.chan with a value of # (we'll need this later on in the next file.) did it look like this in your variables?:

%ping.reply.time.chan #

If so, congrats! Move on... :) Variables are one of those things you pick up as you go.

Remotes:

I think everyone will agree with me that remotes are the most difficult scripts to write and test. But if you stay with it, you'll get it before long. On irc.cyberarmy.com, you have ChanServ in the room, and you can just say !op, !kick, etc. Well, let me tell you something...

Almost all major IRC networks don't.

This means that, to create a "ChanServ" style bot, you will have to:

  1. Either create or get ops in a channel

  2. Get a list of commands

  3. Make it yourself :(

Fear not, once you understand how they work, building a bot is easy. I always use the !prefix for commands, but you can use a . for an eggdrop-type feel, or anything you want. You're the botmaker. Let's study a BASIC"!op" script:

on 1:TEXT:!op:#:/mode $chan +o $nick  

No, come back! No--stop running away! It isn't that hard. Lets study it:

on 1:TEXT:!op:#:/mode $chan +o $nick
The "on 1" means, basically, "for anyone level 1 or higher". Right now, anyone who says !op will get ops, as 1 is the standard level in channels.

on 1:**TEXT:**!op:#:/mode $chan +o $nick  

It's fairly easy to figure this one out. When someone TYPES the command in the channel, it'll trigger. Beware though, an on TEXT remote will not execute for that particular IRC client. That's why most people that can't maintain a shell has two clients running, the bot and the user. Somewhere around 3/4 of the remotes you will write will be on TEXT. There are many, many, MANY different things that will go where TEXT is right now, type /help on in any window to see a list of them all.

on 1:TEXT:**!op**:#:/mode $chan +o $nick  

This is what the command will be. Need help with a list of ChanServ commands?

!op
!deop
!voice
!devoice
!kick
!ban
!kickban

Be creative, come up with your own. The limits of the script lies only in the hands of the scripter.

That's you right now.

on 1:TEXT:!op:**#:**/mode $chan +o $nick  

This means that it will only respond when the command is typed in a channel. Use ? for only on private messages, and * to execute in any window.

on 1:TEXT:!op:#:**/mode $chan +o $nick**  

This is where the command goes. This will end up growing more and more exotic as your knowledge grows. Congratulations, you worked your way through a remote! Now, let's build on it:

on 1:TEXT:!op**\***:#:**if ($2 == me | $2 == $null) { /mode $chan +o $nick } else { /mode $chan +o $2 }**  

Now it's getting a little more convenient. If someone types !op or !op me, the bot will op them, Now, if they say !op OtherNick, where OtherNick is someone else in the room, the bot will op OtherNick. See how that went? Alright, let's try something else. Ever wondered how a bot always msg'd you when you entered their chan? It's one of the easiest scripts to write:

on \*:JOIN:#mychan:/msg $chan Hi $nick, welcome to $chan!!  

Now, when someone enters the chan, you notice this doesn't work....

Do you see why?
The $chan!! and $nick,throws it off, because it treats them as identifiers other than $chan and $nick. So...:

on \*:JOIN:#mychan:/msg $chan Hi **$nick ,** welcome to **$chan !!**  

Now, when you join, my bot would do this:

bluebot88>>Hi bluesoul88 , welcome to #mychan !!  

To me, this is just ugly, you can tell it's a bot. So, we'll use a new identifier. This one is $+, and it ties two objects together. Let's put it in the script, and see what it does...:

on \*:JOIN:#mychan:/msg $chan Hi $nick **$+** , welcome to $chan **$+** !!  

Now, when i use this...:

bluebot88>>Hi bluesoul88, welcome to #mychan!!  

Yay! Now, that was just a bare-bones Join script, feel free to spice it up (bold, underline, colors, etc.)

We'll work more with remotes in the next file.

THE USERLIST:

The userlist in your bot's configuration will quickly grow to be a top priority. If you keep every remote as on 1, everyone can execute them, but if you, say, put a voice at 10, halfop at 50, ops at 100, full control at 1000, etc, etc. ..you get my point. So, go to Users in your bot's settings, it will most likely be empty. A userlist will look like this:

10:voicerdude  
10:igotavoice  
50:halfopsare1337  
50:mr\_halfop  
100:iamopped  
100:no\`ops\`for\`j00  
1000:theprez  
1000:mybestfriend  
1001:bluesoul88  

Yes, I have extra controls that nobody else needs, like inviting ppl to my chan, turning the bot off, etc. To add someone to your userlist, you can either do it manually, in the above style (level:nick), or type, in any window, /auser level nick. To remove someone, type /ruser nick. NOTE, auser will only add their nick, so if they change nicks often, be sure to include all of them. Oh, it can get annoying REAL fast, switching clients and adding a user, so i wrote a neat little remote:

on 1001:TEXT:!add\*:\*:/auser $2 $3  

Now you HAVE to do it in the write order, level then nick, like !add 1000 mybestfriend. Build 2 more remotes, one to remove someone, one to give someone level 0 access, they're both used alot by me.

IDENTIFIERS:

I told you we'd get around to 'em. An identifier is something that...identifies a variable in a script. Here are some common ones:

$me - used when you want the bot to do something to itself, or to 'introduce' itself.
$nick - wide range of uses. $nick is whoever triggered script.
$chan - channel in which script was triggered
$2, $3, etc - second, third, etc word in command (ex. !kick loser scans for a $2, find that $2 = loser, and kicks it)
$null - when referring to a variable that doesn't exist, or when there is no additional words (ex. if $2 = $null, op $nick)
$$? - used in popups to create options

Well, thats about all a beginner needs to know. In the next file, I'll go more in-depth on certain scripts (auto-ping, nick completer, etc.). I can not stress this enough, do not get discouraged!. This is complex stuff, and diving in head first is tough. So, spend some time reading your mIRC manual (esp. If-then-else statements and Identifiers, we'll be using both next), and see what you can do.

Good luck,

--bluesoul88