Skip to content

jberger/Toastr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Toastr - The simple pluggable IRC bot

SYNOPSIS

#!/usr/bin/env perl

use Mojo::Base -strict;
use Toastr;

my $toastr = Toastr->new(
  channels => ['#toastr'],
  nick     => 'toastr',
  user     => 'toastr bot',
  server   => 'irc.perl.org:6667', 
);

$toastr->plugin('KarmaHandler');
$toastr->plugin('Toast');
$toastr->plugin('Hailo');
$toastr->start;

DESCRIPTION

Toastr is a subclass of Mojo::IRC implementing a simple pluggable IRC bot. The base class attaches additional events which are emitted when the bot sees and/or receives a message. The events receive an instance of Toastr::Message containing lots of useful information about the message. Toastr's built-in events are prefixed with toastr_ and Mojo::IRC's events are prefixed with irc_.

Plugins are subclasses of Toastr::Plugin. A plugin will most likely subscribe to one or more event, then either take some action on that event, or even emit events of its own. Plugins namespace must be of the form Toastr::Plugin::<PluginName>. When loaded, the plugin instance will be stored in a the plugins attribute named, keyed on the plugin name. The convenience method "plugin" may be used to access the plugin and load it if necessary.

EVENTS

Toastr inherits all of the events from Mojo::IRC and emits the following new ones:

toastr_message

$toastr->on( toastr_message => sub {
  my ($toastr, $message) = @_;
  ...
});

Emitted for every message that the bot sees.

toastr_direct_message

$toastr->on( toastr_direct_message => sub {
  my ($toastr, $message) = @_;
  ...
});

Emitted for every private message (pm) or message prefixed with the bot's nick (the nick and an optional punctuation mark will be stripped from the message).

ATTRIBUTES

Toastr inherits all of the attributes from Mojo::IRC and implements the following new ones:

channels

An array reference of channels to connect to.

nick_ptn

A qr regex which is used to extract valid nicks. This probably does not need to be changed from its default.

plugins

Holds instances of loaded plugins, keyed by plugin name. This attribute should not be changed manually, use the methods "plugin" and /load_plugin.

METHODS

Toastr inherits all of the methods from Mojo::IRC and implements the following new ones.

attach

$toastr->attach;

This method must be called to subscribe to the necessary events and connect to the server. Note that the convenience method "start" calls this method for you.

load_plugin

$toastr->load_plugin('PluginName' => { attr => $val, attr => $val, ... });

Loads plugin PluginName and creates an instance. An optional hash reference is used to set attributes on the plugin. The instance is stored in the /plugins hash.

Note that this may be used to replace the instance if desired.

msg

$toastr->msg( $chan => $text, $text, ... );

Send a privmsg to the server and channel $chan. The text of the message is all trailing arguments (joined by $").

plugin

$toastr->plugin('PluginName' => { attr => $val, attr => $val, ... });

Returns either the cached instance of the plugin or constructs one if necessary using "load_plugin". If the plugin is already loaded, the constructor hash is ignored.

SEE ALSO

Mojo::IRC
Mojo::IOLoop
Mojolicious

SOURCE REPOSITORY

http://github.com/jberger/Toastr

AUTHOR

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

About

The simple pluggable IRC bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages