<commit_before>package Command::Pick;

use v5.10;
use strict;
use warnings;

use Exporter qw(import);
our @EXPORT_OK = qw(cmd_pick);

use Mojo::Discord;
use Bot::Goose;

###########################################################################################
# Command Info
my $command = "Pick";
my $access = 0; # Public
my $description = "Have the bot decide your fate, you wishy washy fuck.";
my $pattern = '^(pick) ?(.*)$';
my $function = \&cmd_pick;
my $usage = <<EOF;
```!pick thing one, thing two, thing three```
    Give the bot a list of things to pick from, and separate each with a comma.
    You can have the bot pick from as many things as you want.
EOF
###########################################################################################

sub new
{
    my ($class, %params) = @_;
    my $self = {};
    bless $self, $class;
     
    # Setting up this command module requires the Discord connection 
    $self->{'bot'} = $params{'bot'};
    $self->{'discord'} = $self->{'bot'}->discord;
    $self->{'pattern'} = $pattern;

    # Register our command with the bot
    $self->{'bot'}->add_command(
        'command'       => $command,
        'access'        => $access,
        'description'   => $description,
        'usage'         => $usage,
        'pattern'       => $pattern,
        'function'      => $function,
        'object'        => $self,
    );
    
    return $self;
}

sub cmd_pick
{
    my ($self, $channel, $author, $msg) = @_;

    my $args = $msg;
    my $pattern = $self->{'pattern'};
    $args =~ s/$pattern/$2/i;

    my $discord = $self->{'discord'};
    my $replyto = '<@' . $author->{'id'} . '>';

    my $quiznos = 0;

    my @picks = split (/,+/, $args);

    my $count = scalar @picks;
    my $pick = int(rand($count)+.5)+1;  #  Add .5 so the int() rounds instead of doing floor. Otherwise the final option has a very low chance of being picked.

    unshift @picks, "spacer";   # Start things at 1 instead of 0.
    $pick =~ s/^ *//;
    
    for (my $i = 1; $i <= $count; $i++)
    {
        if ( $picks[$i] =~ /^\s*quiznos\s*$/i )
        {
            # Always pick Quiznos
            $pick = $i; 
            $quiznos = 1;
        }
    }

    if ( !$quiznos and int(rand(500)) == 420 )
    {
        $pick = $count+1;
        push @picks, 'Quiznos';
    }
    

    # Send a message back to the channel
    $discord->send_message($channel, "**$pick:** $picks[$pick]");
}

1;<commit_msg>Fix Pick<commit_after>package Command::Pick;

use v5.10;
use strict;
use warnings;

use Exporter qw(import);
our @EXPORT_OK = qw(cmd_pick);

use Mojo::Discord;
use Bot::Goose;

###########################################################################################
# Command Info
my $command = "Pick";
my $access = 0; # Public
my $description = "Have the bot decide your fate, you wishy washy fuck.";
my $pattern = '^(pick) ?(.*)$';
my $function = \&cmd_pick;
my $usage = <<EOF;
```!pick thing one, thing two, thing three```
    Give the bot a list of things to pick from, and separate each with a comma.
    You can have the bot pick from as many things as you want.
EOF
###########################################################################################

sub new
{
    my ($class, %params) = @_;
    my $self = {};
    bless $self, $class;
     
    # Setting up this command module requires the Discord connection 
    $self->{'bot'} = $params{'bot'};
    $self->{'discord'} = $self->{'bot'}->discord;
    $self->{'pattern'} = $pattern;

    # Register our command with the bot
    $self->{'bot'}->add_command(
        'command'       => $command,
        'access'        => $access,
        'description'   => $description,
        'usage'         => $usage,
        'pattern'       => $pattern,
        'function'      => $function,
        'object'        => $self,
    );
    
    return $self;
}

sub cmd_pick
{
    my ($self, $channel, $author, $msg) = @_;

    my $args = $msg;
    my $pattern = $self->{'pattern'};
    $args =~ s/$pattern/$2/i;

    my $discord = $self->{'discord'};
    my $replyto = '<@' . $author->{'id'} . '>';

    my $quiznos = 0;

    my @picks = split (/,+/, $args);

    my $count = scalar @picks;
    my $pick = int(rand($count));

    $pick =~ s/^ *//;
    
    for (my $i = 0; $i < $count; $i++)
    {
        if ( $picks[$i] =~ /^\s*quiznos\s*$/i )
        {
            # Always pick Quiznos
            $pick = $i; 
            $quiznos = 1;
        }
    }

    # Send a message back to the channel
    $discord->send_message($channel, ":point_right: $picks[$pick]");
}

1;
{'fraction_non_alphanumeric': 0.24409965034965034, 'fraction_numerical': 0.006555944055944056, 'mean_word_length': 2.5343629343629344, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 41, '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': '2076888', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1485, 'n_words': 438}