SUNiNET - Your Eggdrop & TCL resources site
[ Home Eggdrop TCL Links About ]

Guide to TCL scripting for Eggdrop 1.6

[ Previous ] [ Index ] [ Next ]
[ Text version ]

6. Outputting information

In this chapter you will learn how to output information.
There are a lot of commands with which you can output information. Some of them are used to send the information to different places and others are used to output the information just in a different way.

6.1 Logging

There are four commands with which you can make Eggdrop log something.
These commands are putlog, putcmdlog, putxferlog and putloglev.
The difference between these commands is that each command sends the log message to a different log level (the various log levels are described in the Eggdrop configfile). Here is a list of the log levels according to eggdrop.complete.conf of Eggdrop 1.6.8:

# Events are logged by certain categories. This way, you can specify
# exactly what kind of events you want sent to various logfiles.
# The most common log file flags are:
#   m  private msgs/ctcps to the bot
#   k  kicks, bans, mode changes on the channel
#   j  joins, parts, netsplits on the channel
#   p  public chatter on the channel
#   s  server connects/disconnects/notices
#   b  information about bot linking and userfile sharing
#   c  commands people use (via msg or dcc)
#   x  file transfers and file-area commands
#      r  (if use-console-r enabled) EVERYTHING sent to the bot by the server
#   o  other: misc info, errors -- IMPORTANT STUFF
#   w  wallops: msgs between IRCops (be sure to set the bot +w in init-server)
# There are others, but you probably shouldn't log them, it'd be rather
# unethical. ;) There are also eight user-defined levels (1-8) which
# are used by Tcl scripts.

The putlog command sends the log message to level o, the putcmdlog command sends the log message to level c, the putxferlog command sends the log message to level x and the putloglev command sends the log message to the level you specify.

The syntax of a putlog, putcmdlog or putxferlog command is putlog "<text>".
The syntax of a putloglev command is putloglev <level(s)> <channel> "<text>".

The <level(s)> is to which log level(s) you want to send the log message.
You can use * to send the log message to all the log levels.

The <channel> is to the log file of which channel you want to send the log message.
Use * to send the log message to the general log.

The <text> is the message you want to log.

The default console modes make masters and owners see all messages sent to the log level o in the partyline.
Because of that putlog is the mostly used log command and you can be pretty sure that the output of it is shown to masters and owners in the partyline which is good because this way you can make your script send out notices of events throughout the partyline for masters and owners.
You can also use this for debugging (finding out where something went wrong). If you place "waypoints" in your script by putting a putlog command every couple of lines in your script that sends a message like "Waypoint X" to the log you can easily see in the partyline where your script goes wrong when it doesn't do something the way you want it do it. Without these "waypoints" it can take a lot longer before you pinpoint the location of the fault.

6.2 Sending output to a user

You can send output to a user on the partyline with the command putdcc.
The standard syntax of a putdcc command is putdcc <idx> "<text>".

The <idx> is to which socket the bot must send the output to.
Every in- and outgoing connection of your bot has a so-called socket number.
Such a connection can be the connection to the IRC server, a linked bot or a user who is on the partyline.
You can see the socket numbers of your bot that are currently in use with the dccstat command in the partyline.
Some binds, like bind dcc, send the socket number of the user who executed the command to the procedure after which you can use that socket number to send information directly to that user alone with the putdcc command.

The <text> is what you want as output.
For example, putdcc $idx "Hello" would send the text "Hello" to the socket number that is in $idx.

6.3 Sending commands to the IRC server

There are three commands with which you can send commands to the IRC server.
These commands are putserv, puthelp and putquick.
All of these commands do exactly the same thing, but they use different queues.
The putquick command uses the fastest queue and is used if you want something to be sent to the server immediantly.
The putserv command uses the normal queue for server messages and is also the command to use when you are sending something to the server that doesn't need to be rushed.
The puthelp command uses the slowest queues and is used to send things like messages and notices to other people, because that usually has a lower priority.

The syntax a putquick, putserv or puthelp command is putserv <text> [options].

The <text> is the command and parameters you want to send to the IRC server.
If you want to send a message to someone or a channel, the syntax would be "PRIVMSG <nickname/channel> :<message>" or if you want to send a notice the syntax would be "NOTICE <nickname/channel> :<message>", where <nickname/channel> is the nickname or channel to which you want to send the message and <message> is the message that you want to send.
For example puthelp "PRIVMSG foo :Hi there." would send the message "Hi there." to the nickname "foo".

The [options] are the parameters for the command. At the moment there is only one parameter and that's -next. This will push your command to the front of the queue that the command uses and thereby sending it faster.

More information about IRC commands can be found in Appendix A.

6.4 Sending commands to other bots

There are two commands with which you can send commands to other bots.
These are putbot and putallbots.
As you might have guessed, putbot will send the command to a specific bot and putallbots will send the command to all the bots that are currently linked.
The syntax of a putbot command is putbot <botnet-nick> <command> and
the syntax of a putallbots command is putallbots <command>.

The <botnet-nick> is the botnet-nick (usually the same as the normal nick) of the bot to which you want to send the command to.

The <command> is the command you want to send and the parameters with it.
The first word is the actual command you want to send and what bind bot will react on and the rest is extra information or parameters that you want to send with it which are placed in the last parameter of the procedure.
Note that here, like with the set command, you have to enclose <command> between quotes.

6.5 Changing channel modes

There are two ways to change channel modes.
These are doing it manually with a putserv command or using the pushmode command which is meant for it and is also faster.
The pushmode command bulks up all the mode changes until the script or procedure has ended and than tries to send as many modes at once to the IRC server (if you've done 3x +o, the bot will make it 1x +ooo if your IRC server allows it).
The syntax of a pushmode command is pushmode <channel> <mode> [parameters].

The <channel> is which channel the mode change must affect.

The <mode> is the mode change you want.
This can be something for the channel itself (like +i or -m) or it can be something towards a user on the channel (like +v or -o).

The [parameters] are the parameters for the mode change.
If you are setting or unsetting a key on the channel for example this would be the key you want to place on or remove from the channel or if you are opping somebody this would be the nickname you want to op.

NOTE: You can only perform ONE mode change per pushmode command.
So using -ooo as <mode> would not work. The bot will do this for you after the script or procedure ends.

6.6 Kicking users from channels

There are two ways to kick somebody off the channel.
These are doing it manually with a putserv command or by using the putkick command which is meant for it.
The syntax of a putkick command is putkick <channel> <nickname(s)> [reason].

The <channel> is from which channel you want to kick the nickname(s).

The <nickname(s)> are the nickname(s) you want to kick.
This can be either one nickname or multiple nicknames seperated by comma's.
How many people you can kick at once depends on your IRC server.

The [reason] is the reason you want the bot to display when the nickname(s) are being kicked.

6.7 Writing your own script

Now it's time to see if you understood it all and are able to use the commands.
Try to write a script that voices everyone who joins a channel and than says "Welcome <nick of the person who joined>!" in the channel.
Good luck.
You can find a small example of such a script here: /tclguide/example-ch6.tcl.
It's not very complicated and it's not the only way to write a script like that, but if you get stuck you can always look at it to see how it can be done.

[ Text version ]
[ Previous ] [ Index ] [ Next ]

Design & Graphics by Shawn Borton
Copyright © 2000-2005 Marijn van Zon