Overview

Twitter Bot

TwitterBot is a really simple helper for making an IRC bot for twitter. This lets you create functionality based on content in replies to the bot. It comes with an example handler for posting links to delicious.

Writing a Plugin/Extension

A plugin is just a module that provides a function "handler" that will be called. The function must accept 3 parameters:

  1. The tweet - A Status object from the Python twitter library.
  2. The Twitter Client API - A Python twitter api connection for further interactions such as replying to a tweet.
  3. Configuration - The configuration defined in the config for that specific handler. In the delicious example, this contains the delicious username and password.

Defining a Plugin

Here is a really simple example plugin:

# sample.py

def handler(tweet, api, conf):
    '''Does the tweet contain any of words?'''

    wordlist = conf.get('words', [])
    had_words = []
    for word in wordlist:
        if word in tweet.text:
            had_words.append(word)
    msg = '%s that last tweet had in it' % (tweet.user.screen_name, ', '.join(had_words)
    api.PostStatus(msg)

Adding it to the Config

Then in the config you would add it along with any config data.

# your.conf

handlers:
  -
     name : hasword
     module : sample
     words :
       - foo
       - bar

The filter then would check if the tweet had any of the listed words in it and send a reply.

Authorized Users

No filter will be called if the person doing the tweeting is not in the list of users defined in the config. Users are specified using the their screen name without the "@".