Extensions writing

From Apibot
Jump to: navigation, search

Apibot extensions will typically do their work by hooking at the Apibot hooks and changing the parameters and/or data that passes through them. If you write an extension, you must define functions and classes that do the work, and to supply them to the appropriate Apibot hooks.

Typically, you will make a directory that is named after your extension and will contain all files needed for it. (The Apibot user, or an appropriate installation procedure will have to copy this directory into the Apibot path /extensions.) The directory must have a file named for it, and with extension ".php". Apibot will include this file on startup. It is the place where you must attach your functions and classes to the Apibot hooks.

The hook attachment is done after the bot has set its environment (you can still re-set its important parts), and the Settings and Hooks sub-objects of the Core object are created. However, all other Core objects are created after that, so with proper hooking you may influence them as early as the start of their creation. Interfaces are always created after the Core object is ready, and tasks are started after the interfaces are created, so you will have control over that, too.

If your extension has problems with another one, or creates problems for another one, make sure to notify the Apibot user in some way. Describe what is needed to not have problems - to disable an extension, or to reconfigure it in a particular way, or to include both extensions in certain order...

All other rules of the good extensions programming are also into play:

  • test Apibot for compatibility (eg. check the constant APIBOT_VERSION)
  • check if there are present offending or offended Apibot extensions
  • check the wiki for known incompatibilities with your extension
  • version your extensions accordingly
  • log info where needed
  • write your code properly, with a good style, readable etc
  • include the needed documentation, readmes, notes etc

See also