| Bot-MetaSyntactic documentation | Contained in the Bot-MetaSyntactic distribution. |
Bot::MetaSyntactic - IRC frontend to Acme::MetaSyntactic
Version 0.03
use Bot::MetaSyntactic;
Bot::MetaSyntactic->new(
nick => 'meta',
name => 'Acme::MetaSyntactic IRC frontend',
server => 'irc.perl.org',
channels => ['#randomchan']
)->run
This module provides the glue for providing an IRC interface to
the module Acme::MetaSyntactic.
Initializes private data.
Main function for interacting with the bot object.
It follows the Bot::BasicBot API and expect an hashref as argument.
See "COMMANDS" for more information on recognized commands.
Prints usage.
Syntax (assuming the name of the bot is meta):
meta [theme] [number]
meta themes
Called with no argument, print this number of random words from a random theme.
Called with a theme name, print this number of random words from this theme.
Called with themes, print all available themes.
(F) Occurs in init(). As the message says, we were unable to create
a new object of the given class.
Sébastien Aperghis-Tramoni, <sebastien@aperghis.net>
Please report any bugs or feature requests to
bug-bot-metasyntactic@rt.cpan.org, or through the web interface at
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Bot-MetaSyntactic.
I will be notified, and then you'll automatically be notified
of progress on your bug as I make changes.
Copyright 2005 Sébastien Aperghis-Tramoni, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Bot-MetaSyntactic documentation | Contained in the Bot-MetaSyntactic distribution. |
package Bot::MetaSyntactic; use strict; use Acme::MetaSyntactic; use Bot::BasicBot; use Carp; use I18N::LangTags qw(extract_language_tags); use Text::Wrap; { no strict; $VERSION = '0.0301'; @ISA = qw(Bot::BasicBot); }
sub init { my $self = shift; $self->{meta} = { obj => undef, limit => 100, wrap => 256, }; $Text::Wrap::columns = $self->{meta}{wrap}; $self->{meta}{obj} = Acme::MetaSyntactic->new or carp "fatal: Can't create new Acme::MetaSyntactic object" and return undef; }
sub said { my $self = shift; my $args = shift; my($number,$theme); # don't do anything unless directly addressed return undef unless $args->{address} eq $self->nick or $args->{channel} eq 'msg'; return if $self->ignore_nick($args->{who}); # ignore karma return if index($args->{body}, '++') == 0; return if index($args->{body}, '--') == 0; my @themes = Acme::MetaSyntactic->themes; { $args->{body} =~ s/\b(\d+)\b//; $number = defined($1) ? $1 : 1; $number = $self->{meta}{limit} if $number > $self->{meta}{limit}; } { $args->{body} =~ s/(\w+)//; $theme = $1 || 'any'; } if ($theme eq 'version') { $args->{body} = sprintf "%s IRC bot, using %s", $self->nick, join ', ', map { $_ . ' ' . $_->VERSION } qw( Acme::MetaSyntactic Bot::BasicBot Bot::MetaSyntactic POE POE::Component::IRC ); $self->say($args); return undef; } if ($theme eq 'themes') { $args->{body} = "Available themes: @themes"; $self->say($args); return undef; } unless (Acme::MetaSyntactic->has_theme($theme)) { $args->{body} = "No such theme: $theme"; $self->say($args); return undef; } my @words = $self->{meta}{obj}->name($theme => $number); @words = @words[0..$self->{meta}{limit}] if @words > $self->{meta}{limit}; $args->{body} = join ' ', wrap('', '', @words); $self->say($args); return undef }
sub help { return "usage: meta [theme] [number]\n". " use theme name 'themes' to print all available themes" }
1; # End of Bot::MetaSyntactic