| 1 |
NAME |
|---|
| 2 |
Bot::BasicBot::Pluggable - extension to the simple irc bot base class |
|---|
| 3 |
allowing for pluggable modules |
|---|
| 4 |
|
|---|
| 5 |
SYNOPSIS |
|---|
| 6 |
Creating the bot module |
|---|
| 7 |
# with all defaults |
|---|
| 8 |
my $bot = Bot::BasicBot->new(); |
|---|
| 9 |
|
|---|
| 10 |
# with useful options |
|---|
| 11 |
my $bot = Bot::BasicBot::Pluggable->new( channels => ["#bottest"], |
|---|
| 12 |
|
|---|
| 13 |
server => "irc.example.com", |
|---|
| 14 |
port => "6667", |
|---|
| 15 |
|
|---|
| 16 |
nick => "pluggabot", |
|---|
| 17 |
altnicks => ["pbot", "pluggable"], |
|---|
| 18 |
username => "bot", |
|---|
| 19 |
name => "Yet Another Pluggable Bot", |
|---|
| 20 |
|
|---|
| 21 |
ignore_list => [qw(hitherto blech muttley)], |
|---|
| 22 |
|
|---|
| 23 |
); |
|---|
| 24 |
|
|---|
| 25 |
(You can pass any option that's valid for Bot::BasicBot) |
|---|
| 26 |
|
|---|
| 27 |
Running the bot (simple) |
|---|
| 28 |
There's a shell script installed to run the bot. |
|---|
| 29 |
|
|---|
| 30 |
$ bot-basicbot-pluggable.pl --nick MyBot --server irc.perl.org |
|---|
| 31 |
|
|---|
| 32 |
Then connect to the IRC server, /query the bot, and set a password. See |
|---|
| 33 |
Bot::BasicBot::Pluggable::Module::Auth for details. |
|---|
| 34 |
|
|---|
| 35 |
Running the bot (advanced) |
|---|
| 36 |
There are two useful ways you can use a Pluggable bot. The simple way |
|---|
| 37 |
and the flexible way. The simple way is: |
|---|
| 38 |
|
|---|
| 39 |
# Load some useful modules |
|---|
| 40 |
my $infobot_module = $bot->load("Infobot"); |
|---|
| 41 |
my $google_module = $bot->load("Google"); |
|---|
| 42 |
my $seen_module = $bot->load("Seen"); |
|---|
| 43 |
|
|---|
| 44 |
# Set the google key (see http://www.google.com/apis/) |
|---|
| 45 |
$google_module->set("google_key", "some google key"); |
|---|
| 46 |
|
|---|
| 47 |
$bot->run(); |
|---|
| 48 |
|
|---|
| 49 |
This lets you run a bot with a few modules, but not change those modules |
|---|
| 50 |
during the run of the bot. The complex way is as follows: |
|---|
| 51 |
|
|---|
| 52 |
# Load the loader module |
|---|
| 53 |
$bot->load('Loader'); |
|---|
| 54 |
|
|---|
| 55 |
# run the bot |
|---|
| 56 |
$bot->run(); |
|---|
| 57 |
|
|---|
| 58 |
This is simpler but needs setup once the bot is joined to a server. the |
|---|
| 59 |
Loader module lets you talk to the bot in-channel and tell it to load |
|---|
| 60 |
and unload other modules. The first one you'll want to load is the |
|---|
| 61 |
'Auth' module, so that other people can't load and unload modules |
|---|
| 62 |
without permission. Then you need to log in as an admin and change your |
|---|
| 63 |
password. |
|---|
| 64 |
|
|---|
| 65 |
(in a query) |
|---|
| 66 |
!load Auth |
|---|
| 67 |
!auth admin julia |
|---|
| 68 |
!password julia new_password |
|---|
| 69 |
!auth admin new_password |
|---|
| 70 |
|
|---|
| 71 |
Once you've done this, your bot is safe against other IRC users. Now you |
|---|
| 72 |
can tell it to load and unload other modules any time: |
|---|
| 73 |
|
|---|
| 74 |
!load Seen |
|---|
| 75 |
!load Google |
|---|
| 76 |
!load Join |
|---|
| 77 |
|
|---|
| 78 |
The join module lets you tell the bot to join and leave channels: |
|---|
| 79 |
|
|---|
| 80 |
!join #mychannel |
|---|
| 81 |
!leave #someotherchannel |
|---|
| 82 |
|
|---|
| 83 |
The perldoc pages for the various modules will list other commands. |
|---|
| 84 |
|
|---|
| 85 |
DESCRIPTION |
|---|
| 86 |
Bot::BasicBot::Pluggable started as Yet Another Infobot replacement, but |
|---|
| 87 |
now is a generalised framework for writing infobot-type bots, that lets |
|---|
| 88 |
you keep each function seperate. You can have seperate modules for |
|---|
| 89 |
factoid tracking, 'seen' status, karma, googling, etc. Included with the |
|---|
| 90 |
package are modules for: |
|---|
| 91 |
|
|---|
| 92 |
Auth - user authentication and admin access |
|---|
| 93 |
Loader - loads and unloads modules as bot commands |
|---|
| 94 |
Join - joins and leaves channels |
|---|
| 95 |
Vars - changes module variables |
|---|
| 96 |
Infobot - handles infobot-style factoids |
|---|
| 97 |
Karma - tracks the popularity of things |
|---|
| 98 |
Seen - tells you when people were last seen |
|---|
| 99 |
DNS - host lookup |
|---|
| 100 |
Google - search google for things |
|---|
| 101 |
Title - Gets the title of pages mentioned in channel |
|---|
| 102 |
|
|---|
| 103 |
use perldoc Bot::BasicBot::Pluggable::Module::<module name> for help on |
|---|
| 104 |
their terminology. |
|---|
| 105 |
|
|---|
| 106 |
The way this works is very simple. You create a new bot object, and tell |
|---|
| 107 |
it to load various modules. Then you run the bot. The modules get events |
|---|
| 108 |
when the bot sees things happen, and can respond to the events. |
|---|
| 109 |
|
|---|
| 110 |
perldoc Bot::BasicBot::Pluggable::Module::Base for the details of the |
|---|
| 111 |
module API. |
|---|
| 112 |
|
|---|
| 113 |
Main Methods |
|---|
| 114 |
new Create a new Bot. Identical to the new method in Bot::BasicBot. |
|---|
| 115 |
|
|---|
| 116 |
load($module) |
|---|
| 117 |
Load a module for the bot by name, from ./modules/Modulename.pm if |
|---|
| 118 |
that file exists, and falling back to the system package |
|---|
| 119 |
Bot::BasicBot::Pluggable::Module::$module if not. |
|---|
| 120 |
|
|---|
| 121 |
reload($module) |
|---|
| 122 |
Reload the module $module - equivalent to unloading it (if it's |
|---|
| 123 |
already loaded) and reloading it. Will stomp the old module's |
|---|
| 124 |
namespace - warnings are expected here. |
|---|
| 125 |
|
|---|
| 126 |
Not toally clean - if you're experiencing odd bugs, restart the bot |
|---|
| 127 |
if possible. Works for minor bug fixes, etc. |
|---|
| 128 |
|
|---|
| 129 |
unload |
|---|
| 130 |
Removes a module from the bot. It won't get events any more. |
|---|
| 131 |
|
|---|
| 132 |
module($module) |
|---|
| 133 |
returns the handler object for the loaded module '$module'. used, |
|---|
| 134 |
eg, to get the 'Auth' hander to check if a given user is |
|---|
| 135 |
authenticated. |
|---|
| 136 |
|
|---|
| 137 |
modules |
|---|
| 138 |
returns a list of the names of all loaded modules, as an array. |
|---|
| 139 |
|
|---|
| 140 |
add_handler(handler object, name of handler) |
|---|
| 141 |
adds a handler object with the given name to the queue of modules. |
|---|
| 142 |
There is no order specified internally, adding a module earlier does |
|---|
| 143 |
not guarantee it gets called first. Names must be unique. |
|---|
| 144 |
|
|---|
| 145 |
remove_handler |
|---|
| 146 |
remove a handler with the given name. |
|---|
| 147 |
|
|---|
| 148 |
store |
|---|
| 149 |
returns the object store associated with the bot. See |
|---|
| 150 |
Bot::BasicBot::Pluggable::Store. |
|---|
| 151 |
|
|---|
| 152 |
dispatch(method name, params) |
|---|
| 153 |
call the named method on every loaded module, if the module has a |
|---|
| 154 |
method with that name. |
|---|
| 155 |
|
|---|
| 156 |
said |
|---|
| 157 |
called as a subclass of Bot::BasicBot, |
|---|
| 158 |
|
|---|
| 159 |
run runs the bot. The POE core gets control as of this point, you're |
|---|
| 160 |
unlikely to get control back. |
|---|
| 161 |
|
|---|
| 162 |
AUTHOR |
|---|
| 163 |
Tom Insam <tom@jerakeen.org> |
|---|
| 164 |
|
|---|
| 165 |
This program is free software; you can redistribute it and/or modify it |
|---|
| 166 |
under the same terms as Perl itself. |
|---|
| 167 |
|
|---|
| 168 |
CREDITS |
|---|
| 169 |
Bot::BasicBot was written initially by Mark Fowler, and worked on |
|---|
| 170 |
heavily by Simon Kent, who was kind enough to apply some patches I |
|---|
| 171 |
needed for Pluggable. |
|---|
| 172 |
|
|---|
| 173 |
Eventually. |
|---|
| 174 |
|
|---|
| 175 |
Oh, yeah, and I stole huge chunks of docs from the Bot::BasicBot source, |
|---|
| 176 |
too. |
|---|
| 177 |
|
|---|
| 178 |
Various people helped with modules. Convert was almost ported from the |
|---|
| 179 |
infobot code by blech. But not quite. Thanks for trying.. blech has also |
|---|
| 180 |
put a lot of effort into the chump.cgi/chump.tem in the examples/ |
|---|
| 181 |
folder, including some /inspired/ calendar evilness. |
|---|
| 182 |
|
|---|
| 183 |
And thanks to the rest of #2lmc, who were my unwilling guinea pigs |
|---|
| 184 |
during development. And who kept suggesting totally stupid ideas for |
|---|
| 185 |
modules that I then felt compelled to go implement. Shout.pm owes it's |
|---|
| 186 |
existence to #2lmc. |
|---|
| 187 |
|
|---|
| 188 |
I spent a lot of time in the mozbot code, and that has influenced my |
|---|
| 189 |
ideas for Pluggable. Mostly to get round its awfulness. |
|---|
| 190 |
|
|---|
| 191 |
SYSTEM REQUIREMENTS |
|---|
| 192 |
Bot::BasicBot::Pluggable is based on POE, and really needs the latest |
|---|
| 193 |
version. Because POE is like that sometimes. |
|---|
| 194 |
|
|---|
| 195 |
You also need POE::Component::IRC. Oh, and Bot::BasicBot. |
|---|
| 196 |
|
|---|
| 197 |
Some of the modules will need more modules. eg, Google.pm needs |
|---|
| 198 |
Net::Google. See the module docs for more details. |
|---|
| 199 |
|
|---|
| 200 |
BUGS |
|---|
| 201 |
During the make, make test make install process, POE will moan about its |
|---|
| 202 |
kernel not being run. This is a Bot::BasicBot problem, apparently. |
|---|
| 203 |
|
|---|
| 204 |
reloading a module causes warnings as the old module gets it's namespace |
|---|
| 205 |
stomped. Not a lot you can do about that. |
|---|
| 206 |
|
|---|
| 207 |
All modules need to be in the Bot::Pluggable::Module:: namespace. Well, |
|---|
| 208 |
that's not really a bug. |
|---|
| 209 |
|
|---|
| 210 |
More other things than I can shake a stick at. |
|---|
| 211 |
|
|---|
| 212 |
SEE ALSO |
|---|
| 213 |
POE |
|---|
| 214 |
|
|---|
| 215 |
POE::Component::IRC |
|---|
| 216 |
|
|---|
| 217 |
Bot::BasicBot |
|---|
| 218 |
|
|---|
| 219 |
Possibly Infobot, at http://www.infobot.org, and Mozbot, somewhere in |
|---|
| 220 |
mozilla.org. |
|---|
| 221 |
|
|---|