TCL
|
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. PurposeWe want the bot to say something in the channel whenever anyone else mentions the word chocolate.New Commands Used
The Script
AnalysisThis 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 CommandThe 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 CommandEvery proc command has the following general syntax:proc <procname> { <parameter list> } {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:
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:
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. ExerciseEnter 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):
|
|