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.

When it’s so easy to add new commands, who can resist coming up with good ones? I can’t, so I got some great commands in there for you. Go, try it out in the Sandbox. I can see how much you like it. No, wait; actually, I can’t unless you show me by starring Loquitor on Github. Any commands you’d like to see added? Tell me about it. Leave a comment below, add an issue on Github, ping me in the Sandbox, send me an e-mail, or add it yourself and submit a pull request. I’m always ready to get help. You might want to tell me about your idea before you code it so that there isn’t the risk of you coding something that I don’t actually use, but you could still use it even if I don’t add it. Run Loquitor from your computer, and you can add as many commands as you like. You could also run Loquitor on Heroku. I’ll show you how in my next blog post.