view release on metacpan or search on metacpan
doc/lang/expr/index.rst view on Meta::CPAN
Which replaces the third element in our earlier example with a nested expression
that happens to, when evaluated, return the value ``2``. Note that except for a
limited set of special forms, nested expressions are evaluated as they are
encountered. Quoting an expression does not currently lead to the consistent
behavior that users familiar with Lisp languages would expect (preventing the
expression or list from being evaluated until explicitly unquoted/eval'ed).
Future versions of |RB| are intended to correct this and bring even more
consistency to the language.
The next example, while it looks similar to the expressions above, is not an
expression but simply a list -- as the first element is not a function or macro
name::
(1 2)
It is, however, still a valid syntactical structure which may be fed to |RB|.
But because there is no function or macro to evaluate, the list will return
itself rather than some computed value or function result.
lib/App/RoboBot/Message.pm view on Meta::CPAN
# If the very first character is an exclamation point, check the following
# non-whitespace characters to see if they match a known command. If they
# do, convert the incoming message to a simple expression to allow people
# to interact with the bot using the older "!command arg arg arg" syntax.
if (substr($self->raw, 0, 1) eq '!') {
if ($self->raw =~ m{^\!+((\S+).*)}) {
$self->log->debug(sprintf('Legacy bang syntax detected in message on network %s. Rewriting as an expression.', $self->network->name));
my ($no_excl, $maybe_cmd) = ($1, $2);
# If there is at least one pipe character followed by what looks to
# be possibly another command, treat the incoming message as if it
# is the old-style piped command chain, and convert to nested
# expressions.
if ($no_excl =~ m{\|\s+\!\S+}) {
my @chained = split(/\|/, $no_excl);
$no_excl = '';
foreach my $command (@chained) {
$command =~ s{(^\s*\!?|\s*$)}{}gs;
$no_excl = sprintf('(%s%s)', $command, (length($no_excl) > 0 ? ' ' . $no_excl : ''));
lib/App/RoboBot/Message.pm view on Meta::CPAN
$no_excl = '(' . $no_excl . ')';
}
$self->raw($no_excl)
if exists $self->bot->commands->{lc($maybe_cmd)}
|| exists $self->bot->macros->{$self->network->id}{lc($maybe_cmd)};
}
} elsif ($self->raw =~ m{ ^ $self->bot->nick->name : \s* (.+) }ixs) {
$self->log->debug(sprintf('Incoming message on network %s was addressed to the bot. Stripping bot name and treating as expression.', $self->network->name));
# It looks like someone said something to us directly, so strip off our
# nick from the front, and treat the reast as if it were a command.
$self->raw('('.$1.')');
}
if ($self->raw =~ m{^\s*\(\S+}o) {
$self->log->debug(sprintf('Incoming message on network %s looks like an expression. Attempting to parse.', $self->network->name));
my $parser = App::RoboBot::Parser->new( bot => $self->bot );
my $expr;
eval {
$expr = $parser->parse($self->raw);
};
if ($@) {
$self->log->warn(sprintf('Parsing resulted in a suppressable error: %s', $@));
lib/App/RoboBot/Parser.pm view on Meta::CPAN
use v5.20;
use namespace::autoclean;
use Moose;
use MooseX::ClassAttribute;
use MooseX::SetOnce;
use App::RoboBot::TypeFactory;
use Scalar::Util qw( looks_like_number );
has 'bot' => (
is => 'ro',
isa => 'App::RoboBot',
required => 1,
);
has 'err' => (
is => 'rw',
isa => 'Str',
lib/App/RoboBot/Parser.pm view on Meta::CPAN
}
if ($in_str) {
return;
}
if (defined $el && length($el) > 0) {
if (substr($el, 0, 1) eq ':') {
$self->log->debug(sprintf('Treating non-list element "%s" as Symbol.', $el));
return $self->tf->build('Symbol', $el);
} elsif (looks_like_number($el)) {
$self->log->debug(sprintf('Treating non-list element "%s" as Number.', $el));
return $self->tf->build('Number', $el);
} elsif (exists $self->bot->commands->{lc($el)}) {
$self->log->debug(sprintf('Treating non-list element "%s" as Function.', $el));
return $self->tf->build('Function', $el);
} elsif (exists $self->macros->{lc($el)}) {
$self->log->debug(sprintf('Treating non-list element "%s" as Macro.', $el));
return $self->tf->build('Macro', $el);
} else {
$self->log->debug(sprintf('Treating non-list element "%s" as String.', $el));
lib/App/RoboBot/Plugin/Bot/Output.pm view on Meta::CPAN
$App::RoboBot::Plugin::Bot::Output::VERSION = '4.004';
use v5.20;
use namespace::autoclean;
use Moose;
use MooseX::SetOnce;
use Data::Dumper;
use Number::Format;
use Scalar::Util qw( looks_like_number );
extends 'App::RoboBot::Plugin';
=head1 bot.output
Provides string formatting and output/display functions.
=cut
has '+name' => (
lib/App/RoboBot/Plugin/Bot/Output.pm view on Meta::CPAN
sub _print_el {
my ($bot, $output, $el) = @_;
if (!defined $el) {
$$output .= " undef";
} elsif (ref($el) eq 'HASH') {
_print_map($bot, $output, $el);
} elsif (ref($el) eq 'ARRAY') {
_print_list($bot, $output, $el);
} elsif (looks_like_number($el)) {
$$output .= " $el";
} else {
$el =~ s{"}{\\"}g;
$el =~ s{\n}{\\n}gs;
$el =~ s{\r}{\\r}gs;
$el =~ s{\t}{\\t}gs;
$$output .= sprintf(' "%s"', $el);
}
return;
lib/App/RoboBot/Plugin/Fun/Factoid.pm view on Meta::CPAN
Creates a new factoid of ``name`` on the current network with the given
description. Descriptions are limited only by the restrictions of the current
network.
=head3 Usage
<factoid name> "<description>"
=head3 Examples
(add-factoid perl "A language which looks the same before and after encryption.")
=head2 update-factoid
=head3 Description
Updates the description of the named factoid.
=head3 Usage
<factoid name> "<new description>"
lib/App/RoboBot/Plugin/Net/URLs.pm view on Meta::CPAN
use Text::Levenshtein qw( distance );
use URI::Find;
extends 'App::RoboBot::Plugin';
=head1 net.urls
Provides functions related to URLs.
In addition to exported functions, this module inserts a pre-hook into the
message processing pipeline which looks for any URLs in messages others have
sent. Any URLs that are detected are retrieved automatically and an attempt is
made to locate a page title. Redirects are also logged.
If either a page title or any redirects are found, they are displayed back in
the channel.
A timeout on all URL retrievals is set to prevent poorly behaving websites from
delaying subsequent message processing. If the timeout is reached, all further
URL detection and page title lookup is skipped for the current message.
lib/App/RoboBot/Plugin/Social/Karma.pm view on Meta::CPAN
use Number::Format;
extends 'App::RoboBot::Plugin';
=head1 social.karma
Modifies and displays karma/reputation points.
In addition to the exported functions, this module inserts a pre-hook into the
message processing pipeline which looks for any karma giving/taking. Any
substrings in messages which match ``nick++`` or ``nick--`` are extracted and
used to automatically increment or decrement, respectively, the named person's
global karma.
A user's karma is calculated using a weighted formula that discourages a single
benefactor or detractor from completely dominating their target's reputation.
It is not a simple integer. Though this module would be much less obtuse if it
were, because karma currently calculates pretty weirdly in some circumstances.
The end goal is for the number of distinct benefactors/detractors to matter
more than the number of grants/revokes performed by a single entity. Stated
lib/App/RoboBot/Plugin/Social/Skills.pm view on Meta::CPAN
(skill-levels)
=head2 describe-skill
=head3 Description
Permits the addition of a description to a skill. Descriptions are free-form
strings, limited only by the current network's message length limits and
formatting options. Because these descriptions are displayed every single time
someone looks up the skill, it's recommended to keep them brief and to the
point.
=head3 Usage
<skill name> <description>
=head3 Examples
(describe-skill PostgreSQL "An object-relational database management system.")