package heufybot.modules;
import heufybot.core.HeufyBot;
import java.util.List;
/**
* This abstract class provides an interface for any module used by the bot. All
* modules must extend this class in order to be loadable.
*
* @author Stefan "Heufneutje" Frijters
*/
public abstract class Module
{
/**
* This variable is to be a regex. An example of a trigger set in the
* constructor of a module would be:<br/>
* <i>
* <p/>
* <pre>
* this.trigger = "ˆ" + commandPrefix + "(say)($| .*)";
* </pre>
* <p/>
* </i> The trigger is not case sensitive. The above trigger ignores any
* suffix after the command. It is possible to trigger on more than one
* command, as shown here: <i>
* <p/>
* <pre>
* this.trigger = "ˆ" + commandPrefix + "(load|unload|reload)($| .*)";
* </pre>
* <p/>
* </i>
*/
protected String trigger;
/**
* This determines whether or not the module should be triggered on every
* message. This is useful for automatic commands, like checking when a
* certain person talks.
*/
protected boolean triggerOnEveryMessage;
/**
* A reference to the static {@link HeufyBot} instance.
*/
protected HeufyBot bot;
/**
* Who can invoke the module. If Anyone is used, any IRC user is allowed to
* invoke the module. If OPs is used, only bot admins are allowed to invoke
* the module.
*/
protected AuthType authType;
protected String commandPrefix;
protected String server;
/**
* What types of events trigger the module. Possible triggers are: Message
* and Action
*/
protected TriggerType[] triggerTypes;
/**
* The module API version this module is using. This must match up with the
* bot's module API version for the module to be loadable.
*/
protected int apiVersion = 0;
public Module(String server)
{
this.bot = HeufyBot.getInstance();
this.server = server;
this.commandPrefix = this.bot.getServer(server).getConfig()
.getSettingWithDefault("commandPrefix", "~");
}
/**
* This method gets called when the module command triggers.
*
* @param source The name of the channel from which the command originated.
* @param message The message received, with any command, without username or
* channel information.
* @param triggerUser The IRC username that entered the command
* @param params The same as message, split at " ". The first index can be
* checked for the trigger.
*/
public abstract void processEvent(String source, String message, String triggerUser,
List<String> params);
/**
* @return The module API version this module is using
*/
public int getAPIVersion()
{
return this.apiVersion;
}
/**
* @return The trigger for this module
*/
public String getTrigger()
{
return this.trigger;
}
/**
* @return The module's authentication type (Anyone or OPs)
*/
public AuthType getAuthType()
{
return this.authType;
}
/**
* @return An array with all trigger types this module supports
*/
public TriggerType[] getTriggerTypes()
{
return this.triggerTypes;
}
@Override
public String toString()
{
return this.getClass().getSimpleName();
}
/**
* Every module can be checked for syntax by the help module. This is the
* method that gets called to facilitate that.
*
* @param message The message received. It is sent to provide help for possible
* subcommands
* @return The string to be printed by the help module when a user calls
* (commandPrefix)help yourmodule
*/
public abstract String getHelp(String message);
/**
* Automatic method that gets called by the ModuleInterface when the module
* is being loaded. Use this to make sure any necessary resources exist,
* such as folders or files.
*/
public abstract void onLoad();
/**
* Automatic method that gets called by the ModuleInterface when the module
* is being loaded. It is typically used to save resources used by the
* module to a file.
*/
public abstract void onUnload();
/**
* @return Whether or not this module will be triggered on any message
*/
public boolean getTriggerOnEveryMessage()
{
return this.triggerOnEveryMessage;
}
public enum AuthType
{
Anyone, BotAdmins
}
public enum TriggerType
{
Message, Action;
}
}