Convos::Plugin::Bot::Action - Base class for bot actions

  1. SYNOPSIS
  2. DESCRIPTION
  3. EVENTS
    1. message
  4. ATTRIBUTES
    1. bot
    2. config
    3. description
    4. enabled
    5. home
    6. moniker
    7. usage
  5. METHODS
    1. event_config
    2. query_db
    3. register
    4. reply
  6. SEE ALSO

SYNOPSIS

package Convos::Plugin::Bot::Action::Beans;
use Mojo::Base "Convos::Plugin::Bot::Action";

sub reply {
  my ($self, $event) = @_;
  return "Cool beans!" if $event->{mesages} =~ m/^beans/;
}

DESCRIPTION

Convos::Plugin::Bot::Action must be used as base class for Convos::Plugin::Bot actions.

EVENTS

message

$action->on(message => sub { my ($action, $event) = @_ });

This event is emitted from Convos::Plugin::Bot, when the bot sees/receives a new message. The $event has this structure:

{
  connection_id   => "irc-something",
  conversation_id => "nick_or_#room_lowercase",
  from            => $nick,
  is_private      => $bool, # true if sent in a private chat
}

ATTRIBUTES

bot

$bot = $action->bot;

Access the parent Convos::Plugin::Bot object.

config

$pointer = $action->config;

Shared config parameters with "config" in Convos::Plugin::Bot.

description

$str = $action->description;

Holds a description of the action, which can be displayed as aid in a conversation with the bot.

enabled

$bool = $action->enabled;
$action = $action->enabled(0);

Can be set to a boolean value in the config file to enable/disable a given action.

home

$path = $action->home;

Path to where the bot/action can store files.

moniker

$str = $action->moniker;

A short nick name for the action class name.

usage

$str = $action->usage;

Holds information about the action, which can be displayed as aid in a conversation with the bot.

METHODS

event_config

$any = $action->event_config(\%event, $config_key);

Used to get a "config" parameter for the current $action and an event with connection_id and conversation_id.

$event should have the same structure as the "message" event.

query_db

$sth = $action->query_db($sql, @bind);

Used to run SQL in SQLite database. Example:

my $sth = $action->query_db('select name from users where id = ?', 42);
my $user = $sth->fetchrow_hashref;
warn $user ? $user->{name} : 'not found';

register

$action->register($bot, \%config);

Called the first time the $action is loaded by Convos::Plugin::Bot.

reply

$str = $action->reply(\%event);

Can be used to generate a reply to a %event. The first Convos::Plugin::Bot::Action object that returns a $str will be used to generate a response. This is to prevent the bot from making multiple responses to the same message.

Return undef to allow the next action to reply.

$event has the same structure as the "message" event.

SEE ALSO

Convos::Plugin::Bot.