The Code
The simple plug-in will be called Simple, so create a new directory
called Simple under the
plugins directory. Then create the directory
path for the source code under that
(src/net/sourceforge/ppf/plugin/simpleplugin).
You should end up with something like .
Figure 1. The directory structure for the Simple plug-in
Now create a file called SimplePlugin.java in
the simpleplugin directory:
package net.sourceforge.ppf.plugin.simpleplugin;
import net.sourceforge.ppf.PPF;
import net.sourceforge.ppf.PPFPlugin;
import net.sourceforge.ppf.util.PPFHelp;
public class SimplePlugin extends PPFPlugin {
static final String PLUGIN_VERSION = "1.0";
// The commands the plug-in will respond to.
static final String COMMAND_TIME = "!time";
static final String COMMAND_HELLO = "!hello";
public SimplePlugin( ) {
// Set the plug-in version information.
setVersion(PLUGIN_VERSION);
// Set the help responses for this plug-in.
setHelp(COMMAND_TIME, new PPFHelp(COMMAND_TIME,
"Show the time of the server that the bot is running on",
PPF.AUTH_NONE));
setHelp(COMMAND_HELLO, new PPFHelp(COMMAND_HELLO,
"The bot says hello back to you", PPF.AUTH_NONE));
}
// Respond to channel messages.
public void onMessage(String channel, String sender, String login,
String hostname, String message) {
if(message.equalsIgnoreCase(COMMAND_TIME)) {
String time = new java.util.Date( ).toString( );
getBot( ).sendMessage(channel, sender +
": The time where I am is currently: "+ time);
} else if(message.equalsIgnoreCase(COMMAND_HELLO)) {
getBot( ).sendMessage(channel, "Hi there " + sender + "!");
}
}
}