About a month and a half ago, I started work on a chat bot for Stack Overflow. The name was chosen by looking up Latin words related to chat. I wanted to get a Latin word for chat bot, but I guess the language went stale before such things existed.

Loquitor is command-based. One can’t do something like @Loquitor: help because it isn’t smart enough to figure out when a ping is meant as a ping or just a mention, like @zondo: You should add blah blah to @Loquitor. Yes, that does happen. A command is any message that starts with >>. I plan on making that configurable, but I haven’t yet. Oh, and testing Loquitor is easy. Just log in to Stack Overflow with an account of >20 reputation, and go into the Sandbox. It all starts with >>help.

Loquitor is meant to be a helpful bot, but there are a couple “fun” parts. The >>test command, for example, responds with a random (usually annoyed) message just to show that Loquitor is running. It also has kaomoji substitutions, which are more fun than helpful. Just run >>kaomoji to see which ones are supported. The substitutions are found when sending a message of the format &some-kaomoji;, where some-kaomoji is something like excited, lenny, flip, etc. Most of the kaomoji substitutions don’t need either the ampersand or the semicolon, but some common words like “what” do require them to prevent Loquitor from posting too many unrelated kaomojis. To see everything including aliases, one can run >>kaomoji all. Note that you can’t see the actual kaomojis without trying them out. The >>kaomoji command merely gives a list of what you can type, not what Loquitor will respond.

I wrote Loquitor in a way that makes it very easy to add more to it. Here is basically how it gets started on my computer: First, a Loquitor.skeleton.Room object is created. That class is an extension of the chatexchange.rooms.Room class that makes signals easier to use. It supplies the connect and disconnect methods, which are similar to the Widget.connect and Widget.disconnect methods available in PyGTK. The connect method is given a signal and a function. When the signal is emitted (such as message-posted or user-entered), the function is called with a couple arguments relevant to the signal. After the room is created, some extra signals are registered with the Loquitor.skeleton.Room.register method. These signals are things like Command-test, Command-help, etc. The signals are determined by reading the modules in the Loquitor.scripts package. Each module is parsed for commands. If a commands dictionary is available as a module variable, each key-value pair will be registered. If, then, a help dictionary is also available, the key-value pairs are seen as a command and the help for it. If the commands dictionary is not available, the module is checked for a main() callable. That could be a function, but a couple of them use a main class. In the main callable, a new command can be registered with the Loquitor.bot.Bot.register method. Since each module is read, adding new commands is as simple as it sounds. Create a new file in the Loquitor/scripts folder with either a commands dictionary or a main callable, or (if your new command is related to others) just add the function to an existing commands dictionary or put your own bot.register() call in an existing main callable.