NAME

Whatbot::Command - Base class for whatbot commands

SYNOPSIS

 package Whatbot::Command::Example;
 use Moose;
 BEGIN { extends 'Whatbot::Command' }
 
 sub register {
	 my ($self) = @_;
	 
	 $self->require_direct(0);
 }

DESCRIPTION

Whatbot::Command is a base class, meant to be subclassed by any additional whatbot command or extension. It provides a skeleton structure to create a new command, parses command attributes, and gives the warnings necessary when a command is not implemented properly.

To create a new command, subclass this module using Moose's 'extends' pragma, and override the given methods with your own. Set attributes to your methods to hook into events.

Keep in mind that if you're looking for functionality that you'd expect in your command, and not seeing it here, double check Whatbot::Component.

RETURN VALUES

Each subroutine called by the Controller can return either a string or a Whatbot::Message.

SUBROUTINE ATTRIBUTES

A Command can respond to different types of messages, triggers, and events, and those are communicated via subroutine attributes. These attributes can be combined for any individual method, or you can structure your code to have different entry points for each event. The available attributes are:

Command

Command is the most basic event type. The given method would fire when a message comes in with "<command-name> <method-name>". For example, for the command "Seen", and the method name "test", then it would fire if someone stated "seen test" in whatever context whatbot is listening.

CommandRegEx('$regex')

CommandRegEx is similar to Command, where it listens after the command name, except it will look for a match to the given regex instead of the method name. To respond to "seen test", you would provide CommandRegEx('test').

GlobalRegEx('$regex')

GlobalRegEx will fire if the given regex is found on any input, whether the command name is involved or not. This is useful for parsing any content in a message, or looking for a triggering keyword.

Monitor

Monitor will fire on any incoming, visible message.

StopAfter

Force whatbot to stop processing commands after this method returns.

Event('$event')

Event will fire on the given incoming event. To specify multiple events to respond to, multiple Event attributes must be provided. An Event attribute does result in a change to the method signature, as it will provide $self, $target, which is the context that the event was fired from, and $event_info, which is a hashref containing different data depending on the event. Events are provided by IO modules, so you will want to check those for additional event types. In general, the possible events are:

enter : $event_info contains 'nick'
user_change : $event_info contains 'nick', 'old_nick'
leave : $event_info contains 'nick'
ping : $event_info contains 'source'
topic : $event_info contains 'nick', 'topic'

PUBLIC ACCESSORS

command_priority

Determines at what point in the processing order this command will fire. Valid entries are 'Primary', 'Core', 'Extension', and defaults to Extension. Primary are first runners, Core are components considered essential, and Extension is parsed in order after those components.

require_direct

Forces the module to only respond if the name of the bot is used in the message.

my_config

Contains the configuration for this module from the whatbot config file, if any.

timer

Provides access to Whatbot::Timer functionality.

PUBLIC METHODS

register()

Called after class instantiation to set properties and instantiate any persistent objects required by the Command. This would be the equivalent of new() or BUILD() for your command.

help()

Returned when a user asks for help on a command. You can also add a : Command attribute so someone may ask your command for help directly.

LICENSE/COPYRIGHT

Be excellent to each other and party on, dudes.