Luke Evers

Kittens: an IRC bot written in Go (Preview)

Posted on 6 July 2014

I've written three IRC bots so far. The first was when I decided I wanted to learn node.js. It started off very rough, but eventually ended up as a nice little modular IRC bot. I wasn't satisfied with the way it was written though, so I decided to write it in Go. I didn't get that far the first time I tried writing it in Go because I was caught on the question of "how am I going to make this modular like the JS version?" and similar questions. In the meantime I was still using my JS bot. I started to rewrite it in CoffeeScript when I decided that I wanted to give that language a try.

I've never really thought about it this way, but I think writing an IRC bot is my goto project when I want to get to know a new language; however, it was not my first time with Go when I originally started my Go version.

The Fourth Time Around

Not to long ago I decided I wanted to rewrite Kittens again in Go. This time instead of just throwing a bot together I decided I really wanted to make something that I could really use. Sure, all my other IRC bots have been useable, but not to the extent that I've wanted them to be. If I need to update something, I don't want to have to ssh in to the server I'm running Kittens on, reattach a tmux session and then run a few commands.

As of right now everything is still in early stages. There's a web interface, but absolutely no security yet. This is what the main interface looks like when you view /:

Main

When you click on one of the servers on the main page it takes you to /server/{id}. When Kittens begins to run, each server in our slice of Server structs in our Config struct is given an ID starting at 0. Each server is run in their own goroutine.

var nextID uint16 = 0  
for _, s := range config.Servers {  
    wg.Add(1) // wait group
    s.ID = nextID; nextID++
    go s.CreateAndConnect(true)
}

Server Enabled

When you hover over the checkmark in the green circle it changes to a red circle with a big x in it. If you click that circle it will disable and disconnect the server from the IRC network it is currently connected to.

Server Hover Disable

Server Disabled

Joining and parting channels is quite easy, too. To part a channel just click the x in the channel box that you want to part. To join a channel type the channel name in that you want to join and hit your enter key.

Next

There are stil a number of issues that need to be adressed, and some that have yet to even have been started. The main two that I will most likely be focusing on next are:

  • Web Interface Security
  • Logging

But for a full list, you can checkout the issues list on GitHub.

Contributing

For anyone that sees this that wants to contribute, I welcome them! Kittens is open sourced on GitHub, and I would gladly accept pull requests that fix problems or implement something that has yet to be implemented.

comments powered by Disqus