The first time it is executed it is passed a single argument: user_commands. The next time Baxter executes the script it is executed with the command server_messages. If a script wants to be called when the user types a specific command, or when a specific server message is received from the server, the commands or messages should be printed out to standard output. For example, if a bash shell script wants to be called when the user types /foo and when the user types /bar the script might look something like this:
#!/bin/sh if [ "$1" = "user_commands" ] # Called when Baxter starts to find out what then echo "/foo" # user commands this script handles echo "/bar" fi
All the script does is check if the first argument is received was equal to "user_commands". If it was, the script prints /foo and /bar to standard output. "server_messages" work in exactly the same way:
#!/bin/sh if [ "$1" = "server_messages" ] # Find out what server messages this then echo "JOIN" # script handles echo "PART" fi
This script tells Baxter it would like to be notified of JOIN messages and PART messages. Consult the documentation of the specific language you would like to write your scripts in. In C/C++ doing a strcmp on argv[1] should work fine. You're on your own for perl, python, etc.
Now that Baxter knows what user commands and server messages your script wants to be notified of you'll need to add code to handle the user command and server message. When the user types /foo Baxter will execute your script as follows:
script.sh user_command nickname viewname selected_users user_entry
Useful Commands: Use /echo to tell the user something. /run and /rrun may also prove useful. /run runs a command and echos its output to the user. /rrun runs a command and echos its output to everyone (if the user is in a channel).
Server Messages
If your script is set to be notified of JOINs, for example, when Baxter receives a JOIN from the server your script will be executed as follows:
script.sh server_message message
:Nick^!ident@www.host.com PRIVMSG #beos :a b c
Argument 2 will be ":Nick^!ident@www.host.com" argument 3 will be "PRIVMSG" and so on.
If you don't want Baxter to continue the handling of the server message you just received, the first line you print out should be "DNC", short for do not continue. In bash this is as simple as:
echo "DNC"