ZogBot

Probably my largest learning experience in java, ZogBot is an irc bot utilising the PircBot API by Paul Mutton, coincidentally a former student of the University of Kent ;).

The current version of ZogBot is the third complete rewrite. The main feature of this rewrite is the ability to dynamically load 'modules' from compiled classes, either on the same computer, or from another URL. In this way it becomes much easier for multiple developers to work on creating functionality for one bot, and avoids having to restart the bot for every minor change.

ZogBot also features a number of useful debugging tools, such as a list of uncaught exceptions which can be accessed via the ExceptionHandler module.

Modules

Modules are created simply by subclassing the Module class, or one of its subclasses designed for the same purpose. The class to extend depends on the precedence the module should take.

Most modules will extend the Module class itself. All modules that extend First will be called before any Modules. If a First module returns true for an action, no Modules will be called, but any remaing Firsts will be.

A Final module will come after all Modules. If a Final module returns true no more Finals will be called.

A Guaranteed module will be called after all Final modules, but will always get called. Useful if you want guaranteed functionality on every action that may otherwise hurt performance.

There are also two special modules which extend the Module class. There can only be one of each of these modules loaded, and they must not be extended. FirstModule will always be called first, and will act the same as a First otherwise.

FinalModule will always be called last. If any other module does anything this module will not be called.

In the future all modules that handle the access list or other network's bots must implement another class in order to 'declare' their intentions. This is to prevent people writing malicious code.

Every module must have a constructor with two parameters, the first being a ZogBot and the second being a String[] array of arguments. It should override the required methods, such as onAllLineMessage() if the module should handle every message spoken in the channel. All of these methods must return a boolean value. In general any method that does anything should return true, otherwise it should return false. There are, however exceptions, which usually become obvious with testing.

Currently modules should be in the com.blamethepixel.zogbot package, however this may become optional in the future.

Having written and compiled a module, it can be loaded via the load command, or via the load url command, eg.

>>zbot load Google
<<module com.blamethepixel.zogbot.Google loaded

>>zbot load url http://www.blamethepixel.com/zbmodules/ com.blamethepixel.zogbot.Google
<<module com.blamethepixel.zogbot.Google loaded

Access

Currently, access is handled by assigning nicknames a password and level. Someone with that nickname may then send a private message to the bot to identify themselves. Modules can access the users' level and make a decision as to whether or not to allow the user access.

Multiple Networks

The ServerManager class allows the bot to be run on multiple networks simultaneously without having to start a new bot for every network. This also means the bot can access information on what is happening on other networks easily. Every network is given an alias, as such another bot can be accessed like so:

z.getServerManager().getBot("wikked");

which will return the bot with alias wikked, or null if none is connected.

Debugging

Every network has its own debugging file, the PrintWriter for this file can be accessed via the ZogBot's getErrorLog() method. Other useful methods are sendStackTrace() and catchException()