Dec 05

I pulled the Zork Twitter bot apart and rebuilt it using more sensible means.   HTMLUnit for scraping the actual WebZork game and Apache Commons Config for configuration reading.  The code was also restructured to support Twiiter Bot plugins. 

It is a failry simple interface constisting of 4 callbacks that are invoked on interesting Twitter events.
The methods are passed a Twitter client object that allows the bot to send tweets. 

The default example that simple echos any tweet sent to it is:

package com.glulogic.twitter.bot

public class DefaultTweetHandler {

  // Each method called is passed a 'context' hashmap
  // containing the following keys:
  //
  //  from    -  the shortname (login) of the user who sent the Tweet
  //  body    -  the contents of the Tweet (@... removed)
  //  twitter -  an object that can send tweets to Twitter users

  // called when someone sends an  metion (e.g. '@...')
  def mention(context) {
    context.twitter.mention('to': context.from, 'message': "You said ${context.body}")
  }

  // called when someone sends a direct message (e.g. 'd ...')
  def direct(context) {
    context.twitter.direct('to': context.from, 'message': "You said ${context.body}")
  }

  // called when a user begins following
  def follow(context) {
  }

  // called when a user stops following
  def unfollow(context) {
  }
}
May 31

About a month ago I created a Twitter Bot that lets people play their own instance of Zork. For example send a tweet to:  @zorkgame look http://twitter.com/zorkgame Its very rough and ready ,but have fun for a few minutes if that’s your thing. Some techincal details:

  1. It is written in Groovy,
  2. It has an XMPP client part using Smack API,
  3. It has a HTTP client part using HTTPBuilder
  4. Integration to Twitter is via tweet.im, a Twitter via XMPP service,
  5. Any Large Zork responses are refered to via a Tweet with a link to a temporary user specific drop box on Mailinator which will contain the large message
  6. The Zork game is provided by these guys,  the script POSTs and ‘parses’ the response (screen scrapes),
  7. The bot is hosted on an Amazon VM (as part of another plaything).
Tagged with: