The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bot::Backbone::Service::Fact::Keyword - Memorize keywords and respond to them when mentioned

VERSION

version 0.142250

SYNOPSIS

    # in the bot config
    service keyword => (
        service   => 'Fact::Keyword',
        frequency => 0.25,
    );

    # in the chat
    alice> !keyword bot That's my name, don't wear it out.
    alice> hello bot
    alice> i said bot, hello
    alice> you dumb bot
    bot> That's my name, don't wear it out.
    alice> !forget_keyword bot

DESCRIPTION

Allows members of the chat to establish a set of keywords that the bot can respond to a configurable percentage of the time. Each keyword can have more than one response associated with it, in which case, a response is chosen at random.

DISPATCHER

!keyword

  !keyword name text of the response

This is used to tell the bot to memorize a keyword. The first word given ot the command is the keyword to trigger on. The remainder is the response to the bot should give when it encounters the keyword.

!forget_keyword

  !forget_keyword name
  !forget_keyword name text of the response

This command allows the chat user to tell the bot to forget the a keyword or particular response. In the first form, all responses to the keyword that have been memorized will be deleted. In the second form, only the response given for that keyword will be forgotten.

ATTRIBUTES

frequency

This is a value between 0 and 1 that determines how often the bot will search chat texts for keywords. The reason for this is twofold:

  1. If the bot always responded to every keyword, it's likely the bot would become annoying in most cases.

  2. There's a small performance penalty with the way this works. The bot has to use every word in the text to search for a keyword. Chances are this is not a big problem, but it exists.

METHODS

load_schema

This is used by the Bot::Backbone::Service::Role::Storage role to setup the fact_keywords table used to store keywords for use with this service.

learn_keyword

This implements the !keyword command to memorize keywords.

forget_keyword

This implements teh !forget_keyword command to forget keywords.

recall_keyword_sometimes

This searches texts in the chat according to the "frequency" setting for keywords. If a keyword is found on one of those searches, the response will be sent back to the chat.

initialize

No op.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Qubling Software LLC.

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