Hack 20 Automate mIRC with Scripting (2024)

Hack 20 Automate mIRC with Scripting

Hack 20 Automate mIRC with Scripting (1) Hack 20 Automate mIRC with Scripting (2)

mIRC is already a friendly and easy-to-use IRCclient. Master its scripting capabilities to automate lots of usefultasks.

mIRC is one of the most popular IRCclients available for Windows, and it comes complete with a robustscripting engine. Thousands of ready-to-runscripts are available from sites likehttp://www.mircscripts.org,although it is often hard to find a script that doesexactly what you want, which is why many peopledecide to write their own scripts, or alter existing ones.

4.5.1 Opening the Scripts Editor

mIRC comes with its own integratedscripts editor (Figure 4-12), which can be accessedby pressing Alt-R while the client is active.

Figure 4-12. The mIRC scripts editor
Hack 20 Automate mIRC with Scripting (3)

The five tabs in the scripts editor are Aliases, Popups, Remote,Users, and Variables. Almost all scripts fall into the Remotesection. Remote means that the script can respond to remote events,such as people joining a channel or your connecting to an IRC server.

4.5.2 Making a Bad Word Banner

One of the most common types of script is thebad word banner, which bans orkicks users who say a bad word. To do this, the script must besupplied with a list of bad words, and it must"listen" for these words in channelmessages.

To make the script nice and flexible, you can use a text file tostore the list of bad words. First, you need to make the file, socreate a file called badwords.txt in your mIRCdirectory (for example, c:\ProgramFiles\mIRC\)and place some bad words in it, one per line.If you want, you can also match phrases that contain spaces, as shownin Figure 4-13.

Figure 4-13. The list of bad words
Hack 20 Automate mIRC with Scripting (4)

Save the bad words list and return to mIRC. Now open up the scripteditor (using Alt-R again) and make sure that the Remote tab isselected. Add the following code:

alias matchbad { set %i 1 while (%i <= $lines(badwords.txt)) { if ($read(badwords.txt,%i) isin $1-) { return $true } inc %i } return $false}

This script will return $true if the given phrasematches a bad word, or $false if itdoesn't. The script is explained step-by-step:

4.5.2.1 alias

This tells mIRC that you are creating an alias for a group ofcommands—instead of the main part of the script doing thesecommands over and over again itself, you can group them into analias, which lets us repeat the code contained within it easily. Thealias you have made is called matchbad. The wordimmediately following the alias command is thename given to the alias, which executes all the code contained in theoutermost curly braces ({ ...}). If you are used to other programminglanguages, you can think of an alias as a method or function.

4.5.2.2 set

The setcommand allows us to set a variable so it contains a value. Variablesbegin with the % character in mIRC scripts. Theset command here sets the %ivariable to 1.

4.5.2.3 while

As with other languages, thewhile loop executes a group of commands whilea condition is true. The condition in this case is%i <=$lines(badwords.txt), which roughly translatesinto English as, "while %i isless than or equal to the number of lines inbadwords.txt". $lines is apredefined alias to count the number of lines in a given file.

The code that gets executed while this condition is true is onceagain included in curly braces and is typically indented for clarity.

4.5.2.4 if

The if statement causes a block of code tobe executed only if the condition is true. Theread alias used in this condition reads the givenline from the specified file, line %i frombadwords.txt. The isin operatorchecks to see if one string is a substring of another. So in thisscript, it is essentially checking to see if the text in the lineread from badwords.txt is in$1-.

$1- is a special variable that returns all thearguments passed to the alias, so if a script calls$matchbad(This is,a test), $1-will be set to "This is a test".There are numerous other variables that reference arguments:$1 and $2 get the first andsecond arguments, respectively, while suffixing one of these with a- (for example, $1-,$2-, etc.) gives you that argument and everythingafter it.

4.5.2.5 return

The return function makes the alias return agiven value to the caller. In our example, the value$true is returned if the arguments contain aphrase in badwords.txt and$false if it doesn't.

4.5.2.6 inc

The inc command increases a variable by 1 or byan optional specified amount, for example, inc %foo200.

4.5.3 Putting It All Together

When you put all of this together, you get an alias that scansthrough a text file and checks to see if any of the phrases within itare contained in the arguments passed. If they are, it returns$true; otherwise it returns$false.

The next part of the script listens to channel messages andbans users who say a phrase that isbanned. To do this, use the onTEXTevent, which is triggered whenever mIRC receives a private or channelmessage.

Add the following text to the script using mIRC'seditor. Again, let's examine the code bit-by-bit:

on *:TEXT:*:#:{ if ($matchbad($1-) == $true) { mode $chan +b $address($nick,3) kick $chan $nick Bad phrase detected! }}

4.5.3.1 on TEXT

This event, as mentioned earlier, is triggered on all private orchannel messages. The * before theTEXT means that there are no conditions attachedrelating to you or the user. You can specify user levels here if youwant—see the built-in help system by typing /helpuser list. The * after it is awildcard that matches all text. You could use *e*to match only text with an e in it, for example.The # means that only messages sent to a channelwill be caught.

4.5.3.2 if

The if statement should be familiar fromthe alias created earlier. This particular ifstatement calls the $matchbad alias with the textas a parameter and checks to see if the result equals$true. $1- is the first word ofthe message and everything after that.

4.5.3.3 mode

This is exactly the same as the/mode command you may have used in mIRC orother IRC clients. The $chan variable contains thename of the channel the message was sent to. The$address alias returns part of a givennickname's address (see /help$address), and the $nick variablecontains the user's nickname. The line mode$chan +b $address($nick,3) will place a ban on theuser's host.

4.5.3.4 kick

The kick command kicks a given user from thespecified channel (with an optional Kick message).This example kicks the user from the channel, with the reason,"Bad phrase detected!" If you want,you can change this to something more fitting.

4.5.4 Running the Hack

Put both the alias and the onTEXT event into your Remote section usingthe mIRC script editor, and create abadwords.txt file with a few banned phrases in.Now try it out! Note that the on TEXT event willnot trigger when you say something, so you will need to use anotherclient or get a friend to help you test the script. Anybody caughtsaying words on the bad word list will be kick-banned from thechannel.

Further information about scripting can be found in the mIRC helpsystem. This is extremely detailed. Simply type/help from mIRC (or press F1) to viewit.

—Chris Smith

    Hack 20 Automate mIRC with Scripting (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Twana Towne Ret

    Last Updated:

    Views: 6015

    Rating: 4.3 / 5 (64 voted)

    Reviews: 87% of readers found this page helpful

    Author information

    Name: Twana Towne Ret

    Birthday: 1994-03-19

    Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

    Phone: +5958753152963

    Job: National Specialist

    Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

    Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.