Site Meter
[Applications]   [Classes]   [Commands]   [Downloads]   [Egghelp]   [Features]   [Help]   [Information]   [Links]   [News]   [Policies]   [Staff]

Setting up an Eggdrop

Setting up a Botnet

1. TCL in General
2. Project: Talk Back

Lesson 2
Project: Talk Back

This first project is intended as a means of starting to learn some TCL, and is not really, in itself, a very important script.


We want the bot to say something in the channel whenever anyone else mentions the word chocolate.

New Commands Used

  • bind
  • proc
  • puthelp

The Script

bind pubm - choc said_choc
proc said_choc { nick host handle chan text } {
    puthelp "PRIVMSG $chan :MmMmm ... chocolate!"


This script conists of a bind command and a proc command, and this is a very typical combination of commands in most eggdrop TCL scripts. The purpose of the bind command is to tell the bot to monitor what is going on, and, each time certain conditions are met, to 'run' a particular procedure.

The bind Command

The general syntax of the bind command is:
bind <type> <flags> <trigger> <procname>
In this script, the type is pubm. This type of bind causes the bot to monitor what is said in the channel, looking for any occurences of the trigger, which in this script is choc. The flags in this bind are - which is used to indicate that it doesn't matter to the bot who actually says the trigger, i.e. anyone can trigger it. Notice that the procname in the bind is said_choc.

Thus, this bind command tells the bot to monitor what is said in the channel, and each time anyone (no matter what flags they have with the bot) says 'choc', the bot will execute the proc named said_choc. Thus, for example, if Jane says "i luv choclits', the bot will execute the proc said_choc.

The proc Command

Every proc command has the following general syntax:
proc <procname> { <parameter list> } {
    <various TCL commands>
In this case, the procname is given as said_choc, so that it is the name mentioned in the bind. Now we need to look at the parameter list.

Note that the parameter list is always enclosed in braces.

In any proc, the parameter list is simply a list of variables, separated from one another by at least one space. The proc expects to be called, with the caller supplying values to the variables in that list. In particular, when a bind of type pubm is triggered, it calls the proc and supplies it with values of exactly five variables. (Thus, our proc must have five variables in its parameter list, whether we plan to make use of them or not.) Here are the values assigned by the bind:

  1. it stores the nickname of the person who triggered the bind, in the first variable of the parameter list; this is why we chose nick as the name of that variable, although we could just as legally have chosen any name.
  2. in the second variable, the bind stores the hostmask of the person who triggered the bind, in the form user@host; again, our choice of variable name seems appropriate
  3. in the third variable, the bind stores the name that the user has when he/she is in dcc with the bot; i.e. the handle the user has with the bot; often, of course, this value is identical to that of the first variable
  4. in the fourth variable, the bind stores the name of the channel in which the bind was triggered
  5. finally, in the last variable, the bind stores the entire statement that the user typed, that triggered the bind.
These variables can be used by the TCL commands that are contained in the third paramter of the proc. Notice the distinction between nick (which is a variable) and $nick (which is the value of that variable).

Finally, we come to the last parameter in our proc command. In this script, it consists of only one command, a puthelp command. Since that command has probably scrolled off the top of your screen by now, let's redisplay it here:

puthelp "PRIVMSG $chan :MmMmm ... chocolate!"
Notice that the puthelp command takes exactly one argument, and that that argument is a string --- in our case, an explicit string, as indicated by the quotation marks enclosing it. What this TCL command does, is twofold:
  1. it scans the string for values to be calculated, such as $chan, and makes the appropriate replacements in the string
  2. it sends the resulting evaluated string to the server
As a result, what the server actually does with the string depends on whether it represents a command that the server understands. Hence, that string must be a valid server command. (Eggdrop TCL coders will thus do a much better job if they have a good knowledge of irc server commands -- which are not TCL at all.) In this case, we have used the server PRIVMSG command, whose general syntax is:
PRIVMSG <target> :<message>
Note the colon in front of the message. In our case, the target is the channel where the person who triggered the bind, spoke. The name of that channel was stored by the bind in the parameter list in the variable we chose to call chan.


Enter the script from this lesson into a txt file, giving the file an appropriate name, and add it to your bot using the appropriate source command in the bot's main configuration file. Run the bot, and in the channel where you sent it, try saying some things in the channel, some of which include choc. Get others to say such things, too. Once you have it working, try making these changes to the script (and rehashing the bot, and saying experimental things in the channel, each time):
  • Change the actual message that the bot comes back with in the channel
  • In the puthelp command, change $chan to $nick and notice the effect that has
  • In the puthelp command, change PRIVMSG $chan to NOTICE $nick and notice the effect that that has
  • Change the third argument in the bind command, so that the bot reacts to candy instead of to choc
  • Add a second puthelp command in the third argument of the proc, so that the bot responds by saying two things in the channel, instead of just one.

©1998 - 2005 BotService