Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Plugin Writing

Jason Fried edited this page Feb 12, 2014 · 7 revisions

There are two types of pyaib plugins, class based or just functions. They both use the same decorators but the class based plugins get a irc_context and config passed to their constructor.

Pyaib objects

Context Object

Every method called by pyaib will receive an irc context object. The context is a dictionary subclass (pyaib.util.data.Object)

The context contains information about the running bot and has methods for interacting with IRC. The following methods are present in the context object, they are all UPPERCASE. In the future these might move to a sub dictionary called 'cmd'

  • context.RAW(string) send raw strings to the irc server
  • context.NICK(string) Set the bot nickname
  • context.PRIVMSG(target, message) Send message to target via PRIVMSG. Messages longer than 510 characters will be split into multiple messages
  • context.JOIN(channels) Join a single channel or a sequence of channels. Will split long sequences of channels into multiple JOINs of a max of 510 characters long.
  • context.PART(channels, message=None) Leave a channel and provide an optional message. Channels can be a list remember context.JOIN('0') is the fastest way to leave all your channels.

The context has the following bits of information

  • context.botnick is the bot's current nickname
  • context.botsender is the bot's Sender Object
  • context.server is the current IRC Server Sender Object
  • context.config the global bot config

The following components are available via the context

  • context.channels (Good for checking membership in a channel) '#channel' in context.channels
  • context.events (Fire events or register new ones)
  • context.timers (Periodic events)
  • context.triggers (keyword triggers)
  • context.db (DB component access, if configured)

Plugin Hooks (Decorators)

from pyaib.plugins import observe, keyword, every, plugin_class

@plugin_class

This decorator designates a class as a plugin and it will be initialized when the module is loaded. The decorator can take an optional string argument that tells pyaib to save the instance of the plugin in the irc_context object with the given name.

All plugin classes must have an init method that takes two arguments the first is the irc context the second is a config object.

Clone this wiki locally