Sarah

From BluWiki
Jump to: navigation, search

Contents

[edit] History

Sarah is an IRC bot that is being developed by BluCoders (at the moment mostly by just Exodus). She was first envisioned about a year and a half ago, and has since been rewritten a few times.

Error creating thumbnail: convert: unable to open image `/usr/share/webapps/mediawiki/images/7/78/No-worries.PNG': No such file or directory @ error/blob.c/OpenBlob/2614.
convert: unable to open file `/usr/share/webapps/mediawiki/images/7/78/No-worries.PNG' @ error/png.c/ReadPNGImage/3639.
convert: missing an image filename `/usr/share/webapps/mediawiki/images/thumb/7/78/No-worries.PNG/200px-No-worries.PNG' @ error/convert.c/ConvertImageCommand/3016.
The first stages of the bot skeleton back in 2008

It all started somewhere at the end of October in 2008. It was originally just a pet project cn00b had intended in order to teach ABK about how the IRC protocol works, and what better way is there than to write an IRC bot? Not after long they had established a decent working a somewhat nice-looking bot skeleton which worked without issues, but at the time neither of them had the slightest idea of just how much this little pet project would escalate and expand beyond their wildest dreams.

In the beginning the bot was named "blu" after ABK's beloved "BluServ", and later on ABK renamed it to "Sarah". As to the reason of why he chose this exact name is still - and might always be, a mystery, even to the creator himself. Over time this tiny project caught interest from several of the BluCoders team members, particularly Exodus who would later became the project's main developer.

[edit] Configuration

At the moment, not much can be configured. The main configuration file is sarah.ini.

[edit] Sarah.ini

It specifies the database that contains details of the servers to connect to. The database can be SQLite or MySQL at the moment. It can be hosted on the same server or a remote one.

[edit] The database

The database specified in sarah.ini contains details of the servers to connect to. It currently has one table - servers. The table contains the following fields:

  • id - this is mostly self-explanatory. It is a unique number identifying the server.
  • name - the name of the server. This is currently only used for messages outputted to the terminal, but may, in future, by used for logging and such
  • inuse - this field is also self-explanatory. If it set to 1, the server will be connected to, otherwise it won't
  • server - the address of the server to connect to. This should be "localhost" if it is to connect to the same computer that it is on, otherwise may be an IP address or domain name.
  • port - the port to connect to on the server.
  • nick - the nickname to use on the server.
  • nickpass - the password needed to identify to nickserv, if any. If the nickname is not already registered, and this field is set, then Sarah will automatically register herself to nickserv.
  • channels - a list of channels to join on connection
  • channelpasswords - the passwords necessary for the channels to connect to
  • cmdprefix - a string that can be used to prefix commands

An example command to create the table: <syntaxhighlight lines="0" lang="mysql"> CREATE TABLE servers ( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(32) NOT NULL UNIQUE, inuse BIT DEFAULT 0, server VARCHAR(64), port INTEGER, nick VARCHAR(32), nickpass VARCHAR(32), channels VARCHAR(128), channelpasswords VARCHAR(128), cmdprefix VARCHAR(8)); </syntaxhighlight>

[edit] Code

Sarah is currently split up into serveral files, to allow the code to be easier to read. These files each serve one purpose, and do that well.

[edit] Command Parsing (commands.php)

This file contains code to parse the commands that Sarah is sent. As such, it is quite an important file.

[edit] Support Functions (functions.php)

This file contains functions that are key to Sarah's functioning. It contains functions such as those to connect to a server, log a message and so on.

[edit] Regular Expressions (regex.php)

This file lists all of the regular expressions used in Sarah. It is quite an extensive list - as previously mentioned, Sarah is highly dependant on regular expressions. It has regex's for IRC messages, and also the format for commands sent to Sarah. The regex's are defined using PHP's define() function.

[edit] The Main Sarah File (sarah.php)

This file holds everything together. It uses the functions in functions.php to connectect, and then executes commmands based on the messages. It currently has a lot of commented out code from the old Sarah file. As such, it is rather ugly.

[edit] Common functions (common/*)

These files are ones that I have come to find useful in pretty much every PHP project, and as such are linked in to this one. They contain the code for making database connection, and a "Blob" class.

Personal tools