CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

[Library Index]

[View category: Internet Relay Chat] [Discuss Article]

Basic Bot scripting in mIRC

Article Rating: Above Average (# of votes: 1)
Author:      jnewton
Submitted:      23-Sep-2007 10:52:35
 


The absolute basics of mIRC bot scripting.
If you've already done some basic scripting using aliases and so forth, then this article may be too basic for you; this article is for those who like leaping into the deep-end, and provides them with water-wings, as it were. I assume you've downloaded a copy of mIRC; if not, hop over to the mIRC website before continuing on.

To start scripting, you'll want the Scripting window, located, oddly enough, on the /a button on the toolbar or by pressing Alt+R. A bot needs to respond to commands from other clients (meaning REMOTE clients), so you'll also need the "Remote" tab between Popups and Users.

So onto your first bot event, welcoming users, and that is coded like this:
ON *:JOIN:#: {
notice $nick Hey there $nick , you're on $chan of the soandso network!
}
That script may seem a little daunting, so let’s break it down:

ON * means "on the following event, do...". The * after ON is a wildcard that means "when ANY USER does..."

:JOIN:#: is like an if-then statement. JOIN is the event that triggers the script to od what is in the brackets, so in this case, when a user joins a channel, the notice appears. The # means any channel. This can be swapped with any channel name if you want to be specific, but there is a way to tidy that up, which I will come to later.

An important thing ot remember is that all commands MUST be enclosed with { }, or the script will not work. This can be irritating as suddenly all of your code after the missing } will execute, and your bot will go insane! Very embarrassing (don't ask how I know).

notice $nick

This tells the bot to NOTICE the user. A notice is red text accompanied by a beep sound. Try not to /notice entire channels (with $chan), as this tends to annoy people. $nick means only the user will get the notice.

Hey there $nick , you're on $chan of the soandso network!

Remember to leave a space between $nick and $chan in messages, lest the bot be tetchy! See above where I did this: notice $nick Hey there_$nick_, ....

The second $nick in this notice is replaced with the users nickname, and the $chan is replaced with the channel name, e.g.:

jnewton joins #chat

<BOT>: Hey there jnewton, you're on chat of the soandso network!

SAVE AND TEST!

Save your script under something easy to remember, e.g. bot1.ini

Test by opening up a second mIRC client. and UNLOAD your script from the *second* one. Otherwise, when you log in you'll get TWO messages.

In a basic bot script you need only a few events: JOIN, TEXT, and possibly PART.

We've covered JOIN, but what about TEXT?

look at this script:
ON *:TEXT:!joke:#: {
  $read(c:\BOT\joke.txt)
}
TEXT is followed by the text the command is waiting for, so when a user types !joke, the bot will tell a joke!

a new command here is $read. Let's look at how it works:

To get a random joke this is the easiest code, but the work behind it is fairly lengthy: go to your C drive and make a folder BOT, and create a notepad file called joke.txt. Then fill it with jokes, but make sure all the jokes start and finish on the same line! By itself, $read will read a random line from joke.txt, hence why you need the jokes starting and finishing on the same line. $read can be fine tuned to make it less random see the mIRC help file if you want to get more detail on it.

SAVE AND TEST!

Lastly, some simple stuff for when a user leaves or PARTS the channel:
ON *:PART:#: {
msg $chan Bye $nick !
}
Self explanatory really, but the PART part means "when a user parts the channel, do this".

msg $chan: every user does this -- it is the same as when you 'say' something by typing in the text box in a channel.

So when a user leaves:

jnewton left #chat

<BOT>: Bye jnewton!

That is the bare minimum a bot needs, but don't even think about showing this off (yet); most networks demand a LOT of functionality from bot makers, so practice a bit whilst you await the next article: Bot scripting in mIRC: IF, ELSEIF, ELSE and Writing!

This article was originally published in the CyberArmy Library on September 24, 2007. The original can be found here.

You must be logged in to vote on an article

About Us | Privacy Policy | Mission Statement | Help