Compy is a Twitter bot slash art project, designed to recreate a heckin' old computer. You can give gifts to friends:

You can battle your followers:

You can get a custom personal horoscope:

You can get a virtual horse friend:

And you can get matched with other Compy users:

WHY

After Statbot I wanted to work on something a little more involved, with a ton of moving parts, possibilities for users, easter eggs, and above all I wanted it to look cute. I decided on a retro style computer GUI, because it’s relatively simple to design (I saved a ton of time not having to pick colors for everything) and it’s visually familiar to people.

HOW

Like all of my Twitter bots, Compy is mostly Ruby code. There’s HTML and CSS to format the visuals, which then gets printed to an image using IMGKit, but it’s all generated in Ruby. Ruby’s string interpolation especially makes things easy, as you quickly generate unique text very simply, kinda like this:

def sentence
        all_topics = discuss
        one = all_topics.shift
        two = all_topics.shift
        [
            "Time 4 a rap battle!! each line must include a reference to either #{one} or #{two}. ideally both.",
        ].sample
    end

    def discuss
        [
            "dogs", "dinosaurs", "pokémon", "sushi", "volcanos", "Gucci Mane", "hi-top sneakers",
            "ice cream", "weed", "skateboards", "Tony Hawk", "dogwurld", "R2D2", "safe sex",
            "dank memes", "genies", "roller coasters", "fried chicken", "fine leather jackets",
            "Melissa Joan Hart", "Indiana Jones", "milkshakes", "soft pillows", "computing", "rap",
            "blankets", "palm trees"
        ].shuffle
    end

Every 10 minutes, the bot checks its recent mentions and filters by a number of factors: the user must follow Compy, it must contain a valid command, the user can’t have more than 5 pending requests in the database. If you’re requesting something for another user, they have to follow you, and so on. After it has filtered the list down to the valid requests, it inserts each request into a PostgreSQL database. I used Datamapper as an ORM since my needs were very simple and it seemed a little more lightweight than including all of ActiveRecord. Here’s what the basic validation looks like:


    def is_valid?
        return false if @type.nil?
        return false if older_than_31_minutes?
        ## require db calls below here
        return false if mention_exists?
        return false if user_has_more_than_x_requests?
        ## comment this out if getting rate limited
        return false unless user_follows_me?
        return false unless user_follows_tagged_user?
        if @type == "framey"
            return false unless is_valid_frame_request?
        end
        return true
    end

Once the requests are entered, Compy then pulls 14 requests from the DB, generates images for them, and uploads them to Twitter. Once the requests are filled they’re marked as done and eventually deleted from the DB.

The entire system is pretty modular, so it’s simple to add to.

ART

I created most of the art myself, using Pixelmator. I’m not the best artist, so the black-and-white pixel style was easy enough to work with. I also asked Statbot’s followers and a few friends to contribute art for the gifts mode, so a number of those were created by other people, many of which I’ve never met.

STATS

This time I wrote some simple stats scripts so I can tell what’s going on. In the interests of keeping everything as free as possible, I use a Gmail account to store all of the stats. Every hour I generate a JSON file and use the Gmail account to mail it to myself. Whenever I want to I can download all the JSON files and run a local script that collects all of the data and counts the interesting stuff. Here are a few examples of the outputs of my stats script:

Here are the total numbers of fulfilled requests for each specific mode:

Here are the average response times (note that it only checks for requests and posts every 10 minutes because it’s on Heroku’s free tier). Times for “match” requests are higher because it takes two people, so if you’re the only one making that request at a given time you have to wait for someone else to come along.

stats for compy in a grid view

And here’s the count of each astrological sign’s frequency:

additional stats for compy in a grid view