App-RoboBot

 view release on metacpan or  search on metacpan

lib/App/RoboBot/Message.pm  view on Meta::CPAN

            }
        }
    }
}

sub process {
    my ($self) = @_;

    $self->log->debug(sprintf('Preparing to process incoming message on network %s.', $self->network->name));

    # Process any before-hooks first
    if ($self->bot->run_before_hooks) {
        $self->log->debug('Processing before_hooks.');

        foreach my $plugin (@{$self->bot->before_hooks}) {
            $self->log->debug(sprintf('Hook from plugin %s being processed.', $plugin->name));

            # Skip hook if plugin is disabled for the current network.
            next if exists $self->network->disabled_plugins->{lc($plugin->name)};

            $plugin->hook_before($self);
        }
    }

    # Process the message itself (unless the network on which it was received is
    # marked as "passive" - only hooks will run, not functions or macros).
    if ($self->has_expression && ! $self->network->passive) {
        $self->log->debug(sprintf('Preparing to evaluate expression (Network %s is non-passive).', $self->network->name));

        my @r = $self->expression->evaluate($self);

        # TODO: Restore pre-type functionality of only adding the implicit
        #       (print ...) call if the last function evaluated wasn't already
        #       an explicit print call.
        if (@r && @r > 0) {
            $self->log->debug('Adding implicit (print) call, as data was returned by outermost expression.');

            $self->bot->commands->{'print'}->process($self, 'print', {}, @r);
        }
    }

    # Process any after-hooks before sending response
    if ($self->bot->run_after_hooks) {
        $self->log->debug('Processing after_hooks.');

        foreach my $plugin (@{$self->bot->after_hooks}) {
            $self->log->debug(sprintf('Hook from plugin %s being processed.', $plugin->name));

            # Skip hook if plugin is disabled for the current network.
            next if exists $self->network->disabled_plugins->{lc($plugin->name)};

            $plugin->hook_after($self);
        }
    }

    # Deliver the response
    $self->log->debug('Issuing response send.');
    $self->response->send;
}

sub update_response_channel {
    my ($self, $new_channel, $old_channel) = @_;

    if ($self->has_response && $self->has_channel) {
        $self->response->channel($new_channel);
    }
}

__PACKAGE__->meta->make_immutable;

1;



( run in 0.563 second using v1.01-cache-2.11-cpan-df04353d9ac )