Writing Plugins

Before starting...

  • This documentation is tentative, it's worth looking at the coreish plugins in contrib/ too. There is probably one that does what you want.
  • Have a look at the docs/javadocs/, viewable online via. viewcvs.
  • This page refers to writing plugins in Java. See also WritingJsPlugins.

The "Hello World!" Plugin

The Code.

import uk.co.uwcs.choob.*;
import uk.co.uwcs.choob.modules.*;
import uk.co.uwcs.choob.support.*;
import uk.co.uwcs.choob.support.events.*;

public class HelloWorld
{
        public void commandOne( Message mes, Modules mods, IRCInterface irc )
        {
                irc.sendContextReply(mes, "Hello world!");
        }
}

The Explanation.

import uk.co.uwcs.choob.*;
import uk.co.uwcs.choob.modules.*;
import uk.co.uwcs.choob.support.*;
import uk.co.uwcs.choob.support.events.*;
  • These are the standard imports that your plugin will probably eventually need to function, you may as well always include them.
public class HelloWorld
{
  • The public class with the name of your plugin. In this example we're calling our plugin "HelloWorld?". Note that while loading the plugin this is case-sensitive, even if your file-system isn't. When calling commands the name isn't case-sensitive.
        public void commandOne( Message mes, Modules mods, IRCInterface irc )
        {
  • This is a public method in your plugin that represents a command; the "command" prefix will be dropped to get the name of the command. In this case, the name of the command is "One". This isn't case sensitive.
    • This function takes three arguments (*).
    • The first is the Message object that contains data about the line that triggered the command.
    • The second is a set of Modules that contain functions you may want to use at a later point.
    • The third, an instance of IRCInterface, allows you to pass commands back to irc.
                irc.sendContextReply(mes, "Hello world!");
  • This line calls the method sendContextReply in IRCInterface.
    • This function takes two simple arguments. The first is the Message (*) that you are trying to reply to. In this case, and most other cases, it's the message that triggered the command.
    • The second is simply the String you want to send. If this is too long it'll be broken up for you.
        }
}
  • I hope you can guess what these lines do. ;)

Lesson 2

You're now ready to progress to Lesson2, woo!