|
Bot::Pluggable - A plugin based IRC bot |
Bot::Pluggable - A plugin based IRC bot
use Bot::Pluggable; use MyPlugin::Joiner; use MyPlugin::Factoid; use MyPlugin::OpBot; use POE;
my $factoid = MyPlugin::Factoid->new(); my $opper = MyPlugin::OpBot->new();
my $bot = Bot::Pluggable->new(
Modules => [qw(MyPlugin::Joiner)],
Objects => [$factoid, $opper],
Nick => 'my_bot',
Server => 'grou.ch',
Port => 6667,
);
$poe_kernel->run(); exit(0);
This is a very small (but important) part of a pluggable IRC bot framework. It provides the developer with a simply framework for writing Bot components as perl modules.
Each module gets a chance to listen to an event on the IRC network it joins and respond to those events accordingly. For example an IRC joiner plugin might look like:
package MyPlugin::Joiner; use POE;
sub new {
my $class = shift;
return bless { channels => [ '#perl', '#axkit-dahut' ] }, $class;
}
sub irc_001 {
my ($self, $bot) = @_[OBJECT, SENDER];
$bot->join($_) for @{$self->{channels}};
return 0;
}
1;
Each plugin gets a chance to respond to the event. If no other plugin should respond then it should return 1. If other plugins are allowed to respond to this event then return 0.
All the events correspond to those listed in the POE::Component::IRC manpage.
The $bot object is stored in the $_[SENDER] parameter (SENDER
is a constant exported by POE). This object is your Bot::Pluggable
instance, which inherits its methods from POE::Component::IRC::Object,
allowing you to join channels, send msgs, etc.
If an event isn't available (check the source code for the list of events supported by default), then you can add it with:
Bot::Pluggable->add_event('irc_ctcp_foo');
This is neccessary for CTCP events that aren't defined by default.
Matt Sergeant, matt@sergeant.org
This is free software. You may use it or redistribute it under the same terms as perl itself.
|
Bot::Pluggable - A plugin based IRC bot |