Main      Site Guide    

RookChat is an open-source HTTP/CGI-based chat room that webmasters may download and install on their web sites. It features dynamic multi-room capabilities, public/private/moderated rooms, multi-lingual support by user, many administrative levels, memos, memo lists (similar to mailing lists), graphical smileys, bot games, and over 75 commands for chatting and administration. RookChat requires a UNIX or Windows NT/2000/XP with Python 2.1 or greater.

Do You Want To Make Modifications to RookChat?

Are you interested in writing new features or bots for RookChat? Because RookChat is open-source, including the bots, those who are interested in mucking about with the code may certainly do so. RookChat is released under the GNU Public License. If you have any questions about what this license permits or prohibits you to do with the program, visit the GNU Public License FAQ. In a nutshell, you can make modifications to the software, but if you make the program available to anyone, you must also distribute (freely) the source code of the modified version under the GNU Public License. This modified version must have your name on it, to distinguish it from the "official" distribution of RookChat, while preserving the copyright notices from the original code.

Should you make a modification to RookChat, whether a simple bug fix or a new command or bot or whatever, it is also requested that you make the modification available to me. I may want to include your new feature in the main distribution or link to it from a mods page (as yet forthcoming), but in any case I would like to see your work.

How the RookChat Code Is Organized

src/,, is the "main" routine. Generally, all this does is keep track of what basic actions and views are recognized and makes appropriate calls to the module and the module, in that order.

For each possible action, there is one method in each of and takes care of effecting any required changes, while returns the HTML that should be viewed as a result.
src/ * All modules that end in are interfaces to data files. Rather than accessing data files directly, the methods of these files should be called. This ensures that data files are not corrupted because two separate pieces of code are handling the same files differently. They also implement data caching features that help reduce disk usage.
src/,,,,,,,,, These modules perform higher level operations than the * modules do. Many of the operations covered in these modules make use of multiple * modules. Rather than handling data storage, as the * modules do, these modules have more of an understanding of the logic of how the program needs to run.
src/, These modules handle the execution of commands issued by users logged into RookChat (the commands that begin with a slash and are typed right into the browser window). The module contains information about what commands are available, what arguments each command takes, help information about the commands, etc. contains the code that actually gets run when a command is issued.
src/ Code for the streaming update method. When the chat is run in streaming mode, the messages frame, rather than refreshing periodically to get new messages, stays open and gets new messages as they appear. Consequently, the CGI process for the messages frame sticks around on the server, rather than simply displaying data real quick and exiting, as is normally the case for CGI programs. This lingering process is called the streamer, and contains the code it runs.
botlib/ This is the bot toolkit. Bots should only ever call functions defined in this module -- it should not be making direct calls to anything in the src/ directory.

How To Add New Features To RookChat

RookChat was designed to be reasonably easy to extend with new views, commands, bots, etc. Here is a brief overview about how to make the most common types of extensions to RookChat's functionality. Unless the changes you wish to make involve the very infrastructure of RookChat, the information below will probably help you.

Adding a new view to RookChat.

Here is how you can add a new view (or screen) to RookChat. Each type of page or frame served by the RookChat scripts is a view, e.g., the login page or the user list frame.

First, assign the new view a keyword and insert this into the __actions dictionary given in Then define two methods, one in and one in, that have this same name. The method should return '1' if no errors have occurred; otherwise, a tuple with the first element being whatever you want (usually 0) and the second being an error code. The error codes are located in This method should perform all actions associated with the view (for example, loading the user list frame updates your idle time, among other things) but not display anything. In most cases, you will want this method to authenticate the user at the very least. This requires making an appropriate call to a function in and immediately returning an error if it fails. You can check the other methods of to see how this is done.

The method in receives the return value of the method as an argument. The first thing you should do is check this argument for an error and act accordingly. Frequently, the first three lines of code will be exactly this:

	if ain != 1:

After that, you can start printing out the HTML code for the view by making calls to or just printing directly. Note that if you need to display a URL, you should use rcfiles.script_filename to refer to the name of the RookChat script, and methods in the module to display the query string portion of the URL. Be sure not to display any English text directly; to allow for internationalization, add a tagged message to the modules (in the language/ directory) instead. (If you know the foreign translations for the string, add it to the other language?.py modules as well.)

Adding a new command to RookChat.

To add a new command to RookChat, add an entry to with the command name, arguments, and help information. You'll have to add tagged strings to the module (in the language/ directory) for the help text. Also remember to add the new command to the "see also" lists of related commands. If the new command is part of a new command category (important only for the help text), then be sure to include the name of this new command category at the top of the list_of_commands_category() function in and to insert a new help_category_* string in the language files.

Next, add a method to that matches the name of the command. This method should do what is required to execute the command. If the new command is not one all users can run, this method should check permissions first. This method can make calls to a variety of modules to get its job done, including,,,,,, and any of the * modules. Make sure that you update the user's idle time if and only if the command does something publicly visible. Also make sure any text displayed anywhere gets sent through, to guard against HTML code, bad words, long messages, etc, being displayed inappropriately.

Adding a new option or profile field to RookChat.

To add a new option or profile field to RookChat, add an entry to the beginning of, where the options and profile fields are listed. There are a lot of possible fields for each option, so you might want to start by copying the most similar existing option. Take note of the comments in code, as they explain some of the less intuitive fields.

Next, edit the and add a translation for opt_newoptiontag (for a new option) or prof_newoptiontag (for a new profile field), where newoptiontag is the value you put for the "tag" field in This should be set to the displayed name of the new option or profile field. If this option or profile field is a "select" type (i.e., a drop-down box that allows the user to choose between a pre-determined set of values), then you must also supply a language translation for each value, in the form of opt_newoptiontag_value or prof_newoptiontag_value. As an example, look at the translations available for the "smileys" option.

If you are adding a new profile field, that's all you need to do; if you're adding a new option, you'll of course need to write whatever code consults and acts upon the value of the option.

Adding a new bot to RookChat.

First create a BotName.cgi file for the bot in the bots/ directory. This filename should be case-sensitive according to how the bot name should be displayed. All it should do is import, where botname is an all lower-case version of the bot name. This script should have all the bot code in it. It should only make calls to functions in to get its job done, i.e., it should never import anything from the src/ directory. If you need to interact with the RookChat code base in any way, and doesn't already have a method that supplies your needs, then add one.

The control flow for the module is a callback system, where methods are called as events occur. Your best bet is to copy an existing bot, one that more or less matches your needs from a structural standpoint, and make changes, rather than starting from scratch.

Adding a new language to RookChat.

Note: The following instructions only valid for version 1.00.04 and later. If you're working on a version of RookChat earlier than 1.00.04, your best bet is to upgrade to the latest version before going any further.

To add support for a new language to RookChat, you must add a new subdirectory to the languages/ directory whose name will function as a tag for the new language. Copy all the files from the english-american/ subdirectory into this new directory. Rename to have the same name as the new directory, but with .py added to the end.

The language files come in three different formats, and the rules for formatting them are slightly different:

Note that commands cannot be changed, so if, for example, there is a reference to the /rose command, it must stay the way it is and not be translated. This is also true of parameters to commands -- for example, the strings fixed, normal, mod, op, admin, owner, public, open, moderated, and restricted are parameters to the /userlevel, /newmemolist, and other commands. These have to stay as they are.

However, the visual display of, for example, [mod], [op], [admin], and [owner] tags can be translated into the new language: in fact, the *.py files contain a string for each of them. So be conscientious about this distinction as you translate.

Lastly, you have to add a line in all of the other *.py files in the other language directories. In each of these files, search for opt_language_, and you'll see a translation string for each language in the system. Add a translation string for the new language, completing the tag opt_language_ with the tag for your new language.

After the new directory and the new files are in place, RookChat should recognize the existence of the new language automatically; to test this, see if the new language now appears in the "Change Language" drop-down list on the main page.

Adding a new smiley to RookChat.

Simply put the new smiley image in the smileys/ directory and modify the src/ file by adding a new entry for the new smiley.