<commit_before>package RoboBot::Plugin::Redirection;

use v5.20;

use namespace::autoclean;

use Moose;
use MooseX::SetOnce;

extends 'RoboBot::Plugin';

has '+name' => (
    default => 'Redirection',
);

has '+description' => (
    default => 'Provides functions for modifying the recipient(s) of function output.',
);

has '+commands' => (
    default => sub {{
        'to-nick' => { method      => 'to_nick',
                       description => 'Redirects output to a private message delivered to the given nick. Must be on the same server. All input values are passed through unchanged.',
                       usage       => '<nick> <value> [<value 2> ... <value N>]',
                       example     => 'dungeonmaster (join ": " "I roll stealth" (roll 20 1))',
                       result      => '[dungeonmaster] I roll stealth: 18' },

        'to-channel' => { method      => 'to_channel',
                          description => 'Redirects output to a specific channel. Must be on the same server. All input values are passed through unchanged.',
                          usage       => '<channel> <value> [<value 2> ... <value N>]',
                          example     => '#boringchan "Join us over in #superfunchan!"',
                          result      => '[#boringchan] Join us over in #superfunchan!' },
    }},
);

sub to_nick {
    my ($self, $message, $command, $to_nick, @args) = @_;

    # TODO: more protection against malicious nick input (maybe done in Nick.pm)

    my ($nick);

    if ($nick = RoboBot::Nick->new( config => $self->bot->config, name => "$to_nick" )) {
        $message->response->nick($nick);
        $message->response->clear_channel;
    } else {
        $message->response->raise(sprintf('Could not instantiate nick recipient: %s', $to_nick));
    }

    return @args;
}

sub to_channel {
    my ($self, $message, $command, $to_channel, @args) = @_;

    $to_channel =~ s{^\#*}{}ogs;

    if (my $channel = (grep { lc($_->name) eq lc($to_channel) } @{$self->bot->config->channels})[0]) {
        $message->response->channel($channel);
        $message->response->clear_nick;
    } else {<commit_msg>fix channel redirection (use Network object, where the channels are actually referenced now)<commit_after>package RoboBot::Plugin::Redirection;

use v5.20;

use namespace::autoclean;

use Moose;
use MooseX::SetOnce;

extends 'RoboBot::Plugin';

has '+name' => (
    default => 'Redirection',
);

has '+description' => (
    default => 'Provides functions for modifying the recipient(s) of function output.',
);

has '+commands' => (
    default => sub {{
        'to-nick' => { method      => 'to_nick',
                       description => 'Redirects output to a private message delivered to the given nick. Must be on the same server. All input values are passed through unchanged.',
                       usage       => '<nick> <value> [<value 2> ... <value N>]',
                       example     => 'dungeonmaster (join ": " "I roll stealth" (roll 20 1))',
                       result      => '[dungeonmaster] I roll stealth: 18' },

        'to-channel' => { method      => 'to_channel',
                          description => 'Redirects output to a specific channel. Must be on the same server. All input values are passed through unchanged.',
                          usage       => '<channel> <value> [<value 2> ... <value N>]',
                          example     => '#boringchan "Join us over in #superfunchan!"',
                          result      => '[#boringchan] Join us over in #superfunchan!' },
    }},
);

sub to_nick {
    my ($self, $message, $command, $to_nick, @args) = @_;

    # TODO: more protection against malicious nick input (maybe done in Nick.pm)

    my ($nick);

    if ($nick = RoboBot::Nick->new( config => $self->bot->config, name => "$to_nick" )) {
        $message->response->nick($nick);
        $message->response->clear_channel;
    } else {
        $message->response->raise(sprintf('Could not instantiate nick recipient: %s', $to_nick));
    }

    return @args;
}

sub to_channel {
    my ($self, $message, $command, $to_channel, @args) = @_;

    $to_channel =~ s{^\#*}{}ogs;

    if (my $channel = (grep { lc($_->name) eq lc($to_channel) } @{$message->network->channels})[0]) {
        $message->response->channel($channel);
        $message->response->clear_nick;
    } else {
{'fraction_non_alphanumeric': 0.15582347588717016, 'fraction_numerical': 0.005004549590536852, 'mean_word_length': 2.371932515337423, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6867105', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1253, 'n_words': 386}