A TCL script is created as an ordinary text file. Hence, appropriate programs to use in editing such a script would include Notepad (in Windows) and pico (in Linux).
The main eggdrop configuration file (usually named eggdrop.conf) is an example of a TCL script. Indeed, that file must be edited in order to add any other scripts to a bot. Let's take a look at how that is done:
source testing.tcl
That's all there is to it. When the bot is started up in the shell, the main configuration file will do whatever it normally did, and it will also load and execute the script named testing.tcl.
It is quite likely that the main configuration file already has several statements in it that begin with the word source. Naturally, they also load and run scripts. It is even possible to have a script that is loaded this way to contain source commands of its own, which will in turn load still more scripts.
set horrible 42In that example, there are four commands in the script: two set commands, a putlog command, and a source command. Notice that:
set wonderful 16
putlog "I set the variable horrible to $horrible"
source horrible.tcl
set horrible 42; set wonderful 16That example has five commands: two set commands, a putlog command, a # command, and a source command, with 2, 2, 1, 5, and 1 arguments, respectively.
putlog "I set the variable horrible to $horrible"; # record in the log file
source horrible.tcl
bind pubm - moron saidmoronIn that example, there are two commands, namely bind and proc. The bind has four arguments, whereas the proc has only three. Notice how braces {} have been used to group five things together into the second argument of the proc command, and braces have been used again to group together a lot of things into the third argument. Moreover, the opening brace of that third argument ends the first line of the proc command. Now, the proc command expects its thrid argument to be a bunch of TCL commands -- essentially a whole TCL script. Let's look again at that third argument:
proc saidmoron { nick host handle chan text} {
if { $nick == "Pulse" } {
puthelp "PRIVMSG $chan :Pulse is the idiot."
} else {
puthelp "PRIVMSG $chan :Be nice, $nick"
}
}
if { $nick == "Pulse" } {This third argument turns out in this case to consist of ONE command, namely an if command. That command has four arguments, of which only the thrid, namely else, is not enclosed in braces.
puthelp "PRIVMSG $chan :Pulse is the idiot."
} else {
puthelp "PRIVMSG $chan :Be nice, $nick"
}
if { $nick == "Pulse" } {Doing it that way, we no longer have one if command with four arguments. Instead, we would have one if command with two arguments, and one else command with one argument. Since there is no such thing as an else command in TCL, that last version would produce an error, and the script would not work.
puthelp "PRIVMSG $chan :Pulse is the idiot."
} else {
puthelp "PRIVMSG $chan :Be nice, $nick"
}
| set approvalfile "~/txt/approval.txt" |
| # maintaining the database |
| bind pub m|j approve approvaledit |
| bind msg m|j approve approvaleditmsg |
| proc approvaleditmsg { nick host handle text } { |
| approvaledit $nick $host $handle "none" $text |
| } |
| proc approvaledit { nick host handle chan text } { |
| global approvalfile |
| if { $text == "" } { |
| puthelp "NOTICE $nick :Syntax: approve <information>" |
| return 0 |
| } |
| set fp [open $approvalfile a] |
| puts $fp $text |
| close $fp |
| puthelp "NOTICE $nick :Added \002$text\002 to the database" |
| return 0 |
| } |
| bind pub f approval approval |
| proc approval { nick host handle chan text } { |
| global approvalfile |
| searchfile 1 $nick $chan $approvalfile $text |
| } |
| putlog "Loaded approval Version 1.1, by terri{N}, for BotService" |