Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/Info3.pm view on Meta::CPAN
++$x;
$vars->{$x} = $item;
}
## var replace kinda like rplprintf
## call _info3repl()
my $re = qr/((\S)~)/;
$str =~ s/$re/__info3repl($1, $2, $vars)/ge;
return $str
}
sub __info3repl {
my ($orig, $match, $vars) = @_;
return $orig unless defined $vars->{$match};
return $vars->{$match}
}
1;
__END__
=pod
=head1 NAME
Bot::Cobalt::Plugin::Info3 - Text-triggered responses for Bot::Cobalt
=head1 SYNOPSIS
<JoeUser> cobaltbot: add hi Howdy N~!
<Bob> hi
<cobaltbot> Howdy Bob!
=head1 DESCRIPTION
B<darkbot6> came with built-in I<info2> functionality; text responses
(possibly with variables) could be triggered by simple glob matches.
This plugin follows largely the same pattern; users can add a topic:
<JoeUser> cobaltbot: add hello*everyone Howdy N~! Welcome to C~!
When a user says something matching the glob, the response is
triggered:
<Somebody> hello there, everyone
<cobaltbot> Howdy Somebody! Welcome to #thischannel!
(Note that if multiple added globs match a given IRC string, the result
is somewhat unpredictable and will largely depend on what your database
gives up first. Managing your topics sanely is up to you.)
Topics can also be hooked into randomized responses.
See L</"RDB integration"> -- this functionality also requires
L<Bot::Cobalt::Plugin::RDB>.
Back-end storage takes place via L<Bot::Cobalt::DB>.
The core distribution comes with a tool called B<cobalt2-import-info2>
capable of converting B<darkbot> and B<cobalt1> 'info' databases.
By default, the same topic can be requested 4 times in a row before
being blocked to prevent loops. This can be adjusted via B<Opts>
in your B<info3.conf>:
Opts:
MaxTriggered: 2
=head1 USAGE
=head2 Add and delete
=head3 add
Add a new B<info3> topic:
bot: add my+new+topic This is my new topic.
bot: add help You're beyond help, N~!
The most common wildcards are * (match any number of any character) and
+ (match a single space).
See L<Bot::Cobalt::Utils/glob_to_re_str> for details regarding glob syntax.
Note that ^$ start/end anchors are not valid when adding B<info3> globs;
every glob is automatically anchored.
Variables are available for use in topic responses -- see
L</"Response variables">.
=head4 Responding with an action
A topic response can also be an action ('/me').
In order to send a response as an action, prefix the response with B<+> :
bot: add greetings +waves to N~
Variable replacement works as-normal.
=head4 Responding to an action
A topic prefixed with C<~action> is a response to an action:
bot: add ~action+waves +waves back to N~
=head3 del
Deletes the specified topic.
bot: del my+new+topic
=head3 replace
Same as 'del' then 'add' for an existing topic:
bot: replace this+topic Some new string
=head2 Searching
=head3 search
( run in 2.331 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )